add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / facet / src / examples / org / apache / lucene / facet / example / simple / SimpleMain.java
1 package org.apache.lucene.facet.example.simple;
2
3 import java.util.List;
4
5 import org.apache.lucene.index.IndexReader;
6 import org.apache.lucene.store.Directory;
7 import org.apache.lucene.store.RAMDirectory;
8
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;
14
15 /**
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
22  *
23  *     http://www.apache.org/licenses/LICENSE-2.0
24  *
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.
30  */
31
32 /**
33  * Driver for the simple sample.
34  * 
35  * @lucene.experimental
36  */
37 public class SimpleMain {
38
39   /**
40    * Driver for the simple sample.
41    * @throws Exception on error (no detailed exception handling here for sample simplicity
42    */
43   public static void main(String[] args) throws Exception {
44     new SimpleMain().runSimple();
45     new SimpleMain().runDrillDown().getFacetResults();
46     ExampleUtils.log("DONE");
47   }
48
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();
53
54     // index the sample documents
55     ExampleUtils.log("index the sample documents...");
56     SimpleIndexer.index(indexDir, taxoDir);
57
58     // open readers
59     TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);
60     IndexReader indexReader = IndexReader.open(indexDir, true);
61
62     ExampleUtils.log("search the sample documents...");
63     List<FacetResult> facetRes = SimpleSearcher.searchWithFacets(indexReader, taxo);
64
65     // close readers
66     taxo.close();
67     indexReader.close();
68     
69     ExampleResult res = new ExampleResult();
70     res.setFacetResults(facetRes);
71     return res;
72   }
73
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();
78     
79     // index the sample documents
80     ExampleUtils.log("index the sample documents...");
81     SimpleIndexer.index(indexDir, taxoDir);
82
83     // open readers
84     TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);
85     IndexReader indexReader = IndexReader.open(indexDir, true);
86
87     ExampleUtils.log("search the sample documents...");
88     List<FacetResult> facetRes = SimpleSearcher.searchWithDrillDown(indexReader, taxo);
89     
90     // close readers
91     taxo.close();
92     indexReader.close();
93     
94     ExampleResult res = new ExampleResult();
95     res.setFacetResults(facetRes);
96     return res;
97   }
98
99 }