List of usage examples for org.apache.lucene.index IndexWriter addDocument
public long addDocument(Iterable<? extends IndexableField> doc) throws IOException
From source file:com.leavesfly.lia.advsearching.MultiPhraseQueryTest.java
License:Apache License
protected void setUp() throws Exception { Directory directory = new RAMDirectory(); IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED); Document doc1 = new Document(); doc1.add(new Field("field", "the quick brown fox jumped over the lazy dog", Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc1); Document doc2 = new Document(); doc2.add(new Field("field", "the fast fox hopped over the hound", Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc2);//from www . jav a 2 s .c om writer.close(); searcher = new IndexSearcher(directory); }
From source file:com.leavesfly.lia.advsearching.MultiSearcherTest.java
License:Apache License
public void setUp() throws Exception { String[] animals = { "aardvark", "beaver", "coati", "dog", "elephant", "frog", "gila monster", "horse", "iguana", "javelina", "kangaroo", "lemur", "moose", "nematode", "orca", "python", "quokka", "rat", "scorpion", "tarantula", "uromastyx", "vicuna", "walrus", "xiphias", "yak", "zebra" }; Analyzer analyzer = new WhitespaceAnalyzer(); Directory aTOmDirectory = new RAMDirectory(); // #1 Directory nTOzDirectory = new RAMDirectory(); // #1 IndexWriter aTOmWriter = new IndexWriter(aTOmDirectory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED); IndexWriter nTOzWriter = new IndexWriter(nTOzDirectory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED); for (int i = animals.length - 1; i >= 0; i--) { Document doc = new Document(); String animal = animals[i]; doc.add(new Field("animal", animal, Field.Store.YES, Field.Index.NOT_ANALYZED)); if (animal.charAt(0) < 'n') { aTOmWriter.addDocument(doc); // #2 } else {/*w ww .j a v a 2 s . com*/ nTOzWriter.addDocument(doc); // #2 } } aTOmWriter.close(); nTOzWriter.close(); searchers = new IndexSearcher[2]; searchers[0] = new IndexSearcher(aTOmDirectory); searchers[1] = new IndexSearcher(nTOzDirectory); }
From source file:com.leavesfly.lia.advsearching.SecurityFilterTest.java
License:Apache License
protected void setUp() throws Exception { Directory directory = new RAMDirectory(); IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED); Document document = new Document(); // 1 document.add(new Field("owner", // 1 "elwood", // 1 Field.Store.YES, // 1 Field.Index.NOT_ANALYZED)); // 1 document.add(new Field("keywords", // 1 "elwood's sensitive info", // 1 Field.Store.YES, // 1 Field.Index.ANALYZED)); // 1 writer.addDocument(document); document = new Document(); // 2 document.add(new Field("owner", // 2 "jake", // 2 Field.Store.YES, // 2 Field.Index.NOT_ANALYZED)); // 2 document.add(new Field("keywords", // 2 "jake's sensitive info", // 2 Field.Store.YES, // 2 Field.Index.ANALYZED)); // 2 writer.addDocument(document);/* ww w. j a v a 2s. co m*/ writer.close(); searcher = new IndexSearcher(directory); }
From source file:com.leavesfly.lia.advsearching.SpanQueryTest.java
License:Apache License
protected void setUp() throws Exception { directory = new RAMDirectory(); analyzer = new WhitespaceAnalyzer(); IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED); Document doc = new Document(); doc.add(new Field("f", "the quick brown fox jumps over the lazy dog", Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc); doc = new Document(); doc.add(new Field("f", "the quick red fox jumps over the sleepy cat", Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc);/*w ww . j a va 2 s .c o m*/ writer.close(); searcher = new IndexSearcher(directory); reader = searcher.getIndexReader(); quick = new SpanTermQuery(new Term("f", "quick")); brown = new SpanTermQuery(new Term("f", "brown")); red = new SpanTermQuery(new Term("f", "red")); fox = new SpanTermQuery(new Term("f", "fox")); lazy = new SpanTermQuery(new Term("f", "lazy")); sleepy = new SpanTermQuery(new Term("f", "sleepy")); dog = new SpanTermQuery(new Term("f", "dog")); cat = new SpanTermQuery(new Term("f", "cat")); }
From source file:com.leavesfly.lia.analysis.Fragments.java
License:Apache License
public void frag2() throws Exception { IndexWriter writer = null; // START/* w ww . j a v a 2 s. c om*/ Document doc = new Document(); doc.add(new Field("title", "This is the title", Field.Store.YES, Field.Index.ANALYZED)); doc.add(new Field("contents", "...document contents...", Field.Store.NO, Field.Index.ANALYZED)); writer.addDocument(doc); // END }
From source file:com.leavesfly.lia.analysis.keyword.KeywordAnalyzerTest.java
License:Apache License
public void setUp() throws Exception { Directory directory = new RAMDirectory(); IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED); Document doc = new Document(); doc.add(new Field("partnum", "Q36", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS)); // A doc.add(new Field("description", "Illidium Space Modulator", Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc); writer.close();// w w w.j a v a 2 s . c o m searcher = new IndexSearcher(directory); }
From source file:com.leavesfly.lia.analysis.positional.PositionalPorterStopAnalyzerTest.java
License:Apache License
public void setUp() throws Exception { RAMDirectory directory = new RAMDirectory(); IndexWriter writer = new IndexWriter(directory, porterAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED); Document doc = new Document(); doc.add(new Field("contents", "The quick brown fox jumps over the lazy dog", Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc); writer.close();/*from w w w .jav a 2 s.c o m*/ searcher = new IndexSearcher(directory, true); parser = new QueryParser(Version.LUCENE_30, "contents", porterAnalyzer); }
From source file:com.leavesfly.lia.analysis.synonym.SynonymAnalyzerTest.java
License:Apache License
public void setUp() throws Exception { RAMDirectory directory = new RAMDirectory(); IndexWriter writer = new IndexWriter(directory, synonymAnalyzer, // #1 IndexWriter.MaxFieldLength.UNLIMITED); Document doc = new Document(); doc.add(new Field("content", "The quick brown fox jumps over the lazy dog", Field.Store.YES, Field.Index.ANALYZED)); // #2 writer.addDocument(doc); writer.close();/*from ww w . jav a2 s . com*/ searcher = new IndexSearcher(directory, true); }
From source file:com.leavesfly.lia.analysis.UsingAnalyzersExample.java
License:Apache License
/** * This method doesn't do anything, except compile correctly. * This is used to show snippets of how Analyzers are used. */// ww w. j av a 2s . co m public void someMethod() throws IOException, ParseException { RAMDirectory directory = new RAMDirectory(); Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30); IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED); Document doc = new Document(); doc.add(new Field("title", "This is the title", Field.Store.YES, Field.Index.ANALYZED)); doc.add(new Field("contents", "...document contents...", Field.Store.NO, Field.Index.ANALYZED)); writer.addDocument(doc); writer.addDocument(doc, analyzer); String expression = "some query"; Query query = new QueryParser(Version.LUCENE_30, "contents", analyzer).parse(expression); QueryParser parser = new QueryParser(Version.LUCENE_30, "contents", analyzer); query = parser.parse(expression); }
From source file:com.leavesfly.lia.commom.CreateTestIndex.java
License:Apache License
public static void main(String[] args) throws IOException { String dataDir = args[0];//from ww w . ja v a 2s .c o m String indexDir = args[1]; List<File> results = new ArrayList<File>(); findFiles(results, new File(dataDir)); System.out.println(results.size() + " books to index"); Directory dir = FSDirectory.open(new File(indexDir)); IndexWriter w = new IndexWriter(dir, new MyStandardAnalyzer(Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED); for (File file : results) { Document doc = getDocument(dataDir, file); w.addDocument(doc); } w.close(); dir.close(); }