1 package org.apache.lucene.facet.search.results;
3 import org.apache.lucene.facet.search.params.FacetRequest;
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements. See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * Result of faceted search.
25 * @lucene.experimental
27 public class FacetResult {
29 private final FacetRequest facetRequest;
30 private final FacetResultNode rootNode;
31 private final int numValidDescendants;
33 public FacetResult(FacetRequest facetRequest, FacetResultNode rootNode, int numValidDescendants) {
34 this.facetRequest = facetRequest;
35 this.rootNode = rootNode;
36 this.numValidDescendants = numValidDescendants;
40 * Facet result node matching the root of the {@link #getFacetRequest() facet request}.
41 * @see #getFacetRequest()
42 * @see FacetRequest#getCategoryPath()
44 public final FacetResultNode getFacetResultNode() {
49 * Number of descendants of {@link #getFacetResultNode() root facet result node},
50 * up till the requested depth, which are valid by the
51 * {@link FacetRequest#createFacetResultsHandler(org.apache.lucene.facet.taxonomy.TaxonomyReader)
52 * results handler in effect}. Typically -- have value != 0.
53 * This number does not include the root node.
54 * @see #getFacetRequest()
55 * @see FacetRequest#getDepth()
57 public final int getNumValidDescendants() {
58 return this.numValidDescendants;
62 * Request for which this result was obtained.
64 public final FacetRequest getFacetRequest() {
65 return this.facetRequest;
69 * String representation of this facet result.
70 * Use with caution: might return a very long string.
71 * @param prefix prefix for each result line
74 public String toString(String prefix) {
75 StringBuilder sb = new StringBuilder();
79 if (this.facetRequest != null) {
80 sb.append(nl).append(prefix).append("Request: ").append(
81 this.facetRequest.toString());
86 sb.append(nl).append(prefix).append("Num valid Descendants (up to specified depth): ").append(
87 this.numValidDescendants);
91 if (this.rootNode != null) {
92 sb.append(nl).append(this.rootNode.toString(prefix + "\t"));
99 public String toString() {