Copied to clipboard

Flag this post as spam?

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


  • Danny 9 posts 28 karma points
    Apr 18, 2014 @ 09:47
    Danny
    0

    How to get correct searchresults with examine

    I have some troubles getting correct searchresults when using Examine.

    It seems some words are just not returned, even though they are included in the index (which I checked with Luke toolbox).
    My search criteria look something like this

    .Field("contentText", searchTerm.Fuzzy(0.5f)).Or()
    .Field("contentText", searchTerm.MultipleCharacterWildcardFuzzy(0.3f)

    The searchTerm variable is the searchterm entered in the searchbox on the site, with "*" added at the beginning and end of the variable. I have enabled the leadingwildcard in the examineindex.config. Without this option barely any result is returned. 

    The main problem now is that when I enter a searchterm, sometimes it returns results, but other times it doesn't.
    If I search for a string "I like strawberries" it returns the pages where the phrase "I like strawberries" is used. But when I search for a similar string, like "you like apples" it can very well return nothing at all even though that sentence is used on multiplepages and can be found using the Luke toolbox (so it is in the Index). 

    I've tried lowering the treshold in the Fuzzyoption, but this seems to return only results that don't seem to have any relation to the searchterms, but still doesn't return the pages where the string can be found. 

    Searching on part of the string (for example "you" or "apples" will return the page in the search results. At first I thought spaces could be the problem, but it doesn't explain why other strings with spaces are returned normally. 

    I'm pretty new to Umbraco, and now I am running a bit out of clues. Currently I am using version 4.11.9


    The function I use looks something like this

    Examine.Providers.BaseSearchProvider baseSearchProvider = ExamineManager.Instance.DefaultSearchProvider;
    IEnumerable<SearchResult> nodesPre = null;
    List<SearchResult> nodes = new List<SearchResult>();
    Lucene.Net.Search.Searcher luceneSearcher = null;

    var searchCriteria = ExamineManager.Instance.CreateSearchCriteria(IndexTypes.Content, Examine.SearchCriteria.BooleanOperation.Or);
    var query = searchCriteria

    .Field("contentText",searchTerm.MultipleCharacterWildcard()).Or()
    .Field("content", searchTerm.MultipleCharacterWildcard()).Or()
    .Field("contentText", searchTerm.Fuzzy(0.3f)).Or()
    .Field("content", searchTerm.Fuzzy(0.3f))
    .Compile();

    var results = baseSearchProvider.Search(query); //.OrderByDescending(x => x.Score)
    luceneSearcher = ((Examine.LuceneEngine.SearchResults)results).LuceneSearcher;
    nodesPre = results.OrderByDescending(x => x.Score);

    I've ommitted a number of fields, the search should include some more fields, but for testing I only use contentText and content.

    Does anyone have a clue that could nudge me in the right direction. I've already improved the results by including wildcardsearches, but I'm still nog quite there yet. 

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 18, 2014 @ 12:02
    Alex Skrypnyk
    0

    Hi Danny,

    1) You can try to install Examine Manager package and test your search results without your code just from the admin part.

    2) As said Aaron Powell on this post : http://our.umbraco.org/forum/developers/extending-umbraco/16893-Examine-MultipleCharacterWildcard()-on-a-word-with-an-apostrophe

    You probably need to call Escape before you use the Wildcard. I've never tested with apostrophized queries though

    Thanks, Alex

  • Danny 9 posts 28 karma points
    Apr 18, 2014 @ 15:57
    Danny
    0

    And how can I call Escape?

    And is there a way I can push a raw query to Lucene. If I try the raw query I compile in Luke Tool it seems to give decent results. Now I only have to find a way to use this query to execute. Somewhere along the way it seems to mess up the results, but I cannot find out where.

    var results = baseSearchProvider.Search(query); //.OrderByDescending(x => x.Score) luceneSearcher = ((Examine.LuceneEngine.SearchResults)results).LuceneSearcher; nodesPre = results.OrderByDescending(x => x.Score);

    This is what I am currently doing to return results.

  • Danny 9 posts 28 karma points
    Apr 22, 2014 @ 09:01
    Danny
    0

    I've found out the actual querystring that is parsed to the lucenesearch.

    +((contentText:you like apples) contentText:you like apples* content:you like apples* contentText:you like apples~0.3 content:you like apples~0.3) +__IndexType:content

    When this is executed, it returns zero results on the website. In the Luke toolbox however it returns 5 results.

    var results = baseSearchProvider.Search(query); //.OrderByDescending(x => x.Score) luceneSearcher = ((Examine.LuceneEngine.SearchResults)results).LuceneSearcher; nodesPre = results.OrderByDescending(x => x.Score);

    this is the part that executes the query, and something goes wrong here. But I cannot find out what.

  • Danny 9 posts 28 karma points
    Feb 04, 2015 @ 13:59
    Danny
    0

    It has been a while since I have been trying to get this fixed. But unfortunately it still doesn't work properly.

    does anyone have an example of a properly working searchfunction? I have used the sample posted above, but it doesn't return proper results.

    currenlty I use the following query

        var query = searchCriteria
       .Field("titel", searchTerm.Fuzzy(0.7f)).Or()
       .Field("text", searchTerm.Fuzzy(0.7f)).Or()
       .Field("nodeName", searchTerm.Fuzzy(0.7f)).Or()
       .Field("vraag", searchTerm.Fuzzy(0.7f)).Or()
       .Field("antwoord", searchTerm.Fuzzy(0.7f)).Or()
       .Field("bodyText", searchTerm.Fuzzy(0.7f)).Or()
       .Field("homeContent2", searchTerm.Fuzzy(0.7f)).Or()
       .Field("intro", searchTerm.Fuzzy(0.7f)).Or()
    
       .Field("titel", searchTerm.MultipleCharacterWildcard()).Or()
       .Field("text", searchTerm.MultipleCharacterWildcard()).Or()
       .Field("nodeName", searchTerm.MultipleCharacterWildcard()).Or()
       .Field("vraag", searchTerm.MultipleCharacterWildcard()).Or()
       .Field("antwoord", searchTerm.MultipleCharacterWildcard()).Or()
       .Field("bodyText", searchTerm.MultipleCharacterWildcard()).Or()
       .Field("homeContent2", searchTerm.MultipleCharacterWildcard()).Or()
       .Field("intro", searchTerm.MultipleCharacterWildcard())
       .Compile();
    

    This should return the correct data, but it doesn't, randomly searchwords seem to be omitted, even though they are in the index.

    Does anyone have an idea how to fix this?

  • Danny 9 posts 28 karma points
    Feb 10, 2015 @ 09:20
    Danny
    0

    Anyone?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Feb 10, 2015 @ 11:06
    Alex Skrypnyk
    100

    Hi Danny,

    It's working example:

        var count = HttpContext.Request.Params["count"] ?? "0";
        var searcher = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"];
        var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
        ISearchCriteria query = null;
        var term = model.SearchText;
        var luceneString = "nodeName:";
    
        query = searchCriteria.RawQuery(term);
    
        var searchResults = searcher.Search(query);
        ViewBag.countItem = searchResults.TotalItemCount;
        var resultCollection = searchResults.Skip(Int32.Parse(count)).Take(10);
    

    Thanks, Danny

Please Sign in or register to post replies

Write your reply to:

Draft