1

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

我的名字=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转义搜索字符串

谢谢

4

1 回答 1

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

于 2013-12-22T20:49:31.727 回答