Copied to clipboard

Flag this post as spam?

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

  • Anton Gildebrand 49 posts 149 karma points c-trib
    May 20, 2015 @ 15:00
    Anton Gildebrand

    Examine improve search suggestions

    I've recently deployed a fairly large site running Umbraco 7, and the site is using Examine for search functionality. Our search form auto suggest pages based on what the user enters.

    It doesn't work optimally however, the user have to enter pretty many characters before Examine returns any results.

    We want that if the user enters the letter "A" Examine returns all pages starting with A (big or small shouldn't matter). They should be sorted alphabetically. So when the user enters more characters more pages are shown. Right now the user have to spell out the entire word before Examine shows any results.

  • TikTakToe 57 posts 97 karma points
    May 20, 2015 @ 15:13

    Whenever i need to do anything complicated, i usually dip in RawQuery mode and use this guide to help:

    var query = string.format("Name:{0}*",term);
    var searchResults = searcher.Search(searcher.CreateSearchCriteria().RawQuery(query));

    For some reason i find RawQuery easier to pick up and understand, but as ever, i'm sure there are a million and 1 ways to do it!



  • Anton Gildebrand 49 posts 149 karma points c-trib
    May 20, 2015 @ 16:03
    Anton Gildebrand

    Thank you TikTakToe for your quick reply, works great :)

    However as soon as there are spaces in the search term, the results is weird and doesn't have any relevance anymore.

  • Ismail Mayat 4354 posts 9409 karma points MVP 2x admin c-trib
    May 20, 2015 @ 16:12
    Ismail Mayat


    You need to look at  your code that is doing the search I take it autosuggest is being called using jquery and that is making request to webapi?  

    If you want really good autosuggest then I would take a look at the elastic search definitive guide book ( there is chapter in there about the concepts of auto suggest.  Although its related to elastic search the principles (ngrams and edgegrams) relate to lucene or in this case examine is just a wrapper around just as elastic is wrapper around lucene.  



  • TikTakToe 57 posts 97 karma points
    May 20, 2015 @ 16:37

    hi anton

    can you not just add quotes around your term, like so?

    var query = string.format("Name:'{0}*'",term);

    Not tried this, so just a guess - also, your analysers will play an important part in how your queries return results and how whitespace is handled (aside: it may work to add in a custom field with the name stripped of spaces and also strip the spaces from your search term when you pass it in - look at gatheringnodedata event handler for more info)

    Also, donwload luke and open your index and you can play around with lucene queries to your hearts content - it's a good way to test raw queries and explore lucene:

    just remember to set the correct analyser to match the one in your examine config so you get the right results.

  • TikTakToe 57 posts 97 karma points
    May 20, 2015 @ 16:43

    something like

        private void OnGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
            var currentItem = Helper.TypedContent(e.NodeId);
            e.Fields.Add("lucenceSearchFriendlyName", e.Name.Replace(" ",""));

    then in your search:

    var query = string.format("lucenceSearchFriendlyName:{0}*",term.Replace(" ",""));
Please Sign in or register to post replies

Write your reply to: