Solr SpellCheckComponent仅显示具有特定值的结果

时间:2013-09-17 22:45:55

标签: java solr lucene

我正在努力让Solr SpellCheckComponent正常工作但遇到了一些问题。当我运行... / solr / collection1 / select?q = %3A & wt = json& indent = true

返回这些结果

{
  "responseHeader": {
    "status": 0,
    "QTime": 1,
    "params": {
      "indent": "true",
      "q": "*:*",
      "_": "1379457032534",
      "wt": "json"
    }
  },
  "response": {
    "numFound": 2,
    "start": 0,
    "docs": [
      {
        "enterprise_name": "because",
        "name": "doc1",
        "enterprise_id": "100",
        "_version_": 1446463888248799200
      },
      {
        "enterprise_name": "what",
        "name": "RZTEST",
        "enterprise_id": "102",
        "_version_": 1446464432735518700
      }
    ]
  }
}

这些是我索引的值。现在,当我想查询拼写时,我得到了一些奇怪的结果。

我跑的时候 / solr的/ collection1 /选择Q =名称%3Arxtest&安培;重量= JSON&安培;缩进=真安培;拼写检查=真

结果准确无误

{
      "responseHeader":{
        "status":0,
        "QTime":4,
        "params":{
          "spellcheck":"true",
          "indent":"true",
          "q":"name:rxtest",
          "wt":"json"}},
      "response":{"numFound":0,"start":0,"docs":[]
      },
      "spellcheck":{
        "suggestions":[
          "rxtest",{
            "numFound":1,
            "startOffset":5,
            "endOffset":11,
            "suggestion":["rztest"]}]}}

无论何时我运行没有名称值的查询,我都会得到0结果。 / solr的/ collection1 /选择Q = enterprise_name%3Abecaus&安培;重量= JSON&安培;缩进=真安培;拼写检查=真

{
  "responseHeader":{
    "status":0,
    "QTime":5,
    "params":{
      "spellcheck":"true",
      "indent":"true",
      "q":"enterprise_name:becaus",
      "wt":"json"}},
  "response":{"numFound":0,"start":0,"docs":[]
  },
  "spellcheck":{
    "suggestions":[]}} 

我的猜测是我的方案有问题,但一切都很好。

Schema.xml的

<field name="name" type="text_general" indexed="true" stored="true"/>
<field name="enterprise_id" type="string" indexed="true" stored="true" required="true" /> 
<field name="enterprise_name" type="text_general" indexed="true" stored="true"/>

<field name="text" type="text_general" indexed="true" stored="false" multiValued="true" />

   <dynamicField name="*_t"  type="text_general"    indexed="true"  stored="true"/>
   <dynamicField name="*_txt" type="text_general"   indexed="true"  stored="true" multiValued="true"/>
   <dynamicField name="attr_*" type="text_general" indexed="true" stored="true" multiValued="true"/>

 <copyField source="name" dest="text"/>
 <copyField source="enterprise_name" dest="text"/> 


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

solrconfig.xml中

<requestHandler name="/select" class="solr.SearchHandler">
    <!-- default values for query parameters can be specified, these
         will be overridden by parameters in the request
      -->
     <lst name="defaults">
       <str name="echoParams">explicit</str>
       <int name="rows">10</int>
       <str name="df">text</str> 
       <!-- Optional, must match spell checker's name as defined above, defaults to "default" -->
       <str name="spellcheck.dictionary">default</str> 
      <!-- Also generate Word Break Suggestions (Solr 4.0 see SOLR-2993) -->
      <str name="spellcheck.dictionary">wordbreak</str>
      <!-- omp = Only More Popular -->
      <str name="spellcheck.onlyMorePopular">false</str>
      <!-- exr = Extended Results -->
      <str name="spellcheck.extendedResults">false</str>
      <!--  The number of suggestions to return -->
      <str name="spellcheck.count">5</str>
    </lst>

     <arr name="last-components">
    <str>spellcheck</str>
  </arr>
<requestHandler>

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">

  <lst name="spellchecker">
    <!--
        Optional, it is required when more than one spellchecker is configured.
        Select non-default name with spellcheck.dictionary in request handler.
    -->
    <str name="name">default</str>
    <!-- The classname is optional, defaults to IndexBasedSpellChecker -->
    <str name="classname">solr.IndexBasedSpellChecker</str>
    <!--
        Load tokens from the following field for spell checking,
        analyzer for the field's type as defined in schema.xml are used
    -->
    <str name="field">name</str>
    <!-- Optional, by default use in-memory index (RAMDirectory) -->
    <str name="spellcheckIndexDir">./spellchecker</str>
    <!-- Set the accuracy (float) to be used for the suggestions. Default is 0.5 -->
    <str name="accuracy">0.5</str>
    <!-- Require terms to occur in 1/100th of 1% of documents in order to be included in the dictionary -->
    <float name="thresholdTokenFrequency">.0001</float>
    <str name="buildOnCommit">true</str>
  </lst>
  <!-- a spellchecker that can break or combine words. (Solr 4.0 see SOLR-2993) -->
  <lst name="spellchecker">
    <str name="name">wordbreak</str>
    <str name="classname">solr.WordBreakSolrSpellChecker</str>
    <str name="field">name</str>
    <str name="combineWords">true</str>
    <str name="breakWords">true</str>
    <int name="maxChanges">3</int>
    <str name="buildOnCommit">true</str>
  </lst>

  <!-- This field type's analyzer is used by the QueryConverter to tokenize the value for "q" parameter -->
  <str name="queryAnalyzerFieldType">text_general</str>
</searchComponent>

任何帮助将不胜感激,谢谢

1 个答案:

答案 0 :(得分:0)

我明白了!

因此,只有名称正常工作的原因是因为name是solrconfig中配置的唯一字段。一旦我这样做,然后我按照这个链接来解决剩下的问题。

SOLR suggester multiple field autocomplete