1
package org.apache.lucene.facet.example.association;
5
import org.apache.lucene.index.IndexReader;
6
import org.apache.lucene.store.Directory;
8
import org.apache.lucene.facet.example.simple.SimpleSearcher;
9
import org.apache.lucene.facet.search.params.association.AssociationFloatSumFacetRequest;
10
import org.apache.lucene.facet.search.params.association.AssociationIntSumFacetRequest;
11
import org.apache.lucene.facet.search.results.FacetResult;
12
import org.apache.lucene.facet.taxonomy.CategoryPath;
13
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
14
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
17
* Licensed to the Apache Software Foundation (ASF) under one or more
18
* contributor license agreements. See the NOTICE file distributed with
19
* this work for additional information regarding copyright ownership.
20
* The ASF licenses this file to You under the Apache License, Version 2.0
21
* (the "License"); you may not use this file except in compliance with
22
* the License. You may obtain a copy of the License at
24
* http://www.apache.org/licenses/LICENSE-2.0
26
* Unless required by applicable law or agreed to in writing, software
27
* distributed under the License is distributed on an "AS IS" BASIS,
28
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
* See the License for the specific language governing permissions and
30
* limitations under the License.
34
* AssociationSearcher searches index with facets, evaluating the facets with
35
* their associated $int value
37
* @lucene.experimental
39
public class AssociationSearcher {
41
/** Search an index with a sum of int-association. */
42
public static List<FacetResult> searchSumIntAssociation(Directory indexDir,
43
Directory taxoDir) throws Exception {
44
// prepare index reader
45
IndexReader indexReader = IndexReader.open(indexDir);
46
TaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
48
AssociationIntSumFacetRequest facetRequest = new AssociationIntSumFacetRequest(
49
new CategoryPath("tags"), 10);
51
List<FacetResult> res = SimpleSearcher.searchWithRequest(indexReader, taxo,
52
AssociationUtils.assocIndexingParams, facetRequest);
61
/** Search an index with a sum of float-association. */
62
public static List<FacetResult> searchSumFloatAssociation(Directory indexDir,
63
Directory taxoDir) throws Exception {
64
// prepare index reader
65
IndexReader indexReader = IndexReader.open(indexDir);
66
TaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
68
AssociationFloatSumFacetRequest facetRequest = new AssociationFloatSumFacetRequest(
69
new CategoryPath("genre"), 10);
71
List<FacetResult> res = SimpleSearcher.searchWithRequest(indexReader, taxo,
72
AssociationUtils.assocIndexingParams, facetRequest);