Copied to clipboard

Flag this post as spam?

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


  • Jeremy 23 posts 72 karma points
    Oct 21, 2010 @ 00:29
    Jeremy
    1

    Examine: Multiple search terms vs Phrases

    Hello,

    I have Examine setup and working, but am running into issues when searching for multiple terms, it always seems to treat my multiple terms as a single phrase.

    For example, in my bodyText I have the following text:  the blue sky is pretty

    If I search for:  blue sky , it returns results.

    If I search for: sky blue , it returns NO results...

    I have configured my search  as shown in the Examine video on Umbraco.tv.

     

     var criteria = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"].CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
    var filter = criteria.GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags" }, SearchTerm).Compile();
      SearchResults = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"].Search(filter);

     

    I'm not sure what I am doing wrong here...Do I need to get my search terms and split them into a string array?  I sort of assumed that happened by default with the delimiter being whitespace between words.

    Any help would be greatly appreciated, I've searched around and look at many examples without any luck.  Thanks!

     

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Oct 21, 2010 @ 04:52
    Aaron Powell
    1

    Examine doesn't implement PhraseQuery (http://lucene.apache.org/java/2_9_2/api/all/org/apache/lucene/search/PhraseQuery.html) which is what you're wanting to achieve that.

    The reason this doesn't match is because you're looking for the ext that you're passing in, and since the word "sky" and the word "blue" are not next to each other (in that order) the match wont occur.

    To implement a very simple pesudo-PhraseQuery you should split each search term by space and add multiple GroupedOr statements for each single word.

    Alternatively you can create a custom Searcher and modify the way the API generates queries to support PhraseQuery.

  • Jeremy 23 posts 72 karma points
    Oct 21, 2010 @ 19:54
    Jeremy
    1

    Thanks @slace for taking the time to reply, I think I got it sorted out now...

    Probably not the cleanest code, but here is what I am using in case others find it useful.

    First I take the SearchTerm, and then split up all the terms and/or phrases into a string array. I am using a split function that supports text qualifiers, you can find it here:

    http://www.codeproject.com/KB/dotnet/TextQualifyingSplit.aspx?msg=2518619

    Then just loop through the string array, building the Fluent query.

    var criteria = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"].CreateSearchCriteria();

                Examine.SearchCriteria.IBooleanOperation filter = null;

                int i = 0;
                for (i = 0; i < aSearchTerm.Length; i++)
                {
                    if (filter == null)
                    {
                        filter = criteria.GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags" }, aSearchTerm[i]);
                    }
                    else
                    {
                        filter = filter.Or().GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags" }, aSearchTerm[i]);
                    }
                }

                SearchResults = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"].Search(filter.Compile());
  • Connie DeCinko 931 posts 1160 karma points
    Jun 28, 2011 @ 22:24
    Connie DeCinko
    0

    Sorry to be so dense... but where is your code to split the SearchTerm?  I have the split function but don't see how you use the function.  What delimiter and qualifier are you using?

     

  • Connie DeCinko 931 posts 1160 karma points
    Sep 28, 2011 @ 20:41
    Connie DeCinko
    0

    Hello?  Is anyone following this thread?  The shown example does not work.

     

  • tankovski.stoian 1 post 21 karma points
    Nov 22, 2014 @ 23:27
    tankovski.stoian
    0

    Simple solution, that i have founnd using raw queries

      var searchTerm = Request["term"].Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
    var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
          var searchCriteria = searcher.CreateSearchCriteria();
          var luceneString = new System.Text.StringBuilder();
          luceneString.Append("nodeTypeAlias:");
    
          luceneString.Append("*");
    
          for (int i = 0; i < searchTerm.Length; i++)
          {
    
              luceneString.Append(" AND ");
    
              luceneString.Append("title:");
              luceneString.Append("*");
              luceneString.Append(searchTerm[i]);
              luceneString.Append("*");
          }
    
          var query = searchCriteria.RawQuery(luceneString.ToString());
          var searchResults = searcher.Search(query);
    
    this article helped me http://www.lucenetutorial.com/lucene-query-syntax.html
Please Sign in or register to post replies

Write your reply to:

Draft