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 421 posts 1038 karma points
    Jan 04, 2019 @ 13:11
    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 (uSkinned.net) 447 posts 1789 karma points
    Jan 04, 2019 @ 13:30
    Marc Love (uSkinned.net)
    0

    Hi Peter,

    Add the following to your searchCriteria:

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

    Cheers,

    Marc

  • Peter Cort Larsen 421 posts 1038 karma points
    Jan 04, 2019 @ 15:03
    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 4511 posts 10092 karma points MVP 2x admin c-trib
    Jan 04, 2019 @ 15:12
    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 421 posts 1038 karma points
    Jan 04, 2019 @ 15:21
    Peter Cort Larsen
    0

    Hi,

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

  • Peter Cort Larsen 421 posts 1038 karma points
    Jan 04, 2019 @ 15:23
    Peter Cort Larsen
    0

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

  • Peter Cort Larsen 421 posts 1038 karma points
    Jan 06, 2019 @ 15:41
    Peter Cort Larsen
    0

    nah, thats not the solution.

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jan 07, 2019 @ 06:41
    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 421 posts 1038 karma points
    Jan 07, 2019 @ 14:29
    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 4511 posts 10092 karma points MVP 2x admin c-trib
    Jan 07, 2019 @ 14:35
    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 421 posts 1038 karma points
    Jan 07, 2019 @ 15:06
    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 4511 posts 10092 karma points MVP 2x admin c-trib
    Jan 07, 2019 @ 15:19
    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 421 posts 1038 karma points
    Jan 08, 2019 @ 10:09
    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 4511 posts 10092 karma points MVP 2x admin c-trib
    Jan 04, 2019 @ 13:45
    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 421 posts 1038 karma points
    Jan 04, 2019 @ 15:02
    Peter Cort Larsen
    0

    HI Ismail,

    Do you mean this part?

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

  • MuirisOG 382 posts 1284 karma points
    Jan 08, 2019 @ 11:48
    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 421 posts 1038 karma points
    Jan 08, 2019 @ 14:40
    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