Copied to clipboard

Flag this post as spam?

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


  • nickornotto 397 posts 900 karma points
    Sep 05, 2018 @ 14:35
    nickornotto
    0

    How to use Examine Search in case insesitive mode?

    I have an Examine search on my website and want to return same results whether I input lower or upper case keyword eg. same results should be expected when I search for 'nature' and 'Nature'.

    Currently I get some results for 'nature' but nothing for 'Nature'.

    I was using Lucene.Net.Analysis.WhitespaceAnalyzer by default.

    I tried to change the indexer and searcher to use Lucene.Net.Analysis.Standard.StandardAnalyzer as per advice here https://our.umbraco.com/forum/developers/extending-umbraco/14449-Examine-Search-Incase-sensitive but it doesn't do the job - I still get different results.

    My ExamineSettings:

      <ExamineIndexProviders>
        <providers>
          <add name="ProductsIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
               supportUnpublished="true"
               supportProtected="true"
               interval="10"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
      </ExamineIndexProviders>
    
      <ExamineSearchProviders defaultProvider="ExternalSearcher">
        <providers>
          <add name="ProductsSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
        </providers>
      </ExamineSearchProviders>
    

    Is there any other way I could try?

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Sep 05, 2018 @ 15:11
    Ismail Mayat
    0

    Manila,

    After changing analyser did you rebuild the index. Also can you show me your search code. How do you get the searcher.

    Also on your ProductsIndexer any reason why you are setting supportUnpublshed=true this will result in unpublihsed content being searchable on the front end.

    Regards

    Ismail

  • nickornotto 397 posts 900 karma points
    Sep 05, 2018 @ 15:39
    nickornotto
    0

    Yes, I rebuilt the index - I deleted the index folder and let the indexer recreate it.

    I'm filtering out unpublished content before outputting to the front end.

    This is my code so far:

    protected async Task<List<SearchResultViewModel>> GetSearchResultAsync(string examineSearcherName, string contentAliasToMatch, Dictionary<string, string> matchProperties = null)
        {
            List<SearchResultViewModel> list = new List<SearchResultViewModel>();
    
            var searcher = ExamineManager.Instance.SearchProviderCollection[examineSearcherName];
            ISearchCriteria searchCriteria = searcher.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content);
    
            List<SearchResult> searchResults = await SearchCriteriaResultAsync(searcher, searchCriteria, contentAliasToMatch, matchProperties);
    
            foreach (SearchResult result in searchResults)
            {
                SearchResultViewModel searchResult = new SearchResultViewModel(result.Fields);
                list.Add(searchResult);
            }
    
            return list;
        }
    
        protected async Task<List<SearchResult>> SearchCriteriaResultAsync(Examine.Providers.BaseSearchProvider searcher, ISearchCriteria searchCriteria, string contentAliasToMatch, Dictionary<string, string> matchProperties)
        {
            IBooleanOperation query = searchCriteria.NodeTypeAlias(contentAliasToMatch); 
    
            if (matchProperties != null && matchProperties.Any())
            {
                foreach (var item in matchProperties)
                {
                    query = query.And().Field(item.Key, item.Value);
                }
            }
    
            return await System.Threading.Tasks.Task.Run(() => {
                return (searcher.Search(query.Compile()).ToList());
            });
        }
    
  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Sep 05, 2018 @ 15:41
    Ismail Mayat
    0

    What are you setting examineSearcherName to? Also why are you going through the extra over head of filtering unpublished stuff when you can just not have them in the index?

    Regards

    Ismial

  • nickornotto 397 posts 900 karma points
    Sep 06, 2018 @ 07:19
    nickornotto
    0

    How does the actual name of the searcher matter for the case-sensitivity of results?

    It's not the worry of this thread whether I filter the results or not. Can you stick to the topic please?

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Sep 06, 2018 @ 07:49
    Ismail Mayat
    0

    I need to know which searcher you are using to figure out which index you are using.

  • nickornotto 397 posts 900 karma points
    Sep 06, 2018 @ 08:31
    nickornotto
    0

    I provided them in my initial post.

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Sep 06, 2018 @ 08:42
    Ismail Mayat
    0

    you provided the setup, in the code in the method GetSearchResultAsync(string examineSearcherName,

    what is examineSearcherName I am trying to determine if you are passing default searcher in which case you are searching on the external index or are you searching on the product index. Also when you say you get different results for different case are they different or is it just the order of the results is different.

    One more thing before this line

    return await System.Threading.Tasks.Task.Run(() => {

    can you do searchCriteria.ToString() this will give you the generated lucene query can you report back what is generated when you search lower and uppercase.

    Ismail

  • nickornotto 397 posts 900 karma points
    Sep 06, 2018 @ 10:59
    nickornotto
    0

    I'm searching on the product index not the default one.

    The queries I get respectively:

    {__NodeTypeAlias:product description:Nature}
    {__NodeTypeAlias:product description:nature}
    

    As I said: Currently I get some results for 'nature' but nothing for 'Nature'.

    Clearely it's not the order that is my worry but different results whatsoever.

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Sep 06, 2018 @ 12:29
    Ismail Mayat
    0

    Can you show me your examineindex.config file i need to see show you are storing the description field.

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft