Copied to clipboard

Flag this post as spam?

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


  • Manish 373 posts 932 karma points
    Apr 12, 2017 @ 12:57
    Manish
    0

    Examine search for phrase search

    Hi All,

    I am using examine search and want to search phrase not the word

    I try in two ways

    First one like this

     var fieldsToSearch = new[]
                    {
                 "type", "topic",  "format", "nodeName", "createDate", "updateDate", "bannerTitle",
                    "bannerText", "articleDescription", "shortDescription", 
                };
         IBooleanOperation filter = searchCriteria.GroupedOr(fieldsToSearch, "\"" + SearchTerm + "\"");
    

    But when i search some phrase on page some time it returns result and some time not. For example if i search "an apomorphine infusion" it return me the result but if i search "apomorphine infusion or a pump" it returns nothing means no result. Both phrase are on same page.

    I also tried using this way

      string rawQuery = "";
                    string oneFieldRawQuery = "(contentTitle:" + "\"" + SearchTerm + "\"" + ")";
    
                    rawQuery = oneFieldRawQuery;
                    rawQuery += " OR " + oneFieldRawQuery.Replace("contentTitle:", " bannerText:");
                    rawQuery += " OR " + oneFieldRawQuery.Replace("contentTitle:", " articleDescription:");
                    rawQuery += " OR " + oneFieldRawQuery.Replace("contentTitle:", " shortDescription:");
                    rawQuery += " OR " + oneFieldRawQuery.Replace("contentTitle:", " articleBody:");
                    rawQuery += " OR " + oneFieldRawQuery.Replace("contentTitle:", " newsBody:");
                    rawQuery += " OR " + oneFieldRawQuery.Replace("contentTitle:", " pageContentSection:");
                    var results = Searcher.Search(searchCriteria.RawQuery(rawQuery).OrderBy().Compile());
    

    But it is returning me the same result.

    Please suggest me the way to achieve Phrase search or what i am doing wrong.

    Manish

  • Manish 373 posts 932 karma points
    Apr 13, 2017 @ 10:31
    Manish
    100

    Able to solve problem

    Basically the problem was Standard analyser class omit some words if it is part of phrase which you are searching to solve this I need to write some custom code

    1. Create a class in your project at root - lets say MyMemberAnalyzer.cs

    write code in this

    namespace YourProject
    {
        public class MyMemberAnalyzer : StandardAnalyzer
        {
            private static TextReader stopWords = File.OpenText(HttpContext.Current.Server.MapPath("~/config/LuceneStopWordsForStandardAnalyzer.txt"));
    
            public MyMemberAnalyzer() : base(Lucene.Net.Util.Version.LUCENE_29, stopWords) { }
        }
    }
    
    1. Create a txt file in config folder and add words

    "a", "an", "and", "are", "as", "at", "be", "but", "by","for", "if", "in", "into", "is", "no", "not", "of", "on", "or", "such","that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"

    1. Now go to examinesetting.config file

    and add analyzer like this

     <add name="YourIndexer"
               type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
               supportUnpublished="false"
               supportProtected="false"
                  analyzer="NameSpace_of_YourProject.MyMemberAnalyzer, NameSpace_of_YourProject"/>
    
     <add name="YourSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
                 analyzer="NameSpace_of_YourProject.MyMemberAnalyzer, NameSpace_of_YourProject"/>
    
    1. Now clear app data folder

    2. Rebuid your index from CMS which you can find under developer > examine management

    3. Now try searching phrase.

    Manish

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

    Continue discussion

Please Sign in or register to post replies