Copied to clipboard

Flag this post as spam?

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


  • Jason Espin 368 posts 1335 karma points
    Aug 28, 2015 @ 13:08
    Jason Espin
    0

    Examine helpers converting negative numbers to positive

    Hi all,

    I am currently building an examine query in Umbraco based upon a media index I have created in Umbraco.

    My query is built as follows:

    BaseSearchProvider MediaSearcher = Examine.ExamineManager.Instance.SearchProviderCollection["MediaSearcher"];
    ISearchCriteria mediaCriteria = MediaSearcher.CreateSearchCriteria();
                IBooleanOperation mediaQuery = mediaCriteria.Field("parentId", "-1");
                switch (umbraco_node.ContentType.Alias.ToLower())
                {
                    case "country":
                        mediaQuery = mediaQuery.And().Field("nodeTypeAlias", "countryImages");
                    break;
    
                    case "area" :
                        mediaQuery = mediaQuery.And().Field("nodeTypeAlias", "areaImages");
                    break;
    
                    case "city" :
                        mediaQuery = mediaQuery.And().Field("nodeTypeAlias", "cityImages");
                    break;
    
                    case "activity" :
                        mediaQuery = mediaQuery.And().Field("nodeTypeAlias", "activityImages");
                    break;
    
                    case "hotel" :
                        mediaQuery = mediaQuery.And().Field("nodeTypeAlias", "hotelImages");
                    break;
    
                    case "package" :
                        mediaQuery = mediaQuery.And().Field("nodeTypeAlias", "packageImages");
                    break;
                }
    
                ISearchResults mediaResults = MediaSearcher.Search(mediaQuery.Compile());
    

    The problem I am facing is this should be returning results and in the back office searcher is however I think there may be a bug in the Umbraco helpers as my query when compiled is being converted to the following:

    {+parentId:1 +nodeTypeAlias:countryimages}
    

    This is obviously incorrect as I have clearly specified -1 above.

    Could someone tell me the best way to force this value to be negative?

  • Mark Bowser 273 posts 860 karma points c-trib
    Aug 28, 2015 @ 17:48
    Mark Bowser
    0

    To be honest, I haven't tried this, so it might not work, but I'm hopeful. Try escaping the -1, so

    IBooleanOperation mediaQuery = mediaCriteria.Field("parentId", "\-1");
    

    I believe that the - symbol tells lucene to exclude some values. Check out this raw lucene query tutorial

    In the Examine Management dashboard on one of our dev sites, I tried running this query as a lucene search and had errors:

    parentID: -1
    

    But I got the expected results when I ran this query:

    parentID: \-1
    
  • Jason Espin 368 posts 1335 karma points
    Sep 09, 2015 @ 09:25
    Jason Espin
    0

    Hi Mark,

    Unfortunately, that was the first thing I tried and when it is run in code it seems to ignore the escape character and still processes this as 1. I therefore had to revert to using the raw lucene query methods where I built my query up in a string and then passed it into the searcher.

    Cheers,

    Jason

Please Sign in or register to post replies

Write your reply to:

Draft