solr 中的刻面

问题描述

朋友们好 我面临一个问题,因为我需要在 solr 中匹配以下查询

SELECT entidad,municipio,count(*) as total,sum(case when ip like '10.%' then 1 else 0 end) as internos,sum(case when ip not like '10.%' then 1 else 0 end) as externos 
 FROM bitacora.actividad a 
 where sistema = 'RGNPmarcas' 
 AND fecha >= '2021/07/16' and fecha <= '2021/07/31' 
 AND parametros like 'PDF'
 and parametros like 'EGV'
 and entidad = '01'
 GROUP BY entidad,municipio 
 ORDER BY entidad,municipio

我一直在研究 solr 中的分面,我已经开始计算如下,但事实是我不知道如何缓解这种情况。

enter image description here

我的架构如下:

<field name="tabla" type="string" indexed="true" stored="false" multiValued="false"/>
  <field name="entidad" type="string" indexed="true" stored="true" default="" multiValued="false"/>
  <field name="municipio" type="string" indexed="true" stored="true" default="" multiValued="false"/>
  <field name="ip" type="text_general" indexed="true" stored="true" default="" multiValued="false"/>
  <field name="fecha" type="pdate" indexed="true" stored="true" multiValued="false" default=""/>
  <field name="parametros" type="text_general" indexed="true" stored="true" default="" multiValued="false"/>
  <field name="total" type="pint" uninvertible="true" indexed="true" stored="true"/>
  <field name="internos" type="pint" uninvertible="true" indexed="true" stored="true"/>
  <field name="externos" type="pint" uninvertible="true" indexed="true" stored="true"/>

如您所见,我已经有了基础字段和索引字段,我需要的是您在这些 solr 问题上的经验或有人可以指导我,拜托!

解决方法

如果你可以有一个名称为“ip_type”的字段和内容“Internos”或“Externos”取决于天气或不以“10”开头的ip,那么你的查询将作为过滤器查询所有条件您在“where”(例如“sistema = 'RGNPMarcas'”)之后写的,方面数据透视表将有 3 个字段:“entidad,municipio,ip_type”。

现在,为了获取“ip_type”列,您可以更改索引数据的方式(更改输入),也可以使用模式替换字符过滤器工厂 (https://solr.apache.org/guide/7_1/charfilterfactories.html#solr-patternreplacecharfilterfactory)