0

我正在尝试让 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/select?q=name%3Arxtest&wt=json&indent=true&spellcheck=true

结果是准确的,我得到了

{
      "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/select?q=enterprise_name%3Abecaus&wt=json&indent=true&spellcheck=true

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

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

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

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

4

1 回答 1

0

我想到了!

所以只有名称起作用的原因是因为名称是 solrconfig 中配置的唯一字段。一旦我这样做了,我就按照这个链接来解决剩下的问题。

SOLR 建议器多字段自动完成

于 2013-09-18T05:04:54.807 回答