Solr:分为两个输出的一个场 [英] Solr: Facet one field with two outputs

查看:81
本文介绍了Solr:分为两个输出的一个场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Solr对产品进行索引并将它们组织成几个类别.每个文档都有一个taxon_names多值字段,其中的类别存储为产品的人类可读字符串.

I'm using Solr for indexing products and organising them into several categories. Each document has a taxon_names multi value field, where the categories are stored as human readable strings for a product.

现在,我想从Solr中获取所有类别,并通过指向用户的可点击链接显示它们,而无需再次点击数据库.在索引时,我从MySQL数据库获取每个类别的永久链接,该数据库存储为多值字段taxon_permalinks.为了生成产品的链接,我需要该类别及其永久链接的人类可读格式(否则,仅使用该类别的普通人类可读名称(例如,%20用于空格),您的浏览器中就会有这些丑陋的URL)

Now I want to fetch all the categories from Solr and display them with clickable links to the user, without hitting the database again. At index time, I get the permalinks for every category from the MySQL database, which is stored as a multi value field taxon_permalinks. For generating the links to the products, I need the human readable format of the category and its permalink (otherwise you would have such ugly URLs in your browser, when just using the plain human readable name of the category, e.g. %20 for space).

当我使用http://localhost:8982/solr/default/select?q=*%3A*&rows=0&wt=xml&facet=true&facet.field=taxon_names进行方面搜索时,我得到了人类可读的分类单元及其计数列表.基于此列表,我想创建链接,这样就不必再次访问数据库.

When I do a facet search with http://localhost:8982/solr/default/select?q=*%3A*&rows=0&wt=xml&facet=true&facet.field=taxon_names, I get a list of human readable taxons with its counts. Based on this list, I want to create the links, so that I don't have to hit the database again.

那么,是否可以从Solr检索不同类别的匹配永久链接?例如,我得到这样的XML:

So, is it possible to retrieve the matching permalinks from Solr for the different categories? For example, I get a XML like this:

<response>
<lst name="responseHeader">
  <int name="status">0</int>
  <int name="QTime">0</int>
</lst>
<result name="response" numFound="6580" start="0"/>
  <lst name="facet_counts">
  <lst name="facet_queries"/>
  <lst name="facet_fields">
  <lst name="taxon_names">
    <int name="Books">2831</int>
    <int name="Music">984</int>
      ...
  </lst>
</result>

taxon_names数组中,我需要永久链接的名称.

And inside the taxon_names array I would need the name of the permalink.

也许可以通过在配置XML中定义自定义字段类型来实现.但是,为此,我没有足够的Solr经验.

Maybe it's possible by defining a custom field type in the config XMLs. But for this, I don't have enough experience with Solr.

推荐答案

由于从您的描述中可以看出,您在taxon_permalink字段中遇到了固定链接,并且该字段中的值应与taxon_names字段. Solr允许您在多个字段上进行构面,因此您可以仅在两个字段上进行构面,并通过taxon_names构面值和taxon_permalink构面值中的固定链接获取两个构面结果.

Since it appears from your description that you are faceting permalink in the taxon_permalink field and the values in that field should correspond to the same category names in the taxon_names field. Solr allows you to facet on multiple fields, so you can just facet on both fields and walk the two facet results grabbing the display name from the taxon_names facet values and the permalink from the taxon_permalink facet values.

查询:

 http://localhost:8982/solr/default/selectq=*%3A*&rows=0&wt=xml
   &facet=true&facet.field=taxon_names&facet.field=taxon_permalink

您的输出应类似于以下内容:

Your output should then look like similar to the following:

<response>
<lst name="responseHeader">
  <int name="status">0</int>
  <int name="QTime">0</int>
</lst>
<result name="response" numFound="6580" start="0"/>
  <lst name="facet_counts">
  <lst name="facet_queries"/>
  <lst name="facet_fields">
  <lst name="taxon_names">
    <int name="Books">2831</int>
    <int name="Music">984</int>
      ...
  </lst>
  <lst name="taxon_permalink">
    <int name="permalink1">2831</int>
    <int name="permalink2">984</int>
      ...
  </lst>
</result>

这篇关于Solr:分为两个输出的一个场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆