【问题标题】:Solr - How to boost a field in Solr? Not getting the correct querySolr - 如何提升 Solr 中的领域?没有得到正确的查询
【发布时间】:2011-12-05 22:26:46
【问题描述】:

我正在使用 Solr 1.4.1。我需要提升一个领域。我的 schema.xml 如下:

<?xml version="1.0" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<schema name="default" version="1.1">
  <types>
    <fieldtype name="string"  class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" omitNorms="true"/>

    <!-- Numeric field types that manipulate the value into
     a string value that isn't human-readable in its internal form,
     but with a lexicographic ordering the same as the numeric ordering,
     so that range queries work correctly. -->
    <fieldType name="sint" class="solr.SortableIntField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="slong" class="solr.SortableLongField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="sfloat" class="solr.SortableFloatField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="sdouble" class="solr.SortableDoubleField" sortMissingLast="true" omitNorms="true"/>

    <fieldType name="date" class="solr.DateField" sortMissingLast="true" omitNorms="true"/>

    <fieldType name="text" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <!-- 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.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EnglishPorterFilterFactory" protected="protwords.txt"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      </analyzer>
      <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EnglishPorterFilterFactory" protected="protwords.txt"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      </analyzer>
    </fieldType>

    <fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100">
      <analyzer>
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      </analyzer>
    </fieldType>

    <fieldType name="ngram" class="solr.TextField" >
      <analyzer type="index">
    <tokenizer class="solr.KeywordTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.NGramFilterFactory" minGramSize="3" maxGramSize="15" />
      </analyzer>
      <analyzer type="query">
    <tokenizer class="solr.KeywordTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>

    <fieldType name="edge_ngram" class="solr.TextField" positionIncrementGap="1">
      <analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory" />
    <filter class="solr.LowerCaseFilterFactory" />
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
    <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="15" side="front" />
      </analyzer>
      <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory" />
    <filter class="solr.LowerCaseFilterFactory" />
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
      </analyzer>
    </fieldType>
  </types>

  <fields>   
    <!-- general -->
    <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/>
    <field name="django_ct" type="string" indexed="true" stored="true" multiValued="false" />
    <field name="django_id" type="string" indexed="true" stored="true" multiValued="false" />

    <dynamicField name="*_i"  type="sint"    indexed="true"  stored="true"/>
    <dynamicField name="*_s"  type="string"  indexed="true"  stored="true"/>
    <dynamicField name="*_l"  type="slong"   indexed="true"  stored="true"/>
    <dynamicField name="*_t"  type="text"    indexed="true"  stored="true"/>
    <dynamicField name="*_b"  type="boolean" indexed="true"  stored="true"/>
    <dynamicField name="*_f"  type="sfloat"  indexed="true"  stored="true"/>
    <dynamicField name="*_d"  type="sdouble" indexed="true"  stored="true"/>
    <dynamicField name="*_dt" type="date"    indexed="true"  stored="true"/>

    <field name="location_ad" type="text" indexed="true" stored="true" multiValued="false" />
    <field name="text" type="text" indexed="true" stored="true" multiValued="false" />
    <field name="location_ad_exact" type="string" indexed="true" stored="true" multiValued="false" />
    <field name="date_inserted" type="date" indexed="true" stored="true" multiValued="false" />
    <field name="zone_ad_exact" type="string" indexed="true" stored="true" multiValued="false" />
    <field name="country_ad" type="text" indexed="true" stored="true" multiValued="false" />
    <field name="job_description" type="text" indexed="true" stored="true" multiValued="false" />
    <field name="zone_ad" type="text" indexed="true" stored="true" multiValued="false" />
    <field name="job_title" type="text" indexed="true" stored="true" multiValued="false" />
  </fields>

  <!-- field to use to determine and enforce document uniqueness. -->
  <uniqueKey>id</uniqueKey>
  <!-- field for the QueryParser to use when an explicit fieldname is absent -->
  <defaultSearchField>text</defaultSearchField>
  <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
  <solrQueryParser defaultOperator="AND" />
</schema>

我需要做以下事情:我需要更加重视“job_title”字段。例如,如果我正在搜索“programmer”这个词,我需要首先显示“job_title”字段中按日期排序的“programmer”的结果,然后显示“programmer”这个词的结果“job_description”字段。最好做个例子,我的英语不是世界上最好的;)

我有这些数据:

job_title                | job_description                    | date_inserted
programmer               | job for IT guys                    | 10-Nov-2011
IT Python                | for python programmer              | 12-Nov-2011
PHP programmer           | PHP programming                    | 08-Nov-2011

例如,在搜索“programmer”一词时,我需要更加重视“job_title”字段,但同时在结果中显示“job_description”字段中包含“programmer”一词的文档。我还需要重视“date_inserted”字段,以便结果如下所示:

job_title                | job_description                    | date_inserted
programmer               | job for IT guys                    | 10-Nov-2011
PHP programmer           | PHP programming                    | 08-Nov-2011
IT Python                | for python programmer              | 12-Nov-2011

我正在做这样的查询:

/?facet=on&sort=date_inserted+desc&fl=*+score&start=0&q=programmer&bf=job_title:programmer^1.50&facet.field=location_ad_exact&facet.field=zone_ad_exact&fq=django_ct:(myapp.jobsadstext)&rows=20

但是这个查询的结果不是我需要的。

谁能给我一个线索,让我知道我需要遵循什么路径才能达到结果?

最好的问候,

【问题讨论】:

    标签: solr field


    【解决方案1】:
    1. 您必须使用 DisMax 查询解析器‘defType=dismax’) 才能使用提升。
    2. 使用 qf 参数进行字段查询(在您的示例中,您使用的是 bf - boost 函数)

    http://wiki.apache.org/solr/DisMaxQParserPlugin#qf_.28Query_Fields.29

    【讨论】:

    • 感谢 Matej 的回复。我已经完成了这个查询:"/?facet=on&sort=date_inserted+desc&fl=*+score&start=0&q=arquiteto&qf=job_title^1.50+job_description^1&facet.field=location_ad_exact&facet.field=zone_ad_exact&fq=django_ct:(emp1001br.jobsadstext)&rows= 20" 不幸的是结果是一样的。我做错了什么?最好的问候,
    • 您可以使用 &amp;debugQuery=true 查看详细输出 - 在浏览器中使用查看源代码以获得更好的格式。
    • 添加 &amp;defType=dismax 以使用 DisMax 查询解析器。如果你想要字段提升,你必须使用 DisMax。
    • 太棒了!现在我看到了分数。我现在的问题是关于订单。如果我按“分数”排序,我会丢失“排序=日期插入”。查询是这样的: "?facet=on&sort=date_inserted+desc&fl=*+score&start=0&q=arquiteto&qf=job_title^100+job_description^1&defType=dismax&facet.field=location_ad_exact&facet.field=zone_ad_exact&fq=django_ct:(emp1001br.jobsadstext)&rows =20”。如何按“score”和“date_inserted”排序?
    • 你必须添加函数查询来提升日期。有关详细信息,请参阅wiki.apache.org/solr/…。很抱歉从一开始就错过了这个。
    猜你喜欢
    • 2010-10-12
    • 1970-01-01
    • 2014-04-25
    • 2011-11-28
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多