Copied to clipboard

Flag this post as spam?

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


  • Alan Howlett 19 posts 54 karma points
    Jul 16, 2013 @ 13:03
    Alan Howlett
    0

    Examine - Phrase search not working...

    Hi All,

    I'm using Examine with Umbraco 4.7.1 and having real trouble trying to get a phrase search working.  Everything I've tried so far always splits my term into separate words rather than searching the full phrase thus always returns zero results.

    The code I'm using to create my search is as follows:

                var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["EventSearcher"];
                var criteria = searcher.CreateSearchCriteria(BooleanOperation.And);
                var filter = criteria.Field("myField", "Phrase text here".Escape());
                var query = filter.Compile();

                SearchResults = searcher.Search(query);

    this will generate the following query:

    +myField:"Phrase text here"

    when I click on 'Explain Structure' in Luke, the query has been split into separate words.  I've tried using the following analysers to see if that makes any difference but no joy:

    WhiteSpaceAnalyzer
    ClassicAnalyzer
    StandardAnalyzer
    KeywordAnalyzer
    SimpleAnalyzer

    Anybody got any ideas what I'm doing wrong here?

     

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 18, 2013 @ 16:56
    Ismail Mayat
    0

    Alan,

    You got 2 options: 

    Split the query text on space then do and saerch 

    var words = "Phrase text here".splt(' ');

     IBooleanOperation examineQuery = criteria.OrderByDescending("whatever"); //not really sorting just want the  query object

    foreach(var word in words){

    examineQuery .And().Field("myField", word .Escape());

    }

    the other option is to use raw lucene query 

    var query = searchCriteria.RawQuery("+field:\"my phrase here\""); //something like that not tested
  • Alan Howlett 19 posts 54 karma points
    Jul 22, 2013 @ 10:50
    Alan Howlett
    0

    Thanks Ismail

    Based on those two options, I think I prefer the 'Raw Query' option as it seems a little cleaner.

    Thanks for your help.

Please Sign in or register to post replies

Write your reply to:

Draft