• 如何大幅优化solr的查询性能(转)


    提升软件性能,通常喜欢去调整各种启动参数,这没有多大意义,小伎俩。 性能优化要从架构和策略入手,才有可能得到较大的收益

    Solr的查询是基于Field的,以Field为基本单元,例如一个文章站要索引

    1. classArticle
    2. {
    3.    String title;
    4.    String content;
    5.    String tags;
    6. }

    查询参数: q=title:big && content:six

    Solr会顺序执行两次 field查询 ,这个开销非常大。 实际例子 :50万条记录,一次在6,7个字段上检索,24 core的服务器也需要10-20ms

    如果把title和content 合并,那只需要查询一次,性能可以提升50%

    在生成索引xml的时候,把title和content填入同一个字段,就能达到这种效果,但是产生新的问问题

    无法对title和content的查询分别指定权重了,一般来说,title的权重要高于content

    Solr给出一种解决方法:在schema中使用 copyField

    上述的Article Schema可以写成如下这种格式,就能达到效果

    1. <fieldname="title"type="text_general"indexed="true"stored="true"/>
    2. <fieldname="content"type="text_general"indexed="true"stored="true"/>
    3. <fieldname="tags"type="text_general"indexed="true"stored="true"/>
    4. <fieldname="text"type="text_general"indexed="true"stored="false"multiValued="true"/>
    5. <copyFieldsource="title"dest="text"/>
    6. <copyFieldsource="content"dest="text"/>
    7. <copyFieldsource="tags"dest="text"/>

    这种schema定义方式,既可以对单个field指定查询权重,也可以在泛查询的时候提升性能,同时生成索引数据的时候不需要多写任何代码

  • 相关阅读:
    docker 日常使用笔记
    docker swarm:启动多个 overlay网络出现 could not find an available IP while allocating VIP问题
    docker 容器启动失败:Could not attach to network
    fabric : orderer启动失败
    git 代码迁移
    Docker 远程访问
    Struts2标签
    BS与CS的联系与区别
    Java的引用和C++的指针de区别
    抽象类和接口的区别
  • 原文地址:https://www.cnblogs.com/rainbowzc/p/3761487.html
Copyright © 2020-2023  润新知