Approaches to Hierarchical Facets in Solr 处理Solr中分层的Facets

This document contains various suggestions and solutions for dealing with"Hierarchical Facets" - a concept which can mean differnet things todiffernet people depending on their data.

本文档包含处理"Hierarchical Facets"的各种建议和解决方案-根据数据的不同,"Hierarchical Facets"对不同的人可能意味着不同的东西。

Contents

  1. Approaches to Hierarchical Facets in Solr
  2. 'facet.prefix' Based Drill Down
    1. Flattened Data “breadcrumbs”
    2. Indexed Terms
    3. Initial Query
    4. Drill Down
  3. PathHierarchyTokenizerFactory
    1. Flattened Data
    2. Output Tokens
    3. Initial Query
  4. Pivot Facets
    1. Flattened Data “breadcrumbs”
    2. Indexed Terms
  5. Strict hierarchical facets
  6. Multipath hierarchical faceting
  7. Faceting Module

'facet.prefix' Based Drill Down

基于‘facet.prefix’的深度探讨。

Solr1.2

Transcribed (with slight edits) from Mastering the Power of Faceted Search by Chris Hostetterof Lucid Imagination (starting ~28minin)

For simple categories, facet.field works fine as-is. However,categorization schemes are frequently organized in a hierarchically-structuredscheme, and the user experience for interacting with thattaxonomy involves drill down,startingat the top (more general) and whittling the way down (more specific).

对于简单的分类,facet.field能正常的工作。然而分类方案经常被组织成层次结构化的,而且深入发掘与分类进行交互的用户体验,开始在顶端(一般)并且在深入中削减(更具体)

This is a basic approach that works well for most usecases and takes advantage of basic Solr faceting parameters by encoding thefacet terms at index time.

在索引时使用基本Solr faceting parameters对facet terms进行编码,是大多数用例下有效基本方法。

Flattened Data “breadcrumbs”

Doc#1: NonFic > Law

Doc#2: NonFic > Sci

Doc#3: NonFic > Hist, NonFic > Sci > Phys

In this example, we have documents associated with multiple categories,like Doc#3. We also have documents that are mapped to internal nodes, likeDoc#2.

在这个例子中,我们的doc与多重分类都有关系,如Doc#3。我们也有doc被映射到了内部节点,如Doc#2

You must perform some index time processing on this flattened data inorder to create the tokens needed for a facet.prefix approach. When we indexthe data we create specially formatted terms that encode the depth informationfor each node that appears as part of the path, and include the hierarchy separatedby a common separator (“depth/first level term/second level term/etc”). We alsoadd additional terms for every ancestors in the original data.

必须花一些索引时间处理flattened数据,以创建facet.prefix方法需要的令牌。当我们索引数据时,我们为路径每一部分节点编码深度信息,创建特殊格式term,并包括被通用分隔符隔开的层次结构(“depth/first levelterm/second level term/etc”) 。我们也为每一个原始数据中的祖先添加了附加的term。

Indexed Terms

Doc#1: 0/NonFic, 1/NonFic/Law

Doc#2: 0/NonFic, 1/NonFic/Sci

Doc#3: 0/NonFic, 1/NonFic/Hist,

            0/NonFic, 1/NonFic/Sci, 2/NonFic/Sci/Phys

Initial Query

With this type of index data, we can then go on and query this to get adrill-down. Initially, we can say we want to facet on the categoryfield with thefacet.prefix “1/NonFic”: things that arechildren ofNonFic at a depth of 1.

说完索引数据的类型,我们可以继续深入研究查询。最初,我们说过我们想使用facet.prefix “1/NonFic” facet on分类字段:NocFic的深度为1的子节点。

facet.field = category

facet.prefix = 1/NonFic

facet.mincount = 1

 

     2

     1

     1

Drill Down

If we drill down into NonFic/Sci, we just add thefq(filter query) as normal and tweak the facet.prefix from the children1/NonFic to the children of2/NonFic/Sci

如果我们要深入到NonFic/Sci,我们通常只需要添加fq (filter query),并且将facet.prefix从1/NonFic子节点微调到2/NonFic/Sci子节点。

fq = {!raw f=category}1/NonFic/Sci

facet.field = category

facet.prefix = 2/NonFic/Sci

facet.mincount = 1

 

     1

We’ve used the depth prefix that lets us look one level deep, but bytweaking the encoding, alternative user experiences can be created.

我们使用了深度前缀,让我们看清了层深,但是我们可以微调编码,建立可供选择的用户体验。

PathHierarchyTokenizerFactory

Solr3.1

The solr.PathHierarchyTokenizerFactory is designed to output file path hierarchies as synonyms,but can also be used in other simple hierarchies.

solr.PathHierarchyTokenizerFactory被设计来输出文件路径层次结构的同义词,但是也可以用在简单的层次结构

Flattened Data

Doc #1: /usr/local/apache

Doc #2: /etc/apache2

Doc #3: /etc/apache2/conf.d

Output Tokens

Doc #1: /usr, /usr/local, /usr/local/apache

Doc #2: /etc, /etc/apache2

Doc #3: /etc, /etc/apache2, /etc/apache2/conf.d

Initial Query

facet.field = category

facet.mincount = 1

 

     2

     2

     1

     1

     1

     1

Unlike the facet.prefix approach, it isn’t as easy to constrain thedepth of the taxonomies, but for small numbers of terms this may be a goodapproach.

facet.prefix方法不一样,它不容易约束分类的层深,但是对于很小的量还是一个好方法。

Pivot Facets

Solr4.0SOLR-792

Pivot facets are query time constructs that allow arbitrary facetresults, but they should be used wisely to avoid performance bottlenecks.

Pivot facet允许任意的facet结果的查询时概念,但是它们应该用的更精确来避免性能上的瓶颈。

You can think of it as "Decision Tree Faceting" which tells youin advance what the "next" set of facet results would be for a fieldif you apply a constraint from the current facet results, e.g. "for facet A, the constraints/counts are X/N,Y/M,” and if you were to constrain A by X, then the constraint counts for Bwould be S/P, T/Q, etc. Another way to think of it is each field is treated asa vector containing the constraint counts for that field, and taking a"cross product" to produce an N-dimensional matrix showing the countsfor each permutation.

你可以认为它像“决策树 Faceting” 预先告诉你,下一个facet结果接将是你从当前facet结果集上申请约束的字段,例如“对于facet A,约束/数量是X/N,Y/M”并且如果你要通过X约束A,则B的约束数量将是S/P,T/Q等等。以另一种方式来想每一个字段被当作一个包含这个字段约束数量的vector来看,并且那“cross product”来产生一个显示每种排列数量的N维矩阵。

This featurecan be easily applied to hierarchical facets insome cases, particularly those where a particular document only appears at onepoint in the taxonomy.

在一些用例中,这个feature可以很用以的被用于分成的facets,特别是当有一个特别的doc只出现分类的一点。

Flattened Data “breadcrumbs”

Doc#1: NonFic > Law

Doc#2: NonFic > Sci

Doc#3: NonFic > Sci > Phys

At index time, we split the data into a separate field for each level ofthe hierarchy.

在索引时,我们将层次结构中每一层数据分隔到独立的字段中。

Indexed Terms

Doc#1: category_level0: NonFic; category_level1: Law

Doc#2: category_level0: NonFic; category_level1: Sci

Doc#3: category_level0: NonFic; category_level1: Sci,category_level2:Phys

When querying Solr, we specify the facet.pivot parameter, which is acomma-separated list of fields to “pivot” on:

当查询Solr时,我们指定facet.pivot参数,这是一个逗号分隔的列表字段:

facet.pivot = category_level0,category_level1,category_level2

 

   

      category_level0

      NonFic

      3

      

        

            category_level1

            Law

             1

        

        

            category_level1

            Sci

            2

            

              

                  category_level2

                 Phys

                 1

              

             

         

      

你可能感兴趣的:(solr)