Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS276 Lucene Section.

Similar presentations


Presentation on theme: "CS276 Lucene Section."— Presentation transcript:

1 CS276 Lucene Section

2 Agenda Lucene overview Specific examples Luke

3 Lucene: overview Apache Java text indexing project Rich query syntax
Sorts returned results by variant of tf-idf

4 Lucene: indexing IndexWriter writer = new IndexWriter(indexPath, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED); Document doc = new Document(); doc.add(new Field("test", "value", Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc); writer.close();

5 Lucene: querying 1 Query query = new QueryParser("some field", new StandardAnalyzer()).parse("some value"); Hits hits = indexSearcher.search(query); for (int ind = 0; ind < Math.min(hits.length(), 20); ind++) { Document doc = hits.doc(ind); System.out.println(printDocument(doc, hits.score(ind),"some field")); }

6 Lucene: querying 2 ery.html Query query = new TermQuery(new Term("some field","value")); Hits hits = indexSearcher.search(query); for (int ind = 0; ind < Math.min(hits.length(), 20); ind++) { Document doc = hits.doc(ind); System.out.println(printDocument(doc, hits.score(ind),"some field")); }

7 Lucene: querying 3 Query query = new TermQuery(new Term("some field","value")); TopDocs docs = indexSearcher.search(query, 20); for (int ind = 0; ind < docs.totalHits; ind++) { int docID = docs.scoreDocs[ind].doc; Document doc = indexSearcher.doc(docID); System.out.println(printDocument(doc, hits.score(ind),"some field")); }

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


Download ppt "CS276 Lucene Section."

Similar presentations


Ads by Google