Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to index only live versions of pages? #4

Open
barrykeenan opened this issue Oct 24, 2019 · 3 comments
Open

How to index only live versions of pages? #4

barrykeenan opened this issue Oct 24, 2019 · 3 comments

Comments

@barrykeenan
Copy link

Hi Andrew,

In the docs you show how to filter:

$index->index([
    Page::class => [
        'ClassName:not' => ErrorPage::class,
    ],
    File::class => [
        'ClassName:not' => Folder::class,
    ],
]);

How would I filter to only get live versions of pages? Similar to:

$live_pages = Versioned::get_by_stage(Page::class, Versioned::LIVE);

Many thanks,
Barry

@barrykeenan barrykeenan changed the title how to only How to index only live versions of pages? Oct 24, 2019
@sylvainreiter
Copy link
Member

sylvainreiter commented Oct 24, 2019 via email

@barrykeenan
Copy link
Author

barrykeenan commented Oct 25, 2019

Hi Sylvain!

I was thinking more from the point of view of a SilverStripe task to re-index the whole site. Since draft pages are returned by default I was ending up with urls in my index with a ?stage=Stage suffix, which I don't want.

In my case I changed PrimitiveDataObjectFactory to use Versioned and PrimitiveDataObject->getLink() to just return source->Link() rather than re-querying SiteTree (which would get the draft url again)

I wonder if this would be a useful option for others?

@samthejarvis
Copy link
Contributor

Hi @barrykeenan - For posterity, another approach is using Versioned::set_stage(Versioned::LIVE); before indexing. This ensures only live/published records are used (mimics viewing from a live context). This approach is useful when you have related objects included in the index which are also versioned (images, content blocks etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants