Copied to clipboard

Flag this post as spam?

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


  • Matt Taylor 859 posts 2052 karma points
    Nov 07, 2011 @ 18:36
    Matt Taylor
    0

    Examine MultipleCharacterWildcard search and the word 'and'

    I have the following string in the content of one of my pages:

    "The cats and dogs sleep."

    and the folowing code to perform the MultipleCharacterWildcard examine search:

    string keyword = "cats and dogs";
    string[] phrasedKeyword = SplitQueryWithQualifiers(keyword, ' ', '\"', true);

                //generate Search Criterea           
                m_Searcher = ExamineManager.Instance.SearchProviderCollection["myindexToSearch"];
                Examine.SearchCriteria.IBooleanOperation filter;
                var criteria = m_Searcher.CreateSearchCriteria(IndexTypes.Content, Examine.SearchCriteria.BooleanOperation.Or);

                if (keyword != "")
                {
                    filter = criteria.Field("umbracoNaviHide", "0");
                }
                else
                {
                    filter = null;
                }

                for (i = 0; i < phrasedKeyword.Length; i++)
                {
                    filter.And().GroupedOr(

                        new string[]
                        {
                            "nodeName",
                            "alternativeTitle",
                            "introText",
                            "bodyText",
                            "metaDescription",
                            "metaKeywords",
                            "FileTextContent"
                        },
                        new IExamineValue[]
                        {
                            phrasedKeyword[i].MultipleCharacterWildcard()
                        }

                    );
                }

    If I search using just 'cat' or 'dog' or 'cats' or 'cats dogs' the correct page is found.
    As soon as I introduce the word 'and' e.g. 'cats and dogs' the page is no longer returned in the results.

    I know words like and, a, I etc. get sripped out when the indeing is performed but how can I make the search work if they are entered by the user?

  • Matt Taylor 859 posts 2052 karma points
    Nov 08, 2011 @ 08:52
    Matt Taylor
    0

    I had the thought that if Examine removes common 'non-useful' words like 'and', 'I', 'a' should I be removing them from the user's search query string first?

    Thanks,

    Matt

  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Nov 08, 2011 @ 10:31
  • Matt Taylor 859 posts 2052 karma points
    Nov 09, 2011 @ 09:10
    Matt Taylor
    0

    Thanks for that link Ismail,

    I'll take a look and see if it's what I need.

    Cheers, Matt

     

  • Barry Fogarty 493 posts 1129 karma points
    Nov 09, 2011 @ 14:13
    Barry Fogarty
    0

    Matt, if you follow the steps in the linked page above to extend the StandardAnalyzer, and use a stopWords file that has the words you need removed, your phrase searches with e.g. 'and' will work.  After many hours of messing I finally got mine sorted - hopefully the info can save you the pain!

  • Matt Taylor 859 posts 2052 karma points
    Nov 11, 2011 @ 12:01
    Matt Taylor
    0

    Thanks for that guys. All is rosey now. :-)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies