Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 14, 2012 @ 12:39
    Bo Damgaard Mortensen
    0

    Examine autocomplete with multiple words

    Hi all,

    I'm trying to get my head around creating a autocomplete/suggest dropdown from a searchfield (just a simple input, really) using Examine. I have created a handler which is called when a user enters more than three characters in the input field.

    The examine code in my handler is as follows:

    ISearchCriteria criteria = ExamineManager.Instance.SearchProviderCollection["GlobalContentSearcher"].CreateSearchCriteria();
            IBooleanOperation query = criteria.Field("header", searchTerm.MultipleCharacterWildcard());
            ISearchResults results = ExamineManager.Instance.SearchProviderCollection["GlobalContentSearcher"].Search(query.Compile());

    When I write something in the input and a result is found, it shows the suggest dropdown as it should. However, when I enter multiple words, it disappears (thus no results)

    In example: I have a page with the header Hello World

    I enter "hello" in the input field and the page "Hello World" pops up in the suggest dropdown. When I enter the whitespace, it disappears - also when I start typing "world".

    Is there any way to make examine/lucene search for a phrase rather than a single word? :-)

    Thanks in advance!

    - Bo

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 15, 2012 @ 11:43
    Bo Damgaard Mortensen
    0

    I went and made the search with XPath instead of Examine. The performance is almost the same and it works with whitespace aswell.

    Code:

    var nodes =
                uQuery.GetNode(nodeId).GetAncestorNodes().FirstOrDefault(c => c.NodeTypeAlias.Equals("Site")).
                    GetDescendantNodes().Where(x => x.NodeTypeAlias.Equals("Recipe")).Where(n => n.GetProperty("header").Value.ToLower().Contains(searchTerm.ToLower()));

     

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 15, 2012 @ 16:00
    Ismail Mayat
    0

    Bo,

    In examine before doing the query check for white space if its there split on it then do or query with each term.  uQuery is fine for now but once you start getting more nodes you will not get same performance as examine which is lightening quick!!

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft