Reputation: 1456
I am working on Solr 4+.
I have several fields into my solr schema with different solr field types.
Does the search on text field and string field differs?
Because I am trying to search on string field (which is a copy field of few facet fields) which does not work as expected. The destination string field is indexed and stored both.
However, when I change destination field which a text field (only indexed), it works fine.
Can you suggest why this happens? What is exactly the difference between text and string fields in solr in respect to searches?
Upvotes: 20
Views: 15201
Reputation: 494
The fields that the Solr model defines by default are very different.
Without using tokenization
or other processes, a string saves a word or sentence as precisely as it is. frequently helpful for facetting, for example, storing exact matches.
Tokenization and secondary processing (such as lower-casing, etc.) are usually handled by text. useful in any situation where we need to match a sentence's partial.
If both fields have the example "This is a sample sentence"
indexed, we need to look for that precise content. For a hit in the text field, searching for sample
or even samples with stemming enabled may be sufficient. "This is a sample sentence"
to get a hit in the string field.
Upvotes: 0
Reputation: 1
A general text field that has reasonable, generic cross-language defaults: it tokenizes with StandardTokenizer, removes stop words from case-insensitive "stopwords.txt" (empty by default), and down cases. At query time only, it also applies synonyms.
The StrField type is not analyzed, but indexed/stored verbatim.
Upvotes: 0
Reputation: 52912
TextFields
usually have a tokenizer and text analysis attached, meaning that the indexed content is broken into separate tokens where there is no need for an exact match - each word / token can be matched separately to decide if the whole document should be included in the response.
StrFields
cannot have any tokenization or analysis / filters applied, and will only give results for exact matches. If you need a StrField with analysis or filters applied, you can implement this using a TextField
and a KeywordTokenizer
.
Upvotes: 36