solr4 schema.xml field 添加boost值
以前在用elasticsearch时,boost值可以在配置mapping时指定.例如:
.startObject("title") .field("type", "string") .field("store", "yes") .field("term_vector","with_positions_offsets") .field("indexAnalyzer", "ik") .field("searchAnalyzer", "ik") .field("include_in_all", "false") .field("boost", 4.0) // 打分(默认1.0) .endObject() |
今天在用solr时,想在schema.xml中指定title的boost值。
这样做的好处就是查询时候开销比较小。缺点同样很明显,写死了,不灵活。但是可以用solr dismax去实现。
查了一些资料:
1.在schem.xml 配置boost=”2.0f”是不行的。
<field name="title" type="ik_text" indexed="true" stored="true" multiValued="false" termVectors="true" termPositions="true" termOffsets="true" default="" omitNorms="true" boost="2.0"/> |
SolrInputDocument document=new SolrInputDocument(); document.setField("title", "qq", 4.0f); |
3.可以在xml形式添加数据时设置boost,例如:
<add> <doc boost="2.5"> <field name="employeeId">05991</field> <field name="content" boost="2.0">test qq</field> </doc> </add> |
4.在http://lucene.472066.n3.nabble.com/BOSTing-FIELDS-in-SCHEMA-XML-td495792.html的问题解答上有如下回答:
问:
Hi, is there a chance to set boosting directly in my schema.xml ? <field name="Name1" type="text" indexed="true" stored="true" multivalued="true" omitNorms="false" boost="2" /> <field name="Name2" type="text" indexed="true" stored="true" multivalued="true" omitNorms="false" boost="1.5f" /> <field name="Name3" type="text" indexed="true" stored="true" multivalued="true" omitNorms="false" boost="0.5f" /> <field name="Name4" type="text" indexed="true" stored="true" /> I want do it directly in the index and not in my query ! |
回答:
Right now you'll have to set the boosts from your indexing client, or
dismax dynamically from the querying side of things, or Lucene query
parser^boosting. |
参考文章:
http://lucene.472066.n3.nabble.com/BOSTing-FIELDS-in-SCHEMA-XML-td495792.html
http://wiki.apache.org/solr/ExtendedDisMax
http://wiki.apache.org/solr/DisMax
http://wiki.apache.org/solr/UpdateXmlMessages#Optional_attributes_for_.22field.22
http://wiki.apache.org/solr/SolrRelevancyFAQ#Field_Based_Boosting
本文固定链接: http://www.chepoo.com/solr4-schema-xml-field-add-boost-value.html | IT技术精华网