I am indexing documents with their urlNames so that I can return a document by its slug e.g. "premiere-stay-fresh-j1-nokia".
Luke returns the document when I search by that field, but Examine is not playing ball. Returns nothing (errs) with that code:
var criteria = searcher.CreateSearchCriteria();
var filter = criteria.Field("urlName", "premiere-stay-fresh-j1-nokia").Compile();
var result = searcher.Search(filter).First();
So, it turns out Luke is using a different analyzer to search. All seems a bit dark arts, why the "Standard" anlyzer would search that different to the "KeywordAnalyzer" used by default by Luke.
Anyway, work around was to create a Search for the latter and use that:
<add name="PostSlugSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
analyzer="Lucene.Net.Analysis.KeywordAnalyzer, Lucene.Net"
indexSet="PostsIndexSet"/>
var slugSearcher = ExamineManager.Instance.SearchProviderCollection["PostSlugSearcher"];
var criteria = slugSearcher.CreateSearchCriteria();
var filter = criteria.Field("urlName", "premiere-stay-fresh-j1-nokia").Compile();
var result = slugSearcher.Search(filter).First();
I just re-used the standard ExternalIndexSet and it seemed to work fine. I tested searching on other custom fields and also using the urlName and all ok.
Here is an example of my search code...
var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["SlugSearcher"];
var criteria = searcher.CreateSearchCriteria();
criteria.NodeTypeAlias("blogArticle");
criteria.Field("urlName", search.UrlName).Or();
var searchResults = searcher.Search(criteria);
I know the thread is a bit old but the reason still matters for future visitors.
The reason the StandardAnalyzer wont come up with a match is that it uses Tokenization, which means spaces, dashes, etc. will split the word into terms.
The KeywordAnalyzer on the other hand does not use Tokenization. This is good for situations where you are looking for exact matches including matching case.
It can be read from the Lucene documentation:
This should be a good tokenizer for most European-language documents:
Splits words at punctuation characters, removing punctuation. However, a dot that's not followed by whitespace is considered part of a token.
Splits words at hyphens, unless there's a number in the token, in which case the whole token is interpreted as a product number and is not split.
Recognizes email addresses and internet hostnames as one token.
Examine can't search urlName, but Luke can
I am indexing documents with their urlNames so that I can return a document by its slug e.g. "premiere-stay-fresh-j1-nokia".
Luke returns the document when I search by that field, but Examine is not playing ball. Returns nothing (errs) with that code:
No idea what to do with that since Luke is happy.
So, it turns out Luke is using a different analyzer to search. All seems a bit dark arts, why the "Standard" anlyzer would search that different to the "KeywordAnalyzer" used by default by Luke.
Anyway, work around was to create a Search for the latter and use that:
Hi,
For anyone interested I was having the exact same problem. I was trying to search by urlName which just wasn't working.
I managed to get this to work by following Alastair's solution.
Basically I added to the ExamineSettings.config file
So it should look something like this.
I just re-used the standard ExternalIndexSet and it seemed to work fine. I tested searching on other custom fields and also using the urlName and all ok.
Here is an example of my search code...
Hope this helps someone.
Kind Regards
David
I know the thread is a bit old but the reason still matters for future visitors.
The reason the StandardAnalyzer wont come up with a match is that it uses Tokenization, which means spaces, dashes, etc. will split the word into terms.
The KeywordAnalyzer on the other hand does not use Tokenization. This is good for situations where you are looking for exact matches including matching case.
It can be read from the Lucene documentation:
is working on a reply...