Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 363 posts 917 karma points
    Mar 07, 2019 @ 10:38
    Craig O'Mahony
    0

    Examine search not filtering out umbracoNaviHide

    Hi all,

    I've got an Umbraco instance (7.6.4) and I'm attempting to use the Examine searcher to create a search (based on https://www.youtube.com/watch?v=B9NeqMN9jIw) but I'm having trouble filtering out results where umbracoNaviHide to set to true on the node.

            ISearchCriteria searchCriteria = ExamineManager.Instance.CreateSearchCriteria(BooleanOperation.And);
            IBooleanOperation queryNodes = null;
    
            //only shows results for visible documents.
            queryNodes = searchCriteria.GroupedNot(new string[] { "umbracoNaviHide" }, "1");
    

    Has anyone experienced this or see what I'm doing wrong please?

    Thanks, C

  • Marc Love (uSkinned.net) 338 posts 894 karma points
    Mar 07, 2019 @ 10:53
    Marc Love (uSkinned.net)
    0

    Hi Craig,

    I use this:

    Examine.Providers.BaseSearchProvider baseSearchProvider = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
    
    var criteria = baseSearchProvider.CreateSearchCriteria(IndexTypes.Content, BooleanOperation.And);
    
    var examineQuery = criteria.Not().Field("umbracoNaviHide", "1");
    
    results = baseSearchProvider.Search(examineQuery.Compile());
    

    Cheers,

    Marc

  • Craig O'Mahony 363 posts 917 karma points
    Mar 07, 2019 @ 12:03
    Craig O'Mahony
    0

    Thanks Marc,

    Are you using an external index there?

    Thanks, C

  • Carlos Mosqueda 182 posts 273 karma points
    Jan 02, 2020 @ 21:04
    Carlos Mosqueda
    0

    Hide 'umbracoNaviHide' node/page or other property given from Examine Search Results

    Depending on what you are doing with the search or the index. You could do something like this. (Umbraco 7+)

    This is what we use in our View/Template

    @{
        var q = Request.QueryString["q"];
        var Searcher = Examine.ExamineManager.Instance.SearchProviderCollection["MySearchSearcher"];
    
            if(String.IsNullOrWhiteSpace(q))
            {
                q = "something if q is blank";
            }
    
            var searchResults = Searcher.Search(q, true).OrderByDescending(x => x.Score);
    
       foreach(var item in results){
         var node = Umbraco.Content(item.Id);
        var url = node.Url;
      @*don't show my things that have 'umbracoNaviHide' (or this can be some other value) *@
    
          if(node.GetPropertyValue<bool>("searchEngineSiteMapHide") == false){
          <div><a href="@url">@node.Name</a></div>
          }
       }@*end foreach*@
    }
    

    EXAMINESETTINGS.CONFIG

    <Examine>
      <ExamineIndexProviders>
        <providers> 
    
     <!--Add your own to this provider extension -->
         <add name="MySearchIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine" 
       supportUnpublished="false" 
       supportProtected="true" interval="10"
       analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" indexSet="MySearch" directoryFactory="Examine.LuceneEngine.Directories.SyncTempEnvDirectoryFactory, Examine" />
        </providers>
     </ExamineIndexProviders>
    
     <ExamineSearchProviders defaultProvider="ExternalSearcher">
        <providers>
      <!--Add your own. -->
            <add name="MySearchSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" indexSet="MySearch" enableLeadingWildcards="true" />
        </provider>
      </ExamineSearchProviders>
    
    </Examine>
    

    EXAMINEINDEX.CONFIG

    <!--Custom indexer setup-->
    
    <!-- The index set used by mysite.com for site search -->
       <IndexSet SetName="MySearch" IndexPath="~/App_Data/ExamineIndexes/MySearch/">
          <IndexAttributeFields>
            <add Name="id" />
            <add Name="name" />
          </IndexAttributeFields>
      <IndexUserFields>
     <add Name="SomePropertyIMade" />
     <!--Add others if you want-->
    </IndexUserFields>
    <IncludeNodeTypes>
      <add Name="NodeTypeIMade" />
        <!--Add others if you want-->
       </IncludeNodeTypes>
     </IndexSet>
    </ExamineLuceneIndexSets>  
    
Please Sign in or register to post replies

Write your reply to:

Draft