Copied to clipboard

Flag this post as spam?

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


  • Marc Aarts 14 posts 35 karma points
    Nov 17, 2010 @ 09:22
    Marc Aarts
    0

    Examine 1.0 RTM Analyzer

    I'm trying to use the 'DemoSearch' usercontrol from umbraco.tv to search through Umbraco's internal Examine/Lucene index. My index is created fine and when I use Luke I see all the stuff I want to see.

    Because I want search results for 'foot' also match 'football', I am using like MultipleCharacterWildcard() this:

    .GroupedOr(new string[] { "nodeName", "docTitel", "docKort", "docTekst" }, SearchTerm.MultipleCharacterWildcard().Value)

     

    I am aware of the case-sensitivity issue/change in Examine 1.0 (Using v1.0 RTM on Umbraco 4.5), but I'm running into something weird.

    When I use Lucene.Net.Analysis.WhitespaceAnalyzer the searchcriteria look like this:

    { SearchIndexType: content, LuceneQuery: +(+(nodeName:werken* docTitel:werken* docKort:werken* docTekst:werken*)) +__IndexType:content }

    When I use Lucene.Net.Analysis.Standard.StandardAnalyzer the searchcriteria look like this:

    { SearchIndexType: content, LuceneQuery: +(+(nodeName:werken docTitel:werken docKort:werken docTekst:werken)) +__IndexType:content }


    As you can see, when using the StandardAnalyzer and still using MultipleCharacterWildcard, no '*' get added to the search filter and as a result 'foot' doesn't match 'football'.

    When using the WhitespaceAnalyzer I get no search results from Umbraco (though they work in Luke) so I'm forced to use StandardAnalyzer.

    Is there a way to get Examine to add wildcards to my search query when using the StandardAnalyzer?

     

     

     

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Nov 17, 2010 @ 12:41
    Aaron Powell
    0

    You need to pass in the IExamineValue object, not the generated string, otherwise Lucene doesn't know it's a wildcard query you're trying to cut and it'll strip out the '*' as it deems it illegal

  • Marc Aarts 14 posts 35 karma points
    Nov 17, 2010 @ 12:51
    Marc Aarts
    0

    Thanks for the reply slace, but I'm not sure I understand.

    I am not adding any '*' manually, as I know that won't work. That's why my code has 'MultipleCharacterWildcard()'.

    The searchcriteria valus I listed are generated, and I wanted to know how to get the wildcard behaviour when using StandardAnalyzer.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Nov 17, 2010 @ 12:54
    Aaron Powell
    0

    You're accessing the Value property of the IExamineValue, that's returning just a string so it's not being treated as a Lucene object by the analyzer

  • Marc Aarts 14 posts 35 karma points
    Nov 17, 2010 @ 14:01
    Marc Aarts
    0

    No no, I just had that value printed to the page and listed here to show what happens when I leave my code untouched but change the analyzer.

     

    This is the actual code:

     

            protected void Page_Load(object sender, EventArgs e)
            {
                SearchTerm = Request.QueryString["s"];
                if (string.IsNullOrEmpty(SearchTerm)) return;
               
                var criteria = ExamineManager.Instance
                        .SearchProviderCollection["InternalSearcher"]
                        .CreateSearchCriteria(UmbracoExamine.IndexTypes.Content);

                var filter = criteria
                   .GroupedOr(new string[] { "nodeName", "docTitel", "docKort", "docTekst" }, SearchTerm.MultipleCharacterWildcard().Value)
                   // .Not().Field("umbracoNaviHide", "1")
                   .Compile();

                litExamine.Text = String.Format("\n\n<!-- {0} -->\n\n", criteria.ToString());

                SearchResultsList =
                    ExamineManager.Instance.SearchProviderCollection["InternalSearcher"].Search(filter);

                SearchResultListing.DataSource = SearchResultsList;
                SearchResultListing.DataBind();

            }
  • Aaron Powell 1708 posts 3046 karma points c-trib
    Nov 17, 2010 @ 22:07
    Aaron Powell
    0

    You're doing this:

                var filter = criteria
                   
    .GroupedOr(new string[] { "nodeName", "docTitel", "docKort", "docTekst" }, SearchTerm.MultipleCharacterWildcard().Value)
                   
    // .Not().Field("umbracoNaviHide", "1")
                   
    .Compile();

    But you should do this:

                var filter = criteria
                   
    .GroupedOr(new string[] { "nodeName", "docTitel", "docKort", "docTekst" }, SearchTerm.MultipleCharacterWildcard())
                   
    // .Not().Field("umbracoNaviHide", "1")
                   
    .Compile();

    Notice the change to the end of the 2nd line

  • Marc Aarts 14 posts 35 karma points
    Nov 18, 2010 @ 08:14
    Marc Aarts
    0

    Thank you so much slace, both for your help here and Examine itself.

    I can't believe I missed that '.Value'! Odd that it worked fine with .Value using the WhitespaceAnalyze though.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Nov 18, 2010 @ 11:23
    Aaron Powell
    0

    It's because when the WhitespaceAnalyzer parses the query it doesn't remove the '*' from it, but the StandardAnalyzer will remove it.

  • Matt Taylor 873 posts 2086 karma points
    Mar 14, 2011 @ 18:00
    Matt Taylor
    0

    Can somebody tell me what I'm doing wrong?

    It won't recognise MultipleCharacterWildcard() as a valid string extension so I cannot compile it.

    I have references to Examine & UmbracoExamine and the folowing code:

    using Examine;
    using Examine.SearchCriteria;
    private void PerformSearch(string searchTerm)
            {
                if (string.IsNullOrEmpty(searchTerm)) return;
               
                var criteria = ExamineManager.Instance
                    .SearchProviderCollection["SiteSearchSearcher"]
                    .CreateSearchCriteria(UmbracoExamine.IndexTypes.Content);

                var filter = criteria
                    .GroupedOr(new string[] { "nodeName", "browserTitle", "metaKeywords", "metaDescription",
                        "featureTitle", "featureSummary", "title", "searchKeywords", "summary", "body", "footer" }, searchTerm.MultipleCharacterWildCard())
                    .Not()
                    .Field("umbracoNaviHide", "1")
                    .Compile();

                SearchResults = ExamineManager.Instance
                    .SearchProviderCollection["SiteSearchSearcher"]
                    .Search(filter);

                searchResultsRepeater.DataSource = SearchResults.Skip(CurrentPage * _pageSize).Take(_pageSize);
               
                searchResultsRepeater.DataBind();

            }

    Thanks, Matt

Please Sign in or register to post replies

Write your reply to:

Draft