Reputation: 183
I'm currently working on a program that sends queries against a Solr service and I'm hanging on a problem with how Solr matches strings.
For example when I'm sending MaterialType:buc, it matches all entries with MaterialType = "buc" and with "ebuc" aswell. Is there anything I can do to tell Solr that I want an exact match only (or that it should match only strings that start with "buc")?
Is this even possible without changing the configuration of the solr service?
Regards Tobias
Upvotes: 0
Views: 676
Reputation: 52822
How the match is performed depends on how your field is defined. You're probably querying against a TextField with an analysis chain attached that decomposes the terms buc
and ebuc
down to the same term (such as by using a EdgeNGramFilter
or a stemming filter, etc.).
You can either use a StrField
directly (which will only give you exact matches, case sensitivity and all), or you use a TextField with a KeywordTokenizer (which leaves the whole term intact) and only apply a LowercaseFilter to make the match case insensitive.
If you want to prefix match, you can append a "*" after your query for a StrField, or you can use one of the ngramfilters and only apply the ngram from the beginning of the token.
All these changes would need to be applied to your schema (schema.xml) and your content would normally have to be reindexed after the schema has changed.
Upvotes: 1