mirror of https://github.com/apache/lucene.git
create all indexes w/ OpenMode.CREATE in facet demos
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1628410 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8f96faf3d3
commit
320be558d7
|
@ -38,6 +38,7 @@ import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
|
|||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.store.Directory;
|
||||
|
@ -61,7 +62,7 @@ public class AssociationsFacetsExample {
|
|||
|
||||
/** Build the example index. */
|
||||
private void index() throws IOException {
|
||||
IndexWriterConfig iwc = new IndexWriterConfig(new WhitespaceAnalyzer());
|
||||
IndexWriterConfig iwc = new IndexWriterConfig(new WhitespaceAnalyzer()).setOpenMode(OpenMode.CREATE);
|
||||
IndexWriter indexWriter = new IndexWriter(indexDir, iwc);
|
||||
|
||||
// Writes facet ords to a separate directory from the main index
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.apache.lucene.facet.taxonomy.TaxonomyReader;
|
|||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.queries.BooleanFilter;
|
||||
import org.apache.lucene.queries.function.ValueSource;
|
||||
import org.apache.lucene.search.BooleanClause;
|
||||
|
@ -54,8 +55,6 @@ import org.apache.lucene.store.Directory;
|
|||
import org.apache.lucene.store.RAMDirectory;
|
||||
import org.apache.lucene.util.SloppyMath;
|
||||
|
||||
|
||||
|
||||
/** Shows simple usage of dynamic range faceting, using the
|
||||
* expressions module to calculate distance. */
|
||||
public class DistanceFacetsExample implements Closeable {
|
||||
|
@ -88,7 +87,7 @@ public class DistanceFacetsExample implements Closeable {
|
|||
/** Build the example index. */
|
||||
public void index() throws IOException {
|
||||
IndexWriter writer = new IndexWriter(indexDir, new IndexWriterConfig(
|
||||
new WhitespaceAnalyzer()));
|
||||
new WhitespaceAnalyzer()).setOpenMode(OpenMode.CREATE));
|
||||
|
||||
// TODO: we could index in radians instead ... saves all the conversions in getBoundingBoxFilter
|
||||
|
||||
|
@ -246,7 +245,6 @@ public class DistanceFacetsExample implements Closeable {
|
|||
}
|
||||
|
||||
/** Runs the search and drill-down examples and prints the results. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void main(String[] args) throws Exception {
|
||||
DistanceFacetsExample example = new DistanceFacetsExample();
|
||||
example.index();
|
||||
|
@ -255,7 +253,6 @@ public class DistanceFacetsExample implements Closeable {
|
|||
System.out.println("-----------------------");
|
||||
System.out.println(example.search());
|
||||
|
||||
System.out.println("\n");
|
||||
System.out.println("Distance facet drill-down example (field/< 2 km):");
|
||||
System.out.println("---------------------------------------------");
|
||||
TopDocs hits = example.drillDown(example.TWO_KM);
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
|
|||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.search.SortField;
|
||||
|
@ -59,7 +60,7 @@ public class ExpressionAggregationFacetsExample {
|
|||
/** Build the example index. */
|
||||
private void index() throws IOException {
|
||||
IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(
|
||||
new WhitespaceAnalyzer()));
|
||||
new WhitespaceAnalyzer()).setOpenMode(OpenMode.CREATE));
|
||||
|
||||
// Writes facet ords to a separate directory from the main index
|
||||
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
|
|||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.store.Directory;
|
||||
|
@ -47,7 +48,7 @@ public class MultiCategoryListsFacetsExample {
|
|||
private final Directory taxoDir = new RAMDirectory();
|
||||
private final FacetsConfig config = new FacetsConfig();
|
||||
|
||||
/** Creates a new instance and populates the catetory list params mapping. */
|
||||
/** Creates a new instance and populates the category list params mapping. */
|
||||
public MultiCategoryListsFacetsExample() {
|
||||
config.setIndexFieldName("Author", "author");
|
||||
config.setIndexFieldName("Publish Date", "pubdate");
|
||||
|
@ -57,7 +58,7 @@ public class MultiCategoryListsFacetsExample {
|
|||
/** Build the example index. */
|
||||
private void index() throws IOException {
|
||||
IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(
|
||||
new WhitespaceAnalyzer()));
|
||||
new WhitespaceAnalyzer()).setOpenMode(OpenMode.CREATE));
|
||||
|
||||
// Writes facet ords to a separate directory from the main index
|
||||
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.lucene.facet.range.LongRangeFacetCounts;
|
|||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
|
@ -42,8 +43,6 @@ import org.apache.lucene.search.TopDocs;
|
|||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
|
||||
|
||||
|
||||
/** Shows simple usage of dynamic range faceting. */
|
||||
public class RangeFacetsExample implements Closeable {
|
||||
|
||||
|
@ -61,7 +60,7 @@ public class RangeFacetsExample implements Closeable {
|
|||
/** Build the example index. */
|
||||
public void index() throws IOException {
|
||||
IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(
|
||||
new WhitespaceAnalyzer()));
|
||||
new WhitespaceAnalyzer()).setOpenMode(OpenMode.CREATE));
|
||||
|
||||
// Add documents with a fake timestamp, 1000 sec before
|
||||
// "now", 2000 sec before "now", ...:
|
||||
|
@ -121,7 +120,6 @@ public class RangeFacetsExample implements Closeable {
|
|||
}
|
||||
|
||||
/** Runs the search and drill-down examples and prints the results. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void main(String[] args) throws Exception {
|
||||
RangeFacetsExample example = new RangeFacetsExample();
|
||||
example.index();
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
|
|||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.store.Directory;
|
||||
|
@ -58,7 +59,7 @@ public class SimpleFacetsExample {
|
|||
/** Build the example index. */
|
||||
private void index() throws IOException {
|
||||
IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(
|
||||
new WhitespaceAnalyzer()));
|
||||
new WhitespaceAnalyzer()).setOpenMode(OpenMode.CREATE));
|
||||
|
||||
// Writes facet ords to a separate directory from the main index
|
||||
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
|
||||
|
@ -235,17 +236,14 @@ public class SimpleFacetsExample {
|
|||
|
||||
System.out.println("Facet counting example (combined facets and search):");
|
||||
System.out.println("-----------------------");
|
||||
example = new SimpleFacetsExample();
|
||||
List<FacetResult> results = example.runSearch();
|
||||
System.out.println("Author: " + results.get(0));
|
||||
System.out.println("Publish Date: " + results.get(1));
|
||||
|
||||
example = new SimpleFacetsExample();
|
||||
System.out.println("Facet drill-down example (Publish Date/2010):");
|
||||
System.out.println("---------------------------------------------");
|
||||
System.out.println("Author: " + example.runDrillDown());
|
||||
|
||||
example = new SimpleFacetsExample();
|
||||
System.out.println("Facet drill-sideways example (Publish Date/2010):");
|
||||
System.out.println("---------------------------------------------");
|
||||
for(FacetResult result : example.runDrillSideways()) {
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState;
|
|||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.store.Directory;
|
||||
|
@ -56,7 +57,7 @@ public class SimpleSortedSetFacetsExample {
|
|||
/** Build the example index. */
|
||||
private void index() throws IOException {
|
||||
IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(
|
||||
new WhitespaceAnalyzer()));
|
||||
new WhitespaceAnalyzer()).setOpenMode(OpenMode.CREATE));
|
||||
Document doc = new Document();
|
||||
doc.add(new SortedSetDocValuesFacetField("Author", "Bob"));
|
||||
doc.add(new SortedSetDocValuesFacetField("Publish Year", "2010"));
|
||||
|
|
Loading…
Reference in New Issue