2

我有一个描述树结构的分类索引。执行查询时,我想获取多个类别的命中数(不一定在树的同一级别)。例如,给定以下路径列表:

[Root/Cat1, Root/Cat1/Cat12, Root/Cat3]

我想获得这三个类别中每一个的点击数。

我一直在寻找解决方案,我知道可以发出树请求,然后通过调用获取结果.getSubResults()(如API中所述)。但是我没有找到任何示例,我真的不知道如何实现它。到目前为止,我有以下几点:

    // Build query
    Query query = extendQuery(queryGenerator.generateQuery(resource));

    // Set the number of top results        
    TopScoreDocCollector tdc = TopScoreDocCollector.create(numTopDocuments, true);

    // Set a faceted search
    FacetSearchParams facetSearchParams = new FacetSearchParams();

    // Search at level of the category in interests     
    CountFacetRequest facetRequest = new CountFacetRequest(new CategoryPath("Top", '/'), numTopCategories);

    facetRequest.setResultMode(ResultMode.PER_NODE_IN_TREE);

    facetSearchParams.addFacetRequest(facetRequest);                    

    // To collect the number of hits per facet
    FacetsCollector facetsCollector = 
            new FacetsCollector(facetSearchParams, documentReader, taxonomyReader);
    try {
        // Collect the number of hits per facet
        documentSearcher
                .search(query, MultiCollector.wrap(tdc, facetsCollector));                          
        for (FacetResult res : facetsCollector.getFacetResults()){
            //this is the top lvl facet
              FacetResultNode toplvl = res.getFacetResultNode();
              System.out.println(toplvl.getLabel() + " (" + toplvl.getValue() + ")");
              for (FacetResultNode secondlvl : toplvl.getSubResults()) {
                  //second lvl facet categories
                  System.out.println("  " + secondlvl.getLabel().getComponent(1) 
                                + " (" + secondlvl.getValue() + ")");
                  for (FacetResultNode thirdlvl : secondlvl.getSubResults()) {
                      //second lvl facet categories
                      System.out.println("  " + thirdlvl.getLabel().getComponent(2) 
                                    + " (" + thirdlvl.getValue() + ")");
                  }
              }
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

但是,当我到达第三级时,我得到了空值。到底是怎么回事?

谢谢。

4

1 回答 1

1

您还必须设置:

facetRequest.setDepth(MAX_DEPTH_TREE);
于 2013-02-13T14:59:57.503 回答