1 package org.apache.lucene.facet.example.simple;
5 import org.apache.lucene.index.IndexReader;
6 import org.apache.lucene.store.Directory;
7 import org.apache.lucene.store.RAMDirectory;
9 import org.apache.lucene.facet.example.ExampleResult;
10 import org.apache.lucene.facet.example.ExampleUtils;
11 import org.apache.lucene.facet.search.results.FacetResult;
12 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
13 import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader;
16 * Licensed to the Apache Software Foundation (ASF) under one or more
17 * contributor license agreements. See the NOTICE file distributed with
18 * this work for additional information regarding copyright ownership.
19 * The ASF licenses this file to You under the Apache License, Version 2.0
20 * (the "License"); you may not use this file except in compliance with
21 * the License. You may obtain a copy of the License at
23 * http://www.apache.org/licenses/LICENSE-2.0
25 * Unless required by applicable law or agreed to in writing, software
26 * distributed under the License is distributed on an "AS IS" BASIS,
27 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 * See the License for the specific language governing permissions and
29 * limitations under the License.
33 * Driver for the simple sample.
35 * @lucene.experimental
37 public class SimpleMain {
40 * Driver for the simple sample.
41 * @throws Exception on error (no detailed exception handling here for sample simplicity
43 public static void main(String[] args) throws Exception {
44 new SimpleMain().runSimple();
45 new SimpleMain().runDrillDown().getFacetResults();
46 ExampleUtils.log("DONE");
49 public ExampleResult runSimple() throws Exception {
50 // create Directories for the search index and for the taxonomy index
51 Directory indexDir = new RAMDirectory();
52 Directory taxoDir = new RAMDirectory();
54 // index the sample documents
55 ExampleUtils.log("index the sample documents...");
56 SimpleIndexer.index(indexDir, taxoDir);
59 TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);
60 IndexReader indexReader = IndexReader.open(indexDir, true);
62 ExampleUtils.log("search the sample documents...");
63 List<FacetResult> facetRes = SimpleSearcher.searchWithFacets(indexReader, taxo);
69 ExampleResult res = new ExampleResult();
70 res.setFacetResults(facetRes);
74 public ExampleResult runDrillDown() throws Exception {
75 // create Directories for the search index and for the taxonomy index
76 Directory indexDir = new RAMDirectory();
77 Directory taxoDir = new RAMDirectory();
79 // index the sample documents
80 ExampleUtils.log("index the sample documents...");
81 SimpleIndexer.index(indexDir, taxoDir);
84 TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);
85 IndexReader indexReader = IndexReader.open(indexDir, true);
87 ExampleUtils.log("search the sample documents...");
88 List<FacetResult> facetRes = SimpleSearcher.searchWithDrillDown(indexReader, taxo);
94 ExampleResult res = new ExampleResult();
95 res.setFacetResults(facetRes);