~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/contrib/facet/src/examples/org/apache/lucene/facet/example/association/AssociationSearcher.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.lucene.facet.example.association;
2
 
 
3
 
import java.util.List;
4
 
 
5
 
import org.apache.lucene.index.IndexReader;
6
 
import org.apache.lucene.store.Directory;
7
 
 
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;
15
 
 
16
 
/**
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
23
 
 *
24
 
 *     http://www.apache.org/licenses/LICENSE-2.0
25
 
 *
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.
31
 
 */
32
 
 
33
 
/**
34
 
 * AssociationSearcher searches index with facets, evaluating the facets with
35
 
 * their associated $int value
36
 
 * 
37
 
 * @lucene.experimental
38
 
 */
39
 
public class AssociationSearcher {
40
 
 
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);
47
 
    
48
 
    AssociationIntSumFacetRequest facetRequest = new AssociationIntSumFacetRequest(
49
 
        new CategoryPath("tags"), 10);
50
 
    
51
 
    List<FacetResult> res = SimpleSearcher.searchWithRequest(indexReader, taxo,
52
 
        AssociationUtils.assocIndexingParams, facetRequest);
53
 
    
54
 
    // close readers
55
 
    taxo.close();
56
 
    indexReader.close();
57
 
    
58
 
    return res;
59
 
  }
60
 
  
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);
67
 
    
68
 
    AssociationFloatSumFacetRequest facetRequest = new AssociationFloatSumFacetRequest(
69
 
        new CategoryPath("genre"), 10);
70
 
    
71
 
    List<FacetResult> res = SimpleSearcher.searchWithRequest(indexReader, taxo,
72
 
        AssociationUtils.assocIndexingParams, facetRequest);
73
 
    
74
 
    // close readers
75
 
    taxo.close();
76
 
    indexReader.close();
77
 
    
78
 
    return res;
79
 
  }
80
 
  
81
 
}