CS 276 Lucene Section Agenda Lucene overview Specific

  • Slides: 8
Download presentation
CS 276 Lucene Section

CS 276 Lucene Section

Agenda Lucene overview Specific examples Luke

Agenda Lucene overview Specific examples Luke

Lucene: overview Apache Java text indexing project Rich query syntax Sorts returned results by

Lucene: overview Apache Java text indexing project Rich query syntax Sorts returned results by variant of tf-idf http: //lucene. apache. org/java/2_9_0/api/all/org/apache/lucene/search/Similarity. html

Lucene: indexing Index. Writer writer = new Index. Writer(index. Path, new Standard. Analyzer(), true,

Lucene: indexing Index. Writer writer = new Index. Writer(index. Path, new Standard. Analyzer(), true, Index. Writer. Max. Field. Length. LIMITED); Document doc = new Document(); doc. add(new Field("test", "value", Field. Store. YES, Field. Index. ANALYZED)); writer. add. Document(doc); writer. close();

Lucene: querying 1 Query query = new Query. Parser("some field", new Standard. Analyzer()). parse("some

Lucene: querying 1 Query query = new Query. Parser("some field", new Standard. Analyzer()). parse("some value"); Hits hits = index. Searcher. search(query); for (int ind = 0; ind < Math. min(hits. length(), 20); ind++) { Document doc = hits. doc(ind); System. out. println(print. Document(doc, hits. score(ind), "some field")); }

Lucene: querying 2 http: //lucene. apache. org/java/2_9_0/queryparsersyntax. html http: //lucene. apache. org/java/2_9_0/api/core/org/apache/lucene/search/Qu ery. html

Lucene: querying 2 http: //lucene. apache. org/java/2_9_0/queryparsersyntax. html http: //lucene. apache. org/java/2_9_0/api/core/org/apache/lucene/search/Qu ery. html Query query = new Term. Query(new Term("some field", "value")); Hits hits = index. Searcher. search(query); for (int ind = 0; ind < Math. min(hits. length(), 20); ind++) { Document doc = hits. doc(ind); System. out. println(print. Document(doc, hits. score(ind), "some field")); }

Lucene: querying 3 Query query = new Term. Query(new Term("some field", "value")); Top. Docs

Lucene: querying 3 Query query = new Term. Query(new Term("some field", "value")); Top. Docs docs = index. Searcher. search(query, 20); for (int ind = 0; ind < docs. total. Hits; ind++) { int doc. ID = docs. score. Docs[ind]. doc; Document doc = index. Searcher. doc(doc. ID); System. out. println(print. Document(doc, hits. score(ind), "some field")); }

Lucene: common problems No errors when field doesn't exist Update = delete + add

Lucene: common problems No errors when field doesn't exist Update = delete + add There is max field length javac -cp lib/lucene-core-2. 9. 0. jar: lib/lucenespellchecker-2. 9. 0. jar