代码之家  ›  专栏  ›  技术社区  ›  Alex Klunniy

实现solr post filter-如何从customer post filter读取配置

  •  0
  • Alex Klunniy  · 技术社区  · 6 年前

    我正在按照以下文章实现自定义solr postfilter逻辑: http://qaware.blogspot.com/2014/11/how-to-write-postfilter-for-solr-49.html https://lucidworks.com/2015/05/15/custom-security-filtering-solr-5/

    在我的自定义solr postfilter中,我正在对sql server进行数据库调用,我需要基于环境的不同连接字符串-dev/prepod/prod。

    如何从solr中的某个配置读取连接字符串? 是否可以以某种方式扩展配置,以便可以在自定义QueryParser中读取连接字符串?

    例如,在里面下面的某个地方 SOLR.CONFIG 在哪里定义自定义解析器?

    <queryParser name="CustomSolrPostFilter" class="CustomSolrPostFilter" />
    

    或从 核心属性 以某种方式归档?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Alex Klunniy    6 年前

    由于通常是在发帖提问后才发现答案的。

    需要在解析器声明中扩展:

    <queryParser name="CustomSolrPostFilter" class="CustomSolrPostFilter">
        <str name="myCustomConfigurationProperty">jdbc:sqlserver....</str>
    </queryParser>
    

    然后它可以在qparserplugin实现中访问:

    @Override
    public void init(NamedList namedList) {
        namedList.get("myCustomConfigurationProperty") //give "jdbc:sqlserver...."
    }