Copied to clipboard

Flag this post as spam?

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


  • Ben Tice 31 posts 131 karma points
    Mar 29, 2016 @ 20:34
    Ben Tice
    0

    Examine Search with Spaces in Search Term using Umbraco.TypedSearch

    Hi all,

    I've set up a search macro based on the documentation at https://our.umbraco.org/Documentation/Reference/Searching/Examine/quick-start. The search works well with the custom searcher and indexer I've set up, with one exception. When the search term has spaces, the returned results include everything with any of the words in the search term, i.e. "about company" returns all pages with about and all pages with company. What I'd like is all pages with the phrase "about company".

    I've tried setting the analyzer to "Lucene.Net.Analysis.KeywordAnalyzer, Lucene.Net", but don't get results after reindexing. Am I missing something?

    Here is my setup:

    ExamineIndex.config

        <IndexSet SetName="SiteSearchIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/SiteSearch/">
        <IndexAttributeFields>
            <add Name="id" />
            <add Name="nodeName" />
            <add Name="updateDate" />
            <add Name="writerName" />
            <add Name="nodeTypeAlias" />
        </IndexAttributeFields>
        <IndexUserFields>
            <add Name="pageContent" />
            <add Name="pageTitle" />
            <add Name="navigationName" />
        </IndexUserFields>
        <IncludeNodeTypes>
            <add Name="Homepage" />
            <add Name="NewsItem" />
            <add Name="TextPage" />
            <add Name="ProjectGallery" />
            <add Name="Project" />
            <add Name="Career" />
            <add Name="Testimonial" />
        </IncludeNodeTypes>
    </IndexSet>
    

    ExamineSettings.config

      <ExamineIndexProviders>
        <providers>
          ...
          <add name="SiteSearchIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine" />
        </providers>
      </ExamineIndexProviders>
      <ExamineSearchProviders defaultProvider="SiteSearchSearcher">
        <providers>
          ...
          <add name="SiteSearchSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" />
        </providers>
      </ExamineSearchProviders>
    

    In Macro Partial

    var selection = Umbraco.TypedSearch(Request.QueryString["q"]);
    

    Thanks in advance! Ben

  • Ben Tice 31 posts 131 karma points
    Mar 31, 2016 @ 17:13
    Ben Tice
    0

    For anybody else running in to this, there's something about how Umbraco.TypedSearch creates the search criteria when you pass a string to it. I've passed the search criteria using the following and it's working as I hoped:

    var q = Request.QueryString["q"];
    var searcher = ExamineManager.Instance.SearchProviderCollection["SiteSearchSearcher"];
    var searchCriteria = searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
    searchCriteria = searchCriteria.Field("pageTitle", q.Boost(4)).Or().Field("pageContent", q.Boost(2)).Compile();
    var selection = Umbraco.TypedSearch(searchCriteria, searcher);
    
Please Sign in or register to post replies

Write your reply to:

Draft