在 Solr 中精确搜索字段

Exact Search in Solr on a field

我想在我的 collection 中精确匹配其中一个字段(域)。 现在,如果我搜索 "DIU",它会给我带来 "DIU" & "DIU/DRRU",我只需要 "DIU"。 当我搜索 "DIU/DRRU" 时,我只需要 "DIU/DRRU"。 我怎样才能做到这一点?我正在使用 Solr 7.4

我的模式设置是 -

"name":"domain",
        "type":"text_general",
        "multiValued":false,
        "indexed":true,
        "stored":true},

{
        "name":"text_general",
        "class":"solr.TextField",
        "positionIncrementGap":"100",
        "multiValued":true,
        "indexAnalyzer":{
          "tokenizer":{
            "class":"solr.StandardTokenizerFactory"},
          "filters":[{
              "class":"solr.StopFilterFactory",
              "words":"stopwords.txt",
              "ignoreCase":"true"},
            {
              "class":"solr.LowerCaseFilterFactory"}]},
        "queryAnalyzer":{
          "tokenizer":{
            "class":"solr.StandardTokenizerFactory"},
          "filters":[{
              "class":"solr.StopFilterFactory",
              "words":"stopwords.txt",
              "ignoreCase":"true"},
            {
              "class":"solr.SynonymGraphFilterFactory",
              "expand":"true",
              "ignoreCase":"true",
              "synonyms":"synonyms.txt"},
            {
              "class":"solr.LowerCaseFilterFactory"}]}},

使用字符串字段而不是基于 text_general 的字段 - text_general 字段(附加了 StandardTokenizer)将在 / 上拆分。 string 字段只有在字段与存储的值完全匹配时才会给出匹配项。

目前字段 domain 的字段类型为 text_general。 如果您要查找完全匹配项,请在您的字段中使用 keywordTokenizer。因为它不会创建文本标记。

keywordTokenizer 是:This tokenizer treats the entire text field as a single token.

您可以为您的字段使用以下字段类型。优点是它有助于在所有情况下搜索单词...大写和小写。

<fieldType name="lowercaseExactMatch" class="solr.TextField" positionIncrementGap="100">
   <analyzer>
     <tokenizer class="solr.KeywordTokenizerFactory"/>
     <filter class="solr.LowerCaseFilterFactory" />
   </analyzer>
</fieldType>