Copied to clipboard

Flag this post as spam?

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


  • Raluca Dumitru 33 posts 174 karma points
    Feb 12, 2020 @ 10:06
    Raluca Dumitru
    0

    Search Results

    Hi all,

    I was wondering if there is a way in Umbraco, when searching through content, to return only the objects that contain the full search string?

    For example if I am searching for 'people management', I want to return only content that contains 'people management' next to each other, exactly like in my search.

    I don't want content that has 'people' in one sentence and 'management' in another one.

    Thank you.

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Feb 12, 2020 @ 11:46
    Ismail Mayat
    0

    Raluca,

    I am guessing this is for search on umbraco front end of the site not in the umbraco backoffice?

    In examine you can do phrase query i think you would have do it with raw lucene query so

    +content:"people mangement"
    

    You can set up examine to use And operator instead of OR but i think that would match if you had people and mangement on different lines. Phrase would do exactly what you want but you need to do raw query.

               ExamineManager.Instance.TryGetIndex(Umbraco.Core.Constants.UmbracoIndexes.ExternalIndexName, out var index);
    
            var searcher = index.GetSearcher();
    
            var query = searcher.CreateQuery("content").Field("excludeFromSearch", "0");
    
            query.And().NativeQuery("+content:\"people mangement\"");
    

    This is assuming the field you want to search over is called content, you will need to replace that with whatever field you want to search over.

    Regards

    Ismial

Please Sign in or register to post replies

Write your reply to:

Draft