Copied to clipboard

Flag this post as spam?

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


  • Danny 46 posts 81 karma points
    Nov 01, 2010 @ 17:20
    Danny
    0

    Search all fields using Examine and fluent API

    I'm trying to do a search via Umbraco Examine in which I'm using the fuent API to add some specific criteria to my search, but I want the keywords used to apply to all indexed fields.  How do I do this?

    I know that simply using the below will search all fields:

    ExamineManager.Instance.SearchProviderCollection["MySearcher"].Search("Keyword");

    Can you search all fields when building ISearchCriteria via the fluent API though or do you manually have to add every field you want to search on?

    On a side note, I'll have to say that I've been fairly frustrated with the documentation (or lack thereof) regarding the Umbraco Examine API.  For example, the GroupedOr isn't even mentioned in the documentation that I could find, I just had to figure out how to make it work. 

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Nov 01, 2010 @ 23:24
    Aaron Powell
    0

    Searching across every field is going to yield lower performance than a properly structured query against the fields you actually want to check. The only way to achieve this is to use the GroupedOr statement, passing in each field and term you want to search against.

    As for lacking documentation, both Shannon and myself have full time jobs too, things get done when things get done.

  • lothar 25 posts 99 karma points
    Sep 08, 2013 @ 12:24
    lothar
    1

    I also was looking for a way to search through all fields using the API to use wildcard operations.

    I couldn't find any example so I wrote it myself where you don't need to list the properties yourself staticly.

    For any other that needs to search through every property with the API, here's an example:

    string search = "toSearchFor*";

    List<PropertyType> types = PropertyType.GetAll().ToList();

    List<string> fields = types.Select(pt => pt.Alias).Distinct().ToList();
    fields.Add("nodeName");

    var searcher = ExamineManager.Instance.SearchProviderCollection["ContentSearcher"];
    var criteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
    var query = criteria.GroupedOr(fields, search.MultipleCharacterWildcard());

    var results = searcher.Search(query.Compile());

    This searches every field (and every property that's added later) with wildcard search.

     

    My search searched less than 200 documents (and it won't be expanding so much) and went quite fast. But as slace said it could yield lower performance when searching through lots of documents.

  • Evan Moore 3 posts 73 karma points c-trib
    Sep 22, 2020 @ 00:27
    Evan Moore
    0

    I know this is an old question, but in V8 you don't have to load the PropertyTypes. You can get all fields in the index if you convert it to a LuceneSearcher like so:

    if((searcher is Examine.LuceneEngine.Providers.LuceneSearcher luceneSearcher))
    {
        allFields = luceneSearcher.GetAllIndexedFields();
        var query = criteria.GroupedOr(allFields, terms);
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft