Search for an exact phrase in all fields with Examine
Is there an easy way to search for an exact phrase over all indexed fields?
I want to search for the phrase "high speed rail" and only return documents with that exact phrase in them, and I don't want to maintain a list of fields to search in.
I've tried
ExamineManager.Instance.SearchProviderCollection[searchProvider].Search("high speed rail", true); - returns anything with high* or speed* or rail* in it
ExamineManager.Instance.SearchProviderCollection[searchProvider].Search("high speed rail", false); - returns anything with the words high, speed or rail (but not all of them and in that order
ExamineManager.Instance.SearchProviderCollection[searchProvider].Search("\"high speed rail\"", true); - returns a strange set of results: the lucene query ends up looking like description:"high* id:speed* id:rail"* which doesn't look right at all.
ExamineManager.Instance.SearchProviderCollection[searchProvider].Search("\"high speed rail\"", false); - again returns anything with the words in the doc.
Most of the examples I find create a searchCriteria by GroupedOr ing a list of fields, but I don't want to maintain that list - is there any way of avoiding that, and why doesn't the Search() work with a phrase passed in.
I'm not sure how you could use this to search accross all indexed fields without explicitly specifying them however. You might be able to read in a list from your ExamineIndex.config file.
Sorry for replying to an old discussion, but does this still work? I have tried this and similar and even though it all looks right, I never get to the second GroupedOr. It's as if Examine only looks at the first one and even if it finds no results it never bothers to check the second GroupedOr.
Search for an exact phrase in all fields with Examine
Is there an easy way to search for an exact phrase over all indexed fields?
I want to search for the phrase "high speed rail" and only return documents with that exact phrase in them, and I don't want to maintain a list of fields to search in.
I've tried
ExamineManager.Instance.SearchProviderCollection[searchProvider].Search("high speed rail", true); - returns anything with high* or speed* or rail* in it
ExamineManager.Instance.SearchProviderCollection[searchProvider].Search("high speed rail", false); - returns anything with the words high, speed or rail (but not all of them and in that order
ExamineManager.Instance.SearchProviderCollection[searchProvider].Search("\"high speed rail\"", true); - returns a strange set of results: the lucene query ends up looking like description:"high* id:speed* id:rail"* which doesn't look right at all.
ExamineManager.Instance.SearchProviderCollection[searchProvider].Search("\"high speed rail\"", false); - again returns anything with the words in the doc.
Most of the examples I find create a searchCriteria by GroupedOr ing a list of fields, but I don't want to maintain that list - is there any way of avoiding that, and why doesn't the Search() work with a phrase passed in.
As a side note I notice http://umbraco.com/search?q=case%20studies returns nothing but http://umbraco.com/search?q=studies returns a page called Case Studies, so maybe I'm not the only one having problems with multiple words.
Stephen
Hi Stephen,
I decided to use raw Lucene syntax rather than the fluent API. I found that this gave me a lot more control over the query.
For an exact match using raw lucene, it's simply a case of putting the phrase in double quotes:
var Searcher = ExamineManager.Instance.SearchProviderCollection["MySearchProvider"];
var searchCriteria = Searcher.CreateSearchCriteria();
string searchQueryString = "mySearchProperty: \"high speed rail\"";
var query = searchCriteria.RawQuery(searchQueryString);
IEnumerable<SearchResult> searchResults = Searcher.Search(query);
I'm not sure how you could use this to search accross all indexed fields without explicitly specifying them however. You might be able to read in a list from your ExamineIndex.config file.
Robert
I've found an easy solution to be used in the code behind. It may help someone.
Sorry for replying to an old discussion, but does this still work? I have tried this and similar and even though it all looks right, I never get to the second GroupedOr. It's as if Examine only looks at the first one and even if it finds no results it never bothers to check the second GroupedOr.
is working on a reply...