Restricting Examine search to just particular sections
Hi,
I have a main search and then I want to add landing pages that have their own search box and only search their own sub pages and folders.
How can this be achieved? Can indexes be set up to only search certain nodes? What about is new sections are added in the future? Would a new index then have to be manually set up? An editor would not be able to do this. Can it be done programatically?
We did something a lot like this for a site we are working on right now. We had set up a custom index and were using it for a faceted search. We needed to be able to restrict search results to the children of the page with the search on it. This is what we did:
Below is what I added to the config/ExamineIndex.config. What is most important here is adding the parentID to the IndexAttributeFields.
When I wanted to perform my search, I add search criteria that restricts my search results to pages with a parentID that matches the id of the current page we are searching from. It might look something like this.
// Note: I have already set containerId up as the id of the current node (the node doing the searching)
var customSearcher = ExamineManager.Instance.SearchProviderCollection["CustomSearcher"];
var searchCriteria = customSearcher.CreateSearchCriteria();
var query = searchCriteria.Field("inactive", "0");
if (containerId > 0)
{
query.And().Field("parentID", containerId.ToString());
}
var searchResults = customSearcher.Search(query.Compile());
Hope this helps you get started. Let me know if you have any questions.
Restricting Examine search to just particular sections
Hi,
I have a main search and then I want to add landing pages that have their own search box and only search their own sub pages and folders.
How can this be achieved? Can indexes be set up to only search certain nodes? What about is new sections are added in the future? Would a new index then have to be manually set up? An editor would not be able to do this. Can it be done programatically?
Thanks a lot for any info!
We did something a lot like this for a site we are working on right now. We had set up a custom index and were using it for a faceted search. We needed to be able to restrict search results to the children of the page with the search on it. This is what we did:
Below is what I added to the
config/ExamineIndex.config
. What is most important here is adding theparentID
to theIndexAttributeFields
.When I wanted to perform my search, I add search criteria that restricts my search results to pages with a
parentID
that matches the id of the current page we are searching from. It might look something like this.Hope this helps you get started. Let me know if you have any questions.
is working on a reply...