Reputation: 3978
I have a text field that can contain very long values (like text files). I want to create field type for it (text, not string), in order to have something like "Match whole word only" in notepad++, but the delimiter should not be only white spaces. If i have:
myName=aaa bbb
I would like to get it for the following search strings "aaa", "bbb", "aaa bbb", "myName=aaa bbb", "myName", but not for "aa" or "ame=a" or "a bb". Another example is:
<myName>aaa bbb</myName>
Can i do this somehow?
What should be my field type definition?
[EDIT] the text can contain any character. Before search i'm escaping the search string using http://lucene.apache.org/solr/4_2_1/solr-solrj/org/apache/solr/client/solrj/util/ClientUtils.html
Thanks
Upvotes: 1
Views: 1958
Reputation: 1787
Start with, (why do you need to escape special chars? , you need let them get tokenized on them both at index and query time) :
<!-- 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. -->
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<!-- in this example, we will only use synonyms at query time
<filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
-->
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
This is a good place to learn how your text gets processed both at index and query time. Very useful admin tool : http://localhost:8983/solr/#/collection1/analysis
Upvotes: 1