12.相关度设置

索引时设置boost

在创建索引时设置boost值:可以针对Field设置boost,也可以针对Document设置boost值。针对Field设置boost必须搜索时匹配到该Field在计算相关度得分时才有效,针对Document设置Field则在搜索时只要匹配到该Document的任意Field在计算相关度得分都有效。
  1. <add>
  2. <doc>
  3. <field name="id">a01</field>
  4. <field name="product_name" boost="20.0">幸福一家人</field>
  5. <field name="product_description" >我们是幸福一家人</field>
  6. </doc>
  7. <doc boost="30.0">
  8. <field name="id">a02</field>
  9. <field name="product_name">幸福两家人</field>
  10. <field name="product_description" >我们是幸福两家人</field>
  11. </doc>
  12. </add>
  13. <commit/>

搜索时设置boost

在创建搜索时设置域的boost值:搜索匹配到的域如果boost值设置的高则计算的相关度得分就可能会高。
  1. <add>
  2. <doc>
  3. <field name="id">a03</field>
  4. <field name="product_name">lucene实战</field>
  5. <field name="product_description" >这是一本讲解全文检索技术的书籍</field>
  6. </doc>
  7. <doc>
  8. <field name="id">a04</field>
  9. <field name="product_name">全文检索</field>
  10. <field name="product_description" >Lucene是一个全文检索工具包</field>
  11. </doc>
  12. </add>
  13. <commit/>
posted @ 2017-03-10 21:38  Wesly186  阅读(165)  评论(0编辑  收藏  举报