Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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:
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.
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.
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.
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);
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted