• solr联合多个字段进行检索(multivalued和copyfield的使用)


    在实际工作中不仅仅对索引中的单个字段进行搜索。需要进行综合查询。 比如book表中有id,name(标题),price,summary(摘要),content(内容),我们要找一本书的时候,查询关键字“平凡的世界”,需要从标题或者摘要或者内容里包含这个关键字时就算找到了。这就需要使用copyField和multiValue标签了。

    在schema.xml中将需要检索的字段,使用copyField拷贝到一个新的searchText的field中,并设置这个searchText field的multivalue属性为true即可。

        <fields>  
             <field name="id" type="string" indexed="true" stored="true" required="true" />  
             <field name="name" type="textMaxWord_cn" indexed="true" stored="true" />  
             <field name="price" type="long" indexed="true" stored="true" />  
             <field name="summary" type="textMaxWord_cn" indexed="true" stored="true" />  
             <field name="content" type="textMaxWord_cn" indexed="true" stored="true" />  
             <field name="searchText" type="textMaxWord_cn" indexed="true" stored="false" multiValued="true" /> 
             <field name="createTime" type="string" indexed="true" stored="false" /> 
         </fields>  
    
         <uniqueKey>id</uniqueKey>  
         <defaultSearchField>searchText</defaultSearchField>  
         <solrQueryParser defaultOperator="AND" />  
    
         <copyField source="name" dest="searchText" />  
         <copyField source="summary" dest="searchText" />  

     

    且可设置检索的时候,哪个field占的权重多一点。 在solrconfig.xml中可设置如下:

    
    <requestHandler name="dismax" class="solr.SearchHandler">
        <lst name="defaults">
            <str name="defType">edismax</str>
            <str name="echoParams">explicit</str>
            <float name="tie">0.1</float>
            <!--
            <str name="bf">scoreParser(type)</str>
            -->
            <str name="bf">sum(recip(ms(NOW,last_modified),3.16e-11,1,1),div(1000,price))^100</str>
            <str name="pf">
                name^100 summary^50 content^20
            </str>
            <str name="qf">
                name^10 summary^ content^2
            </str>
    
    </requestHandler>

     

    在网上找了这两个参数的定义:

    pf: 可提供对一条记录的多个字段做匹配的功能 qf: 针对查询的每个字段设置不同的boost权重打分,其设置的字段必须为在pf中配置的项。

    事例解释

    http://localhost:8080/solr/select?defType=dismax&qf=name^10 summary ^1 &q=平凡的世界&pf=name^50 summary ^1&q.op=OR&bf=sum(recip(ms(NOW,createTime),3.16e-11,1,1),div(1000,price))^100 该查询表示:在name和summary 中搜索关键字“平凡的世界”,name和summary 在字段查询中的比重分别为10、1(qf=qf=name^10 summary ^1);并且这两个字段phrase的打分为 pf=name^50 summary ^1,也就是name占的比重为50,而summary占的比重小点;且该查询考虑了书本的价格和书的上架时间(bf=sum(recip(ms(NOW,last_createTime),3.16e-11,1,1),div(1000,price))^100)

    bf可以自己实现自己的定义。 关于多字段检索也可看看这篇文章的介绍:http://adminjun.iteye.com/blog/2258480

    在实际项目中可能会存储clob类型的字段,这就需要另外的处理,详细请参照博客http://blog.csdn.net/u010248330/article/details/72957645

  • 相关阅读:
    机器学习中数据缺失的处理及建模方法
    小样本学习(Few-Shot Learning)
    常见文本相似度计算法
    【FPGA ZYNQ Ultrascale+ MPSOC教程】33.BRAM实现PS与PL交互
    【紫光同创国产FPGA教程】【第十章】DDR3读写测试实验
    【紫光同创国产FPGA教程】【第九章】HDMI编程测试实验
    【紫光同创国产FPGA教程】【第八章】SD卡读写实验
    【紫光同创国产FPGA教程】【第七章】I2C接口EEPROM实验
    【紫光同创国产FPGA教程】【第六章】PDS下按键消抖实验
    【紫光同创国产FPGA教程】【第五章】串口收发实验
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/9407594.html
Copyright © 2020-2023  润新知