I'm new to examine. The help on codeplex implies adding a field's search term without escaping it will cause the term to be searched as a multi query, i.e. a search term of Umbraco Rocks will return results matching either Umbraco or Rocks. I'm not finding this to be the case, but my specific customer requires an or search on each word in the search term. Here's my code:
int fieldCount = searchFields.GetLength(0); string[] searchParams = new string[fieldCount]; for (int i = 0; i < fieldCount; i++) { searchParams[i] = searchTerm; }
if (!string.IsNullOrEmpty(OrderByFieldList)) { string[] orderByFields = OrderByFieldList.Split(',');
if (OrderByDescending) criteria.OrderByDescending(orderByFields); else criteria.OrderBy(orderByFields); }
// get the search result set IEnumerable<SearchResult> results = ExamineManager.Instance.SearchProviderCollection[SearchProviderName].Search(criteria).AsEnumerable();
...
As you can see, I'm not escaping the search term. Do I need to break up the search term explicitly?
I'm using Lucene.Net.Analysis.Standard.StandardAnalyzer for index and search. I'm also using Umbraco 4.52
Doing a search like .Field("someField", "Umbraco Rocks") will create a Lucene query which is someField:Umbraco Rocks, and since the word "rocks" isn't associated with a field it'll fall back to the default field for the search, which Examine doesn't set (it has no idea what field should be the default one).
If you're trying to search on "Umbraco Rocks" as a phrase then you need to escape it. If you want to match documents which contain either Umbraco or Rocks then there is the GroupedOr operator and if you want to match documents which only contain Umbraco and Rocks then you need to use the GroupedAnd.
Hi Mark. Slace is right (of course :), but I thought I'd add my 2c anyway.
The search scenario you mentioned is the most common and desirable. That is, more keywords == more refinement (less results). You want each word to be found at least once accross the fields you're searching. In TSQL, that search would look something like this:
WHERE (field1 CONTAINS keyword1 OR field2 CONTAINS keyword1 OR field3 CONTAINS keyword1) AND (field1 CONTAINS keyword2 OR field2 CONTAINS keyword2 OR field3 CONTAINS keyword2) AND (field1 CONTAINS keyword3 OR field2 CONTAINS keyword3 OR field3 CONTAINS keyword3)
From what I've learnt from Examine and Lucene so far, the equivalent syntax ends up looking similar to this:
I achieved this by manually splitting the keywords (by space), and appending each one using .And().GroupedOr(). You can see what I mean here (last post). I created my own IExamineValue implementation which both escapes the term and appends a multiple character wildcard at the end (the helper methods only allow one or the other).
Not sure whether that's the best method (Slace will be able to tell us), but it's working great for me. In fact, Examine makes me look good all the time, so I love it!
Examine query syntax - Unescaped fields
I'm new to examine. The help on codeplex implies adding a field's search term without escaping it will cause the term to be searched as a multi query, i.e. a search term of Umbraco Rocks will return results matching either Umbraco or Rocks. I'm not finding this to be the case, but my specific customer requires an or search on each word in the search term. Here's my code:
Examine.SearchCriteria.ISearchCriteria criteria = ExamineManager.Instance.SearchProviderCollection[SearchProviderName].CreateSearchCriteria();
string[] searchFields = SearchFieldList.Split(',');
int fieldCount = searchFields.GetLength(0);
string[] searchParams = new string[fieldCount];
for (int i = 0; i < fieldCount; i++)
{
searchParams[i] = searchTerm;
}
criteria.GroupedOr(searchFields, searchParams).Not().Field("hideFromSearchResults", "1");
if (!string.IsNullOrEmpty(OrderByFieldList))
{
string[] orderByFields = OrderByFieldList.Split(',');
if (OrderByDescending)
criteria.OrderByDescending(orderByFields);
else
criteria.OrderBy(orderByFields);
}
// get the search result set
IEnumerable<SearchResult> results = ExamineManager.Instance.SearchProviderCollection[SearchProviderName].Search(criteria).AsEnumerable();
...
As you can see, I'm not escaping the search term. Do I need to break up the search term explicitly?
I'm using Lucene.Net.Analysis.Standard.StandardAnalyzer for index and search. I'm also using Umbraco 4.52
Any help would be much appreciated.
Thanks,
Mark
Doing a search like .Field("someField", "Umbraco Rocks") will create a Lucene query which is someField:Umbraco Rocks, and since the word "rocks" isn't associated with a field it'll fall back to the default field for the search, which Examine doesn't set (it has no idea what field should be the default one).
If you're trying to search on "Umbraco Rocks" as a phrase then you need to escape it. If you want to match documents which contain either Umbraco or Rocks then there is the GroupedOr operator and if you want to match documents which only contain Umbraco and Rocks then you need to use the GroupedAnd.
Examine doesn't support the Lucene PhraseQuery, you would have to write something custom if you wanted to do that (see my comments herehttp://our.umbraco.org/forum/developers/extending-umbraco/13786-Examine-Multiple-search-terms-vs-Phrases about PhraseQuery)
Hi Mark. Slace is right (of course :), but I thought I'd add my 2c anyway.
The search scenario you mentioned is the most common and desirable. That is, more keywords == more refinement (less results). You want each word to be found at least once accross the fields you're searching. In TSQL, that search would look something like this:
From what I've learnt from Examine and Lucene so far, the equivalent syntax ends up looking similar to this:
I achieved this by manually splitting the keywords (by space), and appending each one using .And().GroupedOr(). You can see what I mean here (last post). I created my own IExamineValue implementation which both escapes the term and appends a multiple character wildcard at the end (the helper methods only allow one or the other).
Not sure whether that's the best method (Slace will be able to tell us), but it's working great for me. In fact, Examine makes me look good all the time, so I love it!
Nope, that's basically what you need to go about doing :)
is working on a reply...
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.