I've set up a custom examine index/profile (following parrot fashion instructions found elsewhere on this site) and what I'd like to do is search for content using only this profile and not the 'standard' one that's already in the config files.
Here's what I've created in the ExamineIndex file
<!-- Default Indexset for external searches, this indexes all fields on all types of nodes--> <IndexSet SetName="ExternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/External/" />
<!-- Search criteria for the courses--> <IndexSet SetName="CourseSearch" IndexPath="~/App_Data/TEMP/ExamineIndexes/CourseSearch"> <IndexAttributeFields> <!--The below aren't really needed but included for completeness--> <add Name="id" /> <add Name="nodeName"/> <add Name="updateDate" /> <add Name="writerName" /> <add Name="nodeTypeAlias" /> </IndexAttributeFields>
<!--Custom fields that have been created and that we wish to search on--> <IndexUserFields> <add Name="courseDescription"/> <add Name="courseTitle"/> </IndexUserFields>
<!--The type of content that is being searched. In this case just the Courses--> <IncludeNodeTypes> <add Name="Course"/> </IncludeNodeTypes> </IndexSet>
<!--End of search -->
This is my ExamineSetting file
<ExamineIndexProviders> <providers> <add name="InternalIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine" supportUnpublished="true" supportProtected="true" analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/> <add name="InternalMemberIndexer" type="UmbracoExamine.UmbracoMemberIndexer, UmbracoExamine" supportUnpublished="true" supportProtected="true" analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/> <!-- default external indexer, which excludes protected and unpublished pages--> <add name="ExternalIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"/> <!--Search indexer for the courses search--> <add name="CourseIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine" supportUnpublished="false" supportProtected="true" interval="10" analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" indexSet="CourseSearch"/> <!--End of search indexer for the courses search-->
<!--Search Provider for the courses search--> <add name="CourseSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" indexSet="CourseSearch" enableLeadingWildcard="true"/>
</providers> </ExamineSearchProviders>
and this is how I'm calling the search in my controller but this is using both indexes I believe (certainly the ExternalIndexSet as I can seeing it's including all node types.
var zString = ""; if (!string.IsNullOrEmpty(zST)) { foreach (var result in Umbraco.TypedSearch(zST)) { zString += result.Name + ", "; } }
Could someone point me in the right direction please?
That's exactly the post I read to create the profile/index but the actual razor snippet that he's put in there (which is great) doesn't appear to do multi word searching, etc. that the Umbraco.TypedSearch seems to which is what really triggered my question.
This is based on passing an object from a webapi controller which I've named 'requestObject' which has a property called 'Keywords' which is just a comma-separated list of keywords.
Yeah I'd expect you to change the variable names but if the code works and you're not getting results I think the issue now is either with the index setup, is it configured properly? Have you checked that you have items in the index? And have you checked to make sure you're using the correct search provider?
Using Custom Examine Index
Hi Folks,
I've set up a custom examine index/profile (following parrot fashion instructions found elsewhere on this site) and what I'd like to do is search for content using only this profile and not the 'standard' one that's already in the config files.
Here's what I've created in the ExamineIndex file
This is my ExamineSetting file
and this is how I'm calling the search in my controller but this is using both indexes I believe (certainly the ExternalIndexSet as I can seeing it's including all node types.
Could someone point me in the right direction please?
Thanks in advance,
Craig
Hi Craig,
This post should have everything you need to get this wired up quite quickly.
http://24days.in/umbraco/2013/getting-started-with-examine/
Hi Richard,
That's exactly the post I read to create the profile/index but the actual razor snippet that he's put in there (which is great) doesn't appear to do multi word searching, etc. that the Umbraco.TypedSearch seems to which is what really triggered my question.
Thanks,
Does this work:
This is based on passing an object from a webapi controller which I've named 'requestObject' which has a property called 'Keywords' which is just a comma-separated list of keywords.
Hi Richard,
I'm not getting any errors but sadly no results!
I had to amend your code slightly to this:
ISearchCriteria searchCriteria = Examine.ExamineManager.Instance.CreateSearchCriteria(BooleanOperation.And);
searchCriteria = searchCriteria.GroupedOr(new[] { "allFields" }, zST.Replace(',', ' ').Split(' ')).Compile();
List<IPublishedContent> resultsList = new UmbracoHelper(UmbracoContext.Current).TypedSearch(searchCriteria, Examine.ExamineManager.Instance.SearchProviderCollection["CourseSearcher"]).ToList();
Where zST is my string eg. "Trust,Management"
Yeah I'd expect you to change the variable names but if the code works and you're not getting results I think the issue now is either with the index setup, is it configured properly? Have you checked that you have items in the index? And have you checked to make sure you're using the correct search provider?
Hi Richard,
Everything seems to be configured correctly. I've got items in the index and all that jazz.....
Craig,
If you want to search only in course index you need to do
ExamineManager.Instance.SearchProviderCollection["CourseSearcher"].CreateSearchCriteria(BooleanOperation.And);
your code currently defaults to external searcher.
Regards
Ismail
is working on a reply...