简体   繁体   中英

Umbraco - Examine not searching IndexUserFields in custom IndexSet

Apologies in advance if I'm missing something obvious here as this is the first time I've used Examine, but I'm currently trying to hook up a jQuery autocomplete call to an Examine search in Umbraco. I need Examine to search for a search term (provided via jquery.autocomplete) in both an Attribute Field ("nodeName") and a User Field ("itemNumber"). The search uses a custom IndexSet that I created in the ExamineIndex.config file and is set up like so:

<IndexSet SetName="ProductQuickSearchIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/{machinename}/ProductQuickSearchIndex/">
  <IndexAttributeFields>
    <add Name="id" />
    <add Name="nodeName"/>
    <add Name="nodeTypeAlias" />
  </IndexAttributeFields>
  <IndexUserFields>
    <add Name="itemNumber"/>
  </IndexUserFields>
  <IncludeNodeTypes>
    <add Name="Product" />
    <add Name="Item" />
  </IncludeNodeTypes>
</IndexSet>

I also have an IndexProvider and a SearchProvider set up in the ExamineSettings.config file that are both tied to this IndexSet.

<!-- IndexProvider -->
<add name="ProductQuickSearchIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
      supportUnpublished="false"
      supportProtected="true"
      analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"
      indexSet="ProductQuickSearchIndexSet"/>

<!-- Search Provider -->
<add name="ProductQuickSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
 analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" indexSet="ProductQuickSearchIndexSet"/>

The jQuery autocomplete call is being routed to a controller that handles the request and uses a search repository to actually execute the Examine Search:

public JsonResult ProductQuickSearch(string term)
    {
        var searchResults = searchRepository.ProductQuickSearch(term);
        // Process results, send back through JSON
    }

And here is the Search Repository method that I'm having trouble with. In the query, my goal is to have Examine search for the search term in both the "nodeName" field and the "itemNumber" field of the nodes I specified in the IndexSet. However, currently, it is only searching the "nodeName" field and the "itemNumber" field is all but ignored .

public List<SearchResult> ProductQuickSearch(string searchTerm)
    {
        var Searcher = ExamineManager.Instance.SearchProviderCollection["ProductQuickSearcher"];
        var searchCriteria = Searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
        var query = searchCriteria.Field("nodeName", searchTerm).Or().Field("itemNumber", searchTerm).Compile();
        return Searcher.Search(query).OrderByDescending(x => x.Score).ToList();
    }

Any and all help is appreciated. Thanks in advance!


EDIT

It looks like, for some reason, the itemNumber field is triggering matches, but only when the query is an exact match. For example, if an example of an item number is M100.50-000-AE, I can get the proper item to show up, but only if my search query is "M100.50-000-AE" and not anything less than that, not even "M100.50-000-A". So with the query how I have it, nodeName is being searched using a "contains" methodology, but itemNumber is only being searched by exact match.

First things first, check your Custom Index to make suer that the field is in there. To do this, goto the developer section and click on the "Examine Management" tab. Select your index from the list of indexers, choose "user fields" and then check that your custom field is listed.

Next, click into the searcher, and try searching for a page that should have that field set, you should be able to see if the fields in the search results.

If it's not showing up, it's an issue with the indexes themselves, otherwise, it could be something in your code, although your code looks OK. Is the search term something that should match in the itemNumber field?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM