简体   繁体   English

如何计算 solr 中的多值字段

[英]How to count multi-valued Field in solr

I Want to count multi-valued field in SOLR.我想计算 SOLR 中的多值字段。

I have two multi-valued fields store_id and filter_id and i want to count these field value like我有两个多值字段 store_id 和 filter_id 我想计算这些字段值

store_id = {0,3,7} count_store_id = 3 store_id = {0,3,7} count_store_id = 3

filter_id = {12,13,20,22,59,61,62,145} count_filter_id = 8 filter_id = {12,13,20,22,59,61,62,145} count_filter_id = 8

在此处输入图像描述

and is that possible when store_id is update then count_store_id also update in solr by default并且当 store_id 更新然后 count_store_id 默认情况下也会在 solr 中更新时是否可能

@@ Ashraful Islam - As you told me i'll change it but there is nothing going happen here i attach image find it. @@ Ashraful Islam - 正如你告诉我的那样,我会改变它,但这里没有任何事情发生,我附上图片找到它。

在此处输入图像描述

Yes as suggested by Alexandre Rafalovitch, by using defining custom UpdaterequestProcessor you can get the count value of multivalued field. 是的,正如亚历山大·拉法洛维奇(Alexandre Rafalovitch)所建议的,通过定义自定义UpdaterequestProcessor您可以获取多值字段的计数值。

add below lines in your solrconfig.xml 在solrconfig.xml中添加以下行

<updateRequestProcessorChain name="multivaluecountnum" default="true">
   <processor class="solr.CloneFieldUpdateProcessorFactory">
     <str name="source">store_id</str>
     <str name="dest">store_id_count</str>
   </processor>
<processor class="solr.CloneFieldUpdateProcessorFactory">
     <str name="source">filter_id</str>
     <str name="dest">filter_id_count</str>
   </processor>
   <processor class="solr.CountFieldValuesUpdateProcessorFactory">
     <str name="fieldName">store_id_count</str>
   </processor>
 <processor class="solr.CountFieldValuesUpdateProcessorFactory">
     <str name="fieldName">filter_id_count</str>
   </processor>
   <processor class="solr.DefaultValueUpdateProcessorFactory">
     <str name="fieldName">store_id_count</str>
     <int name="value">0</int>
   </processor>
<processor class="solr.DefaultValueUpdateProcessorFactory">
     <str name="fieldName">filter_id_count</str>
     <int name="value">0</int>
   </processor>
<processor class="solr.LogUpdateProcessorFactory" />
  <processor class="solr.RunUpdateProcessorFactory" />
 </updateRequestProcessorChain>

Do not forget to add RunUpdateProcessorFactory at the end of any chains you define in solrconfig.xml 不要忘记在solrconfig.xml中定义的任何链的末尾添加RunUpdateProcessorFactory

Add store_id_count and filter_id_count fields in schema file 在架构文件中添加store_id_count和filter_id_count字段

   <field name="store_id_count" type="int" stored="true"/>
   <field name="filter_id_count" type="int" stored="true"/>

Reindex docs and query, you will see two new fields store_id_count and filter_id_count in result. 重新索引文档和查询,您将在结果中看到两个新字段store_id_count和filter_id_count。

Hope this Helps, Vinod. 希望对您有帮助,Vinod。

您可以使用使用CountFieldValuesUpdateProcessorFactory的自定义UpdateRequestProcessor链来执行此操作

In my Solr Schema I have a multivalued field <field name="Student_id" type="string" indexed="true" stored="true" multiValued="true"/> I Want count the multivalued field. So I Am using schema.xml -> <field name="Student_id_count" indexed="true" type="pint" stored="true"/> solrConfig - > <updateRequestProcessorChain name="multivaluecountnum" default="true"> <processor class="solr.CloneFieldUpdateProcessorFactory"> <str name="source">Student_id</str> <str name="dest">Student_id_count</str> </processor> <processor class="solr.CountFieldValuesUpdateProcessorFactory"> <str name="fieldName">Student_id_count</str> </processor> <processor class="solr.DefaultValueUpdateProcessorFactory"> <str name="fieldName">Student_id_count</str> <int name="value">0</int> </processor> <processor class="solr.LogUpdateProcessorFactory" /> <processor class="solr.RunUpdateProcessorFactory" /> </updateRequestProcessorChain> <schemaFactory class="ClassicIndexSchemaFactory"/> </config> But It's Not working. How to resolve my issue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM