Copied to clipboard

Flag this post as spam?

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


  • Nadine Fisch 118 posts 332 karma points
    May 16, 2018 @ 09:28
    Nadine Fisch
    0

    ExternalSearcher create Searchcriteria

    Hi,

    the first time I get in contact with the ExternalSearcher and I try to extend the query to exclude special documenttypes for my search results.

    But I don't find the correct syntax to select the correct data. Here is the statement I want to adjust

    var results = searcher.Search(criteria2)
           .Where(x => (Here happens some magic I can't show to public)
            .ToList();
    

    So I search the correct wording to exclude some documenttypes. I've already thought about this solution, but the key in the dictionary seems to be wrong. How can I find out how to get the correct key?

       var results = searcher.Search(criteria2)
               .Where(x => (Here happens some magic I can't show to public) 
                &&(
                    x.Fields["DocumentTypeAlias"] != "infografikTeaser"
                 )  )
                .ToList();
    

    Another try:

      var results = searcher.Search(criteria2)
                   .Where(x => (Here happens some magic I can't show to public))
                    .Not().
                    .Field("DocumentTypeAlias","infografikTeaser").
                    .ToList();
    

    My knowledge about ExternalSearcher is very limited, maybe you give me some hints or tutorials so I can understand the technique behind this querying.

    Thank you in advance for your input.

    Cheers Nadine

  • Ismail Mayat 4137 posts 8584 karma points MVP admin c-trib
    May 16, 2018 @ 09:46
    Ismail Mayat
    1

    Nadine,

    You are using the searcher to search then trying to further filter the results using link which is not good. Can you show me the code for criteria2.

    If you want to ignore certain document types from your search you would do something like:

    BaseSearchProvider _searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
    

    var criteria = _searcher.CreateSearchCriteria(IndexTypes.Content);

    var examineQuery = criteria.Field("searchablePath", query.SiteRootId.ToString());

    examineQuery.Not().Field(HideFromNavigation, 1.ToString());

    foreach (var nodeTypeAlias in query.NodeTypeAliases) { examineQuery.Not().Field("nodeTypeAlias", nodeTypeAlias); }

    The ExternalSearcher is used to perform searches on your content using Examine which is a wrapper around lucene.net search engine.

    More information on it can be found here https://our.umbraco.org/Documentation/Reference/Searching/Examine/

  • Nadine Fisch 118 posts 332 karma points
    May 16, 2018 @ 10:03
    Nadine Fisch
    0

    Thank you very much for your fast reply. I'm sorry, but I'm not allowed to post the code, but I try to give you some parts:

    var criteria = searcher.CreateSearchCriteria();
     var query = new StringBuilder();
    
    ....(create query)....
    
    var criteria2 = criteria.RawQuery(query.ToString());
    

    query is a StringBuilder and there are many statements looking similiar to this

       query.AppendFormat("-{0}:1 ", model.HideFromSearchField);
    

    I try to understand your code and the tutorial, thank you!

  • Ismail Mayat 4137 posts 8584 karma points MVP admin c-trib
    May 16, 2018 @ 10:09
    Ismail Mayat
    100

    Nadine,

    Any reason why you are using raw query? Either way you need to update raw query and add to it:

    -nodeTypeAlias:infografikTeaser
    

    Also add more of these for any other node types you want to exclude.

    You can also test your raw queries on your external index using luke. See https://code.google.com/archive/p/luke/downloads use v 3.5.0 you will need java installed on your machine. The index lives in \App_Data\TEMP\ExamineIndexes\External\Index if you dont want to use luke there is also package https://our.umbraco.org/projects/backoffice-extensions/cogworks-examine-inspector/ you can test raw queries there as well

    Regards

    Ismail

  • Nadine Fisch 118 posts 332 karma points
    May 16, 2018 @ 10:13
    Nadine Fisch
    0

    I didn't write the code, so I can't answer the question why we are using a raw query here :) I think you give me all information I need and I try to put it together. Thanks ;)

  • Nadine Fisch 118 posts 332 karma points
    May 16, 2018 @ 11:41
    Nadine Fisch
    0

    it is working with

            query.AppendFormat("-nodeTypeAlias:InfografikTeaser ");
    

    You are great, thank you so much for your help!!

Please Sign in or register to post replies

Write your reply to:

Draft