Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alastair Todd 44 posts 142 karma points
    Jun 10, 2016 @ 11:03
    Alastair Todd
    0

    Examine can't search urlName, but Luke can

    I am indexing documents with their urlNames so that I can return a document by its slug e.g. "premiere-stay-fresh-j1-nokia".

    Luke returns the document when I search by that field, but Examine is not playing ball. Returns nothing (errs) with that code:

            var criteria = searcher.CreateSearchCriteria();
            var filter = criteria.Field("urlName", "premiere-stay-fresh-j1-nokia").Compile();
            var result = searcher.Search(filter).First();
    

    No idea what to do with that since Luke is happy.

  • Alastair Todd 44 posts 142 karma points
    Jun 10, 2016 @ 11:20
    Alastair Todd
    0

    So, it turns out Luke is using a different analyzer to search. All seems a bit dark arts, why the "Standard" anlyzer would search that different to the "KeywordAnalyzer" used by default by Luke.

    Anyway, work around was to create a Search for the latter and use that:

      <add name="PostSlugSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
            analyzer="Lucene.Net.Analysis.KeywordAnalyzer, Lucene.Net"
            indexSet="PostsIndexSet"/>
    
        var slugSearcher = ExamineManager.Instance.SearchProviderCollection["PostSlugSearcher"];
        var criteria = slugSearcher.CreateSearchCriteria();
        var filter = criteria.Field("urlName", "premiere-stay-fresh-j1-nokia").Compile();
        var result = slugSearcher.Search(filter).First();
    
  • David Armitage 508 posts 2078 karma points
    Aug 18, 2017 @ 07:20
    David Armitage
    1

    Hi,

    For anyone interested I was having the exact same problem. I was trying to search by urlName which just wasn't working.

    I managed to get this to work by following Alastair's solution.

    Basically I added to the ExamineSettings.config file

    <add name="SlugSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" analyzer="Lucene.Net.Analysis.KeywordAnalyzer, Lucene.Net" indexSet="ExternalIndexSet"/>
    

    So it should look something like this.

    <ExamineSearchProviders defaultProvider="ExternalSearcher">
        <providers>
          <add name="InternalSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
               analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/>
    
          <add name="ExternalSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" />
    
          <add name="InternalMemberSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" enableLeadingWildcard="true"/>
    
          <add name="SlugSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" analyzer="Lucene.Net.Analysis.KeywordAnalyzer, Lucene.Net" indexSet="ExternalIndexSet"/>
    
        </providers>
      </ExamineSearchProviders>
    

    I just re-used the standard ExternalIndexSet and it seemed to work fine. I tested searching on other custom fields and also using the urlName and all ok.

    Here is an example of my search code...

    var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["SlugSearcher"];
    var criteria = searcher.CreateSearchCriteria();
    criteria.NodeTypeAlias("blogArticle");
    criteria.Field("urlName", search.UrlName).Or();
    var searchResults = searcher.Search(criteria);   
    

    Hope this helps someone.

    Kind Regards

    David

  • Christian A 24 posts 98 karma points c-trib
    Oct 16, 2018 @ 09:45
    Christian A
    1

    I know the thread is a bit old but the reason still matters for future visitors.

    The reason the StandardAnalyzer wont come up with a match is that it uses Tokenization, which means spaces, dashes, etc. will split the word into terms.

    The KeywordAnalyzer on the other hand does not use Tokenization. This is good for situations where you are looking for exact matches including matching case.

    It can be read from the Lucene documentation:

    This should be a good tokenizer for most European-language documents:

    • Splits words at punctuation characters, removing punctuation. However, a dot that's not followed by whitespace is considered part of a token.
    • Splits words at hyphens, unless there's a number in the token, in which case the whole token is interpreted as a product number and is not split.
    • Recognizes email addresses and internet hostnames as one token.
Please Sign in or register to post replies

Write your reply to:

Draft