使用 apache solr 的 Facet 动态字段
我在 ApacheSolr 中定义了动态字段:
我用它来存储产品特征,例如:颜色特征、直径特征、材料特征等。由于产品不断变化,这些字段的数量并不恒定。
是否可以使用相同的查询获取所有这些动态字段的构面结果,或者我是否需要始终在查询中写入所有字段,例如... facet.field=color_feature&facet.field=diameter_feature&facet.field =material_feature&facet.field=
...
I have defined dynamic field in ApacheSolr:
I use it to store products features like: color_feature, diameter_feature, material_feature and so on. Number of those fields are not constant becouse products are changing.
Is it possible to get facet result for all those dynamic fields with the same query or do I need to write always all fields in a query like ... facet.field=color_feature&facet.field=diameter_feature&facet.field=material_feature&facet.field=
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Solr 目前不支持facet.field 参数中的通配符。
所以
*_feature
不适合你。可能想检查一下 - https://issues.apache.org/jira/browse/ SOLR-247
如果您不想传递参数,您可以轻松地将这些参数添加到请求处理程序默认值中。
请求中的
qt=requesthandler
将始终包含这些方面。Solr currently does not support wildcards in the facet.field parameter.
So
*_feature
won't work for you.May want to check on this - https://issues.apache.org/jira/browse/SOLR-247
If you don't want to pass parameters, you can easily add these to your request handler defaults.
The
qt=requesthandler
in request would always include these facets.我在电子商务平台工作时也遇到过类似的情况。每个项目都有静态字段(
Price
、Name
、Category
),可以轻松映射到 SOLR 的schema.xml
,但是每个项目还可以有动态数量的变化。例如,商店中的一件 T 恤可能有
颜色
(黑色
、白色
、红色
等。 )和尺寸
(小
、中
等)属性,而同一商店中的蜡烛可能有气味
代码> (<代码>南瓜,Vanilla
等)变体。本质上,这是一个实体-属性-值(EAV)关系数据库设计,用于描述产品的某些功能。由于从分面的角度来看,SOLR 中的 schema.xml 文件是扁平的,因此我通过将变体修改为单个多值字段来解决这个问题……
将数据库中的数据推入这些字段为
Color|Black
、Size|Small
和Scent|Pumpkin
......这样当我告诉 SOLR 进行构面时,然后我得到的结果看起来像......
所以我的代码解析这些结果以显示给用户,只需在我的
|
分隔符上进行拆分(假设我的键和值中都不会有|
),然后进行分组通过钥匙……这对于政府工作来说已经足够了。
这样做的一个缺点是,您将失去对此 EAV 数据执行范围方面的能力,但就我而言,这并不适用(
Price
字段适用于所有项目,并且因此在 schema.xml 中定义,以便可以以通常的方式进行分面)。希望这对某人有帮助!
I was in a similar situation when working on an e-commerce platform. Each item had static fields (
Price
,Name
,Category
) that easily mapped to SOLR'sschema.xml
, but each item could also have a dynamic amount of variations.For example, a t-shirt in the store could have
Color
(Black
,White
,Red
, etc.) andSize
(Small
,Medium
, etc.) attributes, whereas a candle in the same store could have aScent
(Pumpkin
,Vanilla
, etc.) variation. Essentially, this is an entity-attribute-value (EAV) relational database design used to describe some features of the product.Since the
schema.xml
file in SOLR is flat from the perspective of faceting, I worked around it by munging the variations into a single multi-valued field ...... shoving data from the database into these fields as
Color|Black
,Size|Small
, andScent|Pumpkin
...... so that when I tell SOLR to facet, then I get results that look like ...
... so that my code that parses these results to display to the user can just split on my
|
delimiter (assuming that neither my keys nor values will have a|
in them) and then group by the keys ...... which is good enough for government work.
One disadvantage of doing it this way is that you'll lose the ability to do range facets on this EAV data, but in my case, that didn't apply (the
Price
field applying to all items and thus being defined inschema.xml
so that it can be faceted in the usual way).Hope this helps someone!