2013-12-22 31 views
0

我有一个可以包含非常长的值的文本字段(如文本文件)。 我想为它创建字段类型(文本,而不是字符串),以便在记事本++中有类似于“仅匹配整个字”的内容,但分隔符不应仅为空格。 如果我有:Solr - 仅在文本字段中匹配整个字

MYNAME = AAA BBB

我想获得它下面的搜索字符串 “AAA”, “BBB”, “AAA BBB”, “MYNAME = AAA BBB”,“MYNAME “,但不适用于”aa“或”ame = a“或”a bb“。 另一个例子是:

<myName>aaa bbb</myName> 

我可以这样做吗?

什么应该是我的字段类型定义?

[编辑]文本可以包含任何字符。搜索之前,我正在使用转义http://lucene.apache.org/solr/4_2_1/solr-solrj/org/apache/solr/client/solrj/util/ClientUtils.html

感谢

回答

0

开始与搜索字符串,(为什么你需要转义特殊字符,你需要让他们在索引和查询时间记号化在他们两个?):

<!-- 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> 

这是学习如何在索引和查询时处理文本的好地方。非常有用的管理工具:http://localhost:8983/solr/#/collection1/analysis

+0

thx。但是,这只能在像“name = aaa”这样的文档中找到aaa,但不能在没有像“name = aaa”之类的空间的文档中找到。我需要在两者中找到aaa。 – axelrod

+0

为您认为它不起作用的示例发布完整的solr查询。 – Arun

相关问题