Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 844 posts 2220 karma points
    Oct 04, 2019 @ 09:20
    Claushingebjerg
    0

    Search all fields by default

    So, i have this search working:

    if(ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index))
        {
            var searcher = index.GetSearcher();
            var textFields = new[] { "nodeName", "metaDescription_da-dk",  "bodyText", "bodyText_da-dk"};
            var results = searcher.CreateQuery("content").GroupedOr(textFields, searchTerm).Execute();
    
            if (results.Any())
            {
                <ul>
                    @foreach (var result in results)
                    {
                        if (result.Id != null)
                        {
                            var node = Umbraco.Content(result.Id);
                            <li>
                                <a href="@node.Url">@node.Name</a><br/>
                                @node.Value("metaDescription")
                            </li>
                        }
                    }
                </ul>
            }
            else
            {
                <p>No results found for query @searchTerm</p>
            }
        }
        return;
    }
        }
    

    But as it is now, i have to feed it all the document properties i want to search. Which could be ok, but its a multilingual site, so eg "bodyText" isn't searched, as it is bodyText_da-dk in Examine. So more work to keep in check. And even worse if the editor is allowed to create a new language... then this is not searched... So it would be nice to know a way to just search all fields..

    Thanks

  • Nik 1155 posts 4743 karma points MVP 2x c-trib
    Oct 04, 2019 @ 09:32
    Nik
    100

    Hey Claus,

    Yes it is possible.

    I believe if you use

    searcher.CreateQuery("content").ManagedQuery("searchtermhere")
    

    This should search all fields.

    Thanks

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft