when searching a field that contains the text "touchpad mouse brilliant", in luke, the order in which i have these words in the query doesn't matter - it always returns matches.
in umbraco, unless i match the word order exactly, i.e. "touchpad mouse brilliant", nothing will be returned. to give you an example of what would fail: "brilliant mouse touchpad".
Is there any way i can get examine behaving more like luke?
current code:
var criteria = ExamineManager.Instance .SearchProviderCollection["TestSearcher"] .CreateSearchCriteria(UmbracoExamine.IndexTypes.Content);
//create basic filter to start with var filter = criteria .Field("tags", "brilliant mouse touchpad") ;
//execute query using custom distinct constraint IEnumerable<SearchResult> Results = new List<SearchResult>(); Results = ExamineManager.Instance.SearchProviderCollection["TestSearcher"].Search(filter.Compile()).Distinct(new SearchResultComparer());
what i don't want to do is have to split the text into words loop through them dynamically adding OR() operators to end up with something equivalent to this:
Are you wanting to search for all documents that have those three keywords anywhere, or do you want to search on documents which have those three keywords together? It's different depending on what you're trying to achieve.
If you're wanting the words together you're not escaping your search, so you end up with a Lucene query like this:
+tags:touchpad mouse brilliant
When what you want is:
+tags:"touchpad mouse brilliant"
This can be achieved by using the Escape extension method (which resides in UmbracoExamine.SearchCriteria).
If you're wanting the documents which contain one-or-more of the words you need to do a GroupedOr statement:
Luke can operate differently when searching as it is capable of doing a 'default field' for the search. Examine does not have this feature and this is why 'tag:... ... ...' may be different in Luke to Examine. Also, if you're using a different analyzer in Luke (Whitespace is it's default IIRC) to Examine (it's default is StandardAnalyzer) you can receive different results.
I guess the problem in my case is that the search query is automatically being escaped without me explicitly using the extension method. to achieve the "contains" result i'm after, i will need to resort to dynamically OR'ing words from the query against the fields.
examine vs luke
when searching a field that contains the text "touchpad mouse brilliant", in luke, the order in which i have these words in the query doesn't matter - it always returns matches.
in umbraco, unless i match the word order exactly, i.e. "touchpad mouse brilliant", nothing will be returned. to give you an example of what would fail: "brilliant mouse touchpad".
Is there any way i can get examine behaving more like luke?
current code:
var criteria = ExamineManager.Instance
.SearchProviderCollection["TestSearcher"]
.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content);
//create basic filter to start with
var filter = criteria
.Field("tags", "brilliant mouse touchpad")
;
//execute query using custom distinct constraint
IEnumerable<SearchResult> Results = new List<SearchResult>();
Results =
ExamineManager.Instance.SearchProviderCollection["TestSearcher"].Search(filter.Compile()).Distinct(new SearchResultComparer());
-----------
any insights?
Cheers,
Si
what i don't want to do is have to split the text into words loop through them dynamically adding OR() operators to end up with something equivalent to this:
var filter = criteria
.Field("tags", "touchpad")
.Or()
.Field("tags", "mouse")
.Or()
.Field("tags", "brilliant")
;
that would work but is this necessary, or am i missing a particular setting?
ps: setting default operation of OR in the CreateSearchCriteria factory method won't work in this instance
Are you wanting to search for all documents that have those three keywords anywhere, or do you want to search on documents which have those three keywords together? It's different depending on what you're trying to achieve.
If you're wanting the words together you're not escaping your search, so you end up with a Lucene query like this:
When what you want is:
This can be achieved by using the Escape extension method (which resides in UmbracoExamine.SearchCriteria).
If you're wanting the documents which contain one-or-more of the words you need to do a GroupedOr statement:
Luke can operate differently when searching as it is capable of doing a 'default field' for the search. Examine does not have this feature and this is why 'tag:... ... ...' may be different in Luke to Examine.
Also, if you're using a different analyzer in Luke (Whitespace is it's default IIRC) to Examine (it's default is StandardAnalyzer) you can receive different results.
thanks for that slace.
I guess the problem in my case is that the search query is automatically being escaped without me explicitly using the extension method. to achieve the "contains" result i'm after, i will need to resort to dynamically OR'ing words from the query against the fields.
cheers
si
The example code you posted wont escape, it'll generate this:
The easiest way to do n-level grouped or statements is like this:
(That's notepad code so it might not be 100% :P)
i don't know what the reason was slace, but it wasn't returning results unless i OR'd every word together ;'/
now i'm using your neater grouped OR linq goodness which still gives the results i was expecting :]
thanks again
If you ever need to find out the lucene query you can just ToString the search criteria object and it's in there :P
is working on a reply...