I have a multi site set up where there are three separate sites in the CMS. At present there is only 1 Site Index and the search on all 3 sites bring back the same results.
How can I separate the search results to only show results relevant to the current site?
Do you have separate trees for each site? How does solution look from Umbraco admin part?
You can filter search results on render stage, just check what site this result bongs and show or hide it, another solution is to add a new param to index entries, that will store which site is this page.
I have a multisite install with 12+ sites in it and to be able to filter search results I have an event handler to add a custom field into the search index when a document is saved that allows me to filter search results later on.
So, in my ApplicationEventHandlerApplicationStarted method I add a new event handler as follows:
foreach (BaseIndexProvider index in ExamineManager.Instance.IndexProviderCollection)
{
if (index.Name == "SiteSearchIndexer" || index.Name == "MyCustomSearchIndexer")
{
index.GatheringNodeData += this.SearchIndexerGatheringNodeData;
((LuceneIndexer)index).DocumentWriting += LuceneDocumentWriting;
}
}
This is then implemented as follows:
private void SearchIndexerGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
{
if (e.IndexType == IndexTypes.Content)
{
try
{
if (e.Fields.ContainsKey("path"))
{
// Split the path to the current node and extract the homepage id
string rootNodeId = e.Fields["path"].Split(',')[2];
e.Fields.Add("siteId", rootNodeId);
}
[...]
}
catch (Exception ex)
{
LogHelper.Error(this.GetType(), "Failed to update search index node data", ex);
}
}
}
Then in my search query something like this:
if (Model.AncestorOrSelf("MyHomepageDoctypeAlias") != null)
{
filter.And().Field("siteId", site.Id.ToString());
}
Examine search on Multi site set up - 7.4.3
HI,
I have a multi site set up where there are three separate sites in the CMS. At present there is only 1 Site Index and the search on all 3 sites bring back the same results.
How can I separate the search results to only show results relevant to the current site?
Thanks
Jon
Hi Jon
Do you have separate trees for each site? How does solution look from Umbraco admin part?
You can filter search results on render stage, just check what site this result bongs and show or hide it, another solution is to add a new param to index entries, that will store which site is this page.
Thanks,
Alex
I have a multisite install with 12+ sites in it and to be able to filter search results I have an event handler to add a custom field into the search index when a document is saved that allows me to filter search results later on.
So, in my
ApplicationEventHandler
ApplicationStarted
method I add a new event handler as follows:This is then implemented as follows:
Then in my search query something like this:
Hope that helps.
Simon
is working on a reply...