Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 886 posts 2415 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 1413 posts 6212 karma points MVP 3x c-trib
    Oct 04, 2019 @ 09:32
    Nik
    101

    Hey Claus,

    Yes it is possible.

    I believe if you use

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

    This should search all fields.

    Thanks

    Nik

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies