zoukankan      html  css  js  c++  java
  • solr特点七:Plugins(扩展点)

    http://wiki.apache.org/solr/SolrPlugins

    在 Solr 1.3 中,扩展 Solr 以及配置和重新整理扩展变得十分简单。以前,您需要编写一个 SolrRequestHandler来实现新功能。这个方法的问题是其他 SolrRequestHandler很难重用该功能。例如,您可能有更好的分类方法,但却想保留现有的查询与突出显示功能。为了解决这个问题,Solr 项目提出了将各种 SolrRequestHandler(比如 StandardRequestHandler和 DismaxRequestHandler)重构为组件 —称为SearchComponent—的想法,这些组件可以链接起来,形成一个新的 SolrRequestHandler。现在,您只要关注 SearchComponent的新功能就可以了,不用再费神思考怎样才能最好地扩展、重用或复制其他功能。

    不过请放心,现有的 SolrRequestHandler仍然可以像以前一样无缝地工作,但它们现在仅仅是负责实际工作的围绕 SearchComponent的包装器而已。表 1 介绍了一些新 SearchComponent的详细信息。稍后,我还将在本文中提供有关表 1 中的两个组件的更多信息(MoreLikeThisComponent和 SpellCheckComponent。参见 参考资料中的 SearchComponent链接)。

    表 1. 常用的 SearchComponent
    名称说明和查询样例
    QueryComponent 负责将查询提交到 Lucene 并返回 Document的列表。 

    http://localhost:8983/solr/select?&q=iPod&start=0&rows=10
    FacetComponent 决定结果集的分类。

    http://localhost:8983/solr/select?&q=iPod&start=0&rows=10&facet=true&facet.field=inStock
    MoreLikeThisComponent 为每个搜索结果查找与结果类似的文档,并返回这些结果。

    http://localhost:8983/solr/select?&q=iPod&start=0&rows=10&mlt=true&mlt.fl=features&mlt.count=1
    HighlightComponent 在搜索结果的正文中突出显示查询词语的位置。 

    http://localhost:8983/solr/select?&q=iPod&start=0&rows=10&hl=true&hl.fl=name
    DebugComponent 返回有关查询的解析方式的信息,以及每个文档的记录方式的详细信息。 

    http://localhost:8983/solr/select?&q=iPod&start=0&rows=10&debugQuery=true
    SpellCheckComponent 根据索引的内容对输入查询进行拼写检查,并提供其他备选方法。

    http://localhost:8983/solr/spellCheckCompRH?&q=iPood&start=0&rows=10&spellcheck=true&spellcheck.build=true

    默认情况下,所有 SolrRequestHandler都附带有 QueryComponentFacetComponentMoreLikeThisComponentHighlightComponentDebugComponent。要添加自己的组件,您需要:

    1. 扩展 SearchComponent类。
    2. 使 Solr 可以使用这些代码(参见 参考资料中链接到 Solr Plugins wiki 页面的链接)。
    3. 在 solrconfig.xml 中配置它。

    例如,假定我创建了一个名为 com.grantingersoll.MyGreatComponent的 SearchComponent,并让 Solr 可以使用它,而现在我想要将其插入到 SolrRequestHandler中以查询它。那么我首先需要声明该组件,如清单 2 所示,这样 Solr 才能知道如何实例化这个类:

    清单 2. 组件声明
      <searchComponent name="myGreatComp" class="com.grantingersoll.MyGreatComponent"/>

    接下来,我需要告知 Solr 要将其连接到哪个 SolrRequestHandler。在这个用例中,我可以使用三个选择之一:

    • 显式地声明所有 SearchComponent,如清单 3 所示:
      清单 3. 显式地声明所有 SearchComponent
       <requestHandler name="/greatHandler" class="solr.SearchHandler"> 
          <arr name="components"> 
            <str>query</str> 
            <str>facet</str> 
            <str>myGreatComp</str> 
            <str>highlight</str> 
            <str>debug</str> 
          </arr> 
       </requestHandler>
    • 预先将组件添加到现有的链接上,如清单 4 所示:
      清单 4. 预先将组件添加到现有的链接上
       <requestHandler name="/greatHandler" class="solr.SearchHandler"> 
          <arr name="first-components"> 
            <str>myGreatComp</str> 
          </arr> 
       </requestHandler>
    • 将组件追加到现有链接上,如清单 5 所示:
      清单 5. 将组件追加到现有链接上
       <requestHandler name="/greatHandler" class="solr.SearchHandler"> 
          <arr name="last-components"> 
            <str>myGreatComp</str> 
          </arr> 
       </requestHandler>

    关于 DebugComponent的说明

    当您使用 first-components或 last-components方法时,DebugComponent必须是链接的最后组件。当组件改变 DebugComponent报告的值时(比如查询结果),这尤为有用。

    现在,与 SearchComponent重构类似,也可以将查询解析和 SolrRequestHandler分开。因此,您可以把 DismaxQParser与任何 SolrRequestHandler一起使用。您可以通过输入defType参数来实现。例如:

    http://localhost:8983/solr/select?&q=iPod&start=0&rows=10&defType=dismax&qf=name

    使用 Dismax 查询解析器来解析查询,而不是标准 Lucene 查询解析器。

    另外,您也可以通过扩展 QParser和 QParserPlugin来创建您自己的查询解析器,并让 Solr 可以使用它们,然后在 solrconfig.xml 中配置它。例如,如果我创建了 com.grantingersoll.MyGreatQParser和 com.grantingersoll.MyGreatQParserPlugin,并使让 Solr 可以使用它们,那么我应该在 solrconfig.xml 中按以下方式配置它们:

    <queryParser name="greatParser" class="com.grantingersoll.MyGreatQParserPlugin"/>

    随后,我可以将 defType=greatParser键 / 值对添加到一个查询请求中,以查询这个新的解析器。

    Solr 最近版本还包含了很多其他的改进。如果您有兴趣学习更多内容的话,可以看一下 参考资料中的发布说明链接。从这里开始我们将学习 Solr 的新特性。

     
  • 相关阅读:
    httprunner 3.x--参数化parameters(参数和值多对一,多对多,一对一等),csv文件
    httprunner 3.x--variables变量和声明(变量和值一一对应)
    httprunner 3.x 带参数接口测试(get方法)
    appium安装(windows7)
    httprunner 3运行报错AttributeError: module 'allure' has no attribute 'severity_level'
    jmespath用法
    httprunner3.x 测试用例应用/变量传递(测试用例编写)
    Python框架之Tornado(一)
    Python之Web框架
    Python 装饰器(进阶篇)
  • 原文地址:https://www.cnblogs.com/lvfeilong/p/1232dsfdsf.html
Copyright © 2011-2022 走看看