Skip to content

How indexing of draft and live content is managed

nyeholt edited this page Oct 26, 2010 · 1 revision

There are several considerations when indexing content for multiple stages

  • Recording the current stage the content is found in
  • Only updating the relevant draft record when subsequently saved
  • Querying against the correct version of the content
  • Allowing non-versioned items to be indexed alongside versioned items
  • Allowing for the return of the 'latest' non-versioned item regardless of querying for 'Live' or 'Stage' content

The basic approach here is to index two versions of the content; one for the Live stage, and one for the "Stage" (draft) stage. As well as indexing the two separate versions (using a compound id; ID_Type_Stage), we record the stage the item is being indexed within in a new multivalue property. The 'stage' value is passed as a parameter to the index() method, and the correct one is chosen based on whether the content is being _write()_en or onAfterPublish().

Now, if there's content that is not Versioned, it will never have onAfterPublish called, meaning that we won't ever get an entry for the item for the "Live" stage, meaning that if we perform a search against the Live site, there won't be any results. Therefore we need to have an entry written for it in the "Live" stage when we write() the content. However, now there's a problem if we search against the "Stage" (draft) version of the site. How do we fix this? Luckily, Solr lets us index multiple values in the same property, meaning that for items that aren't Versioned, we just index the fact that they are relevant for searches against BOTH stages.