Copied to clipboard

Flag this post as spam?

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


  • Peter Cort Larsen 339 posts 789 karma points
    18 days ago
    Peter Cort Larsen
    0

    Examine search: filter out nodes with umbracoNaviHide

    Hi,

    I am working a on combined search, which gets results from umbraco and from a custom table.

    But i cant figure out how to filter out umbraco nodes with umbracoNaviHide set to 1. Also i would like to boost the Umbraco nodes so they appear first in the search results.
    Can anyone help?

    Here a some code. Here is a link to the entire razor page: http://www.pcl.dk/searchumb.cshtml.zip

     var searcherNamedCollection = new NameValueCollection();
        searcherNamedCollection.Add("indexSets", "ExternalIndexSet");
        searcherNamedCollection.Add("indexSets", "CustomIndexSet");
    
        var searchProvider = new Examine.LuceneEngine.Providers.MultiIndexSearcher();
        searchProvider.Initialize("ExternalSearcher", searcherNamedCollection);
    
        ISearchCriteria searchCriteria = searchProvider.CreateSearchCriteria(BooleanOperation.Or);
    
        var searchQuery = searchCriteria.Field("nodeName", searchTerm.Fuzzy()).Or().Field("grid", searchTerm).Or().Field("Udbyder", searchTerm.Fuzzy()).Or().Field("Adresse", searchTerm.Fuzzy()).Or().Field("KursusType", searchTerm.Fuzzy()).Compile();
    
        ISearchResults searchResults = searchProvider.Search(searchQuery, maxResults: pageSize * (pageIndex + 1));
    
        var TotalItemCount = searchResults.TotalItemCount;
        var pagedResults = searchResults.Skip(pageIndex * pageSize);
    
  • Marc Love 274 posts 659 karma points
    18 days ago
    Marc Love
    0

    Hi Peter,

    Add the following to your searchCriteria:

    .Not().Field("umbracoNaviHide", 1.ToString());
    

    Cheers,

    Marc

  • Peter Cort Larsen 339 posts 789 karma points
    18 days ago
    Peter Cort Larsen
    0

    Hi Marc,

    Yes, i have seen this code in other posts.

    But for some reason it dosnt work when doing a combined search.

  • Ismail Mayat 4220 posts 8877 karma points MVP admin c-trib
    18 days ago
    Ismail Mayat
    0

    Is your custom index and umbraco index or something else? if it is something else it will not have umbracoNaviHide property

  • Peter Cort Larsen 339 posts 789 karma points
    18 days ago
    Peter Cort Larsen
    0

    Hi,

    Its only the Umbraco Index. Some pages has the umbracoNaviHide attribute set.

  • Peter Cort Larsen 339 posts 789 karma points
    18 days ago
    Peter Cort Larsen
    0

    Wonder, if it could be as simple as adding a umbracoNaviHide attribute to the non Umbraco Index?

  • Peter Cort Larsen 339 posts 789 karma points
    16 days ago
    Peter Cort Larsen
    0

    nah, thats not the solution.

  • Ismail Mayat 4220 posts 8877 karma points MVP admin c-trib
    15 days ago
    Ismail Mayat
    0

    Peter,

    Can you write out the generated query you can do this by outputting:

    searchCriteria.ToString()

    Just before you call searchProvider.Search

    This will output the lucene query

    Regards

    Ismail

  • Peter Cort Larsen 339 posts 789 karma points
    15 days ago
    Peter Cort Larsen
    0

    Hi,

    Then i get this:

    { SearchIndexType: , LuceneQuery: nodeName:test~0.5 grid:test Udbyder:test~0.5 Adresse:test~0.5 KursusType:test~0.5 -umbracoNaviHide:1 }

    But i still see nodes with umbracoNaviHide set to false.

  • Ismail Mayat 4220 posts 8877 karma points MVP admin c-trib
    15 days ago
    Ismail Mayat
    0

    Peter,

    At the start of you query creation you have boolean.or setup and therefore the query generated will be too permissive so you have the part -umbracoNaviHide:1 however its part of an overall or. So change:

    searchProvider.CreateSearchCriteria(BooleanOperation.Or);

    to

    searchProvider.CreateSearchCriteria(BooleanOperation.And);

    and try again also can you output the generated query again as well please.

  • Peter Cort Larsen 339 posts 789 karma points
    15 days ago
    Peter Cort Larsen
    0

    Hi,

    It gives me this query: { SearchIndexType: , LuceneQuery: +nodeName:test~0.5 grid:test Udbyder:test~0.5 Adresse:test~0.5 KursusType:test~0.5 -umbracoNaviHide:1 }

    No i dont see any data which matches Udbyder:test~0.5 Adresse:test~0.5 KursusType:test~0.5

    only umb pages, but it does not filtered out pages with umbracoNaviHide.

  • Ismail Mayat 4220 posts 8877 karma points MVP admin c-trib
    15 days ago
    Ismail Mayat
    0

    Peter,

    The query needs to look like:

    +(nodeName:test~0.5 grid:test Udbyder:test~0.5 Adresse:test~0.5 KursusType:test~0.5) -umbracoNaviHide:1

    So whatever is in brackets is an OR and outside bracket which is the navihide part is an and. So I am guessing you need a GroupedOr then an And

  • Peter Cort Larsen 339 posts 789 karma points
    1 week ago
    Peter Cort Larsen
    0

    Hi,

    This criteria:

    var searchQuery = searchCriteria.GroupedOr(new List<string> { "nodeName", "grid", "Udbyder", "Adresse", "KursusType" }, searchTerm.Fuzzy()).Not().Field("umbracoNaviHide", 1.ToString()).Compile();
    

    gives me:

     +(nodeName:test~0.5 grid:test~0.5 Udbyder:test~0.5 Adresse:test~0.5 KursusType:test~0.5) -umbracoUmbracoHide:1
    

    But still the pages containing the word 'test' are include, even if they are set to true in umbracoNaviHide.

    Its crazy.

  • Ismail Mayat 4220 posts 8877 karma points MVP admin c-trib
    18 days ago
    Ismail Mayat
    100

    Peter,

    Any reason why you are creating the searcher on the fly in code rather than in examine.config? I didn't know you could do it this way you live and learn as they say lol

  • Peter Cort Larsen 339 posts 789 karma points
    18 days ago
    Peter Cort Larsen
    0

    HI Ismail,

    Do you mean this part?

    var searcherNamedCollection = new NameValueCollection(); searcherNamedCollection.Add("indexSets", "ExternalIndexSet"); searcherNamedCollection.Add("indexSets", "CustomIndexSet");

  • MuirisOG 333 posts 1126 karma points
    1 week ago
    MuirisOG
    0

    Hi Peter

    I haven't tried combining search collections, but does the setting supportProtected="false" in the examinesettings.config file do anything?

    Thanks

    Muiris

  • Peter Cort Larsen 339 posts 789 karma points
    1 week ago
    Peter Cort Larsen
    0

    Hi,

    I found a solution:

    I added a searchprovider in ExamineSettings.config, which combines my 2 indexsets, instead of doing it in code.

    Then my query was changed to this:

     var searchQuery = searchCriteria.Field("nodeName", searchTerm.Fuzzy()).Or().Field("grid", searchTerm).Or().Field("Udbyder", searchTerm.Fuzzy()).Or().Field("Adresse", searchTerm.Fuzzy()).Or().Field("KursusType", searchTerm.Fuzzy()).Not().Field("umbracoNaviHide", 1.ToString()).Compile();
    

    Which gives me this ouput:

    nodeName:test~0.5 grid:test Udbyder:test~0.5 Adresse:test~0.5 KursusType:test~0.5 -umbracoNaviHide:1
    
Please Sign in or register to post replies

Write your reply to:

Draft