Lucene学习总结-扩展查询
custom sort method:
custom HitCollector:
Please read full article from
Lucene学习总结-扩展查询
custom sort method:
- Sort sort = new Sort(new SortField("location",
- new DistanceComparatorSource(10, 10)));
- TopFieldDocs docs = searcher.search(query, null, 3, sort);
- FieldDoc fieldDoc = (FieldDoc) docs.scoreDocs[0];
- Document document = searcher.doc(fieldDoc.doc);
custom HitCollector:
- public void testCollecting() throws Exception {
- TermQuery query = new TermQuery(new Term("contents", "junit"));
- IndexSearcher searcher = new IndexSearcher(TestUtil.getBookIndexDirectory());
- BookLinkCollector collector = new BookLinkCollector(searcher);
- searcher.search(query, collector);
- Map linkMap = collector.getLinks();
- TopDocs hits = searcher.search(query, 10);
- TestUtil.dumpHits(searcher, hits);
- searcher.close();
Extending QueryParser:getFieldQuery,getFuzzyQuery,getPrefixQuery,getRangeQuery,getBooleanQuery,getWildcardQuery
custom filter:
- SpecialsAccessor accessor = new TestSpecialsAccessor(isbns);
- Filter filter = new SpecialsFilter(accessor);
- WildcardQuery educationBooks = // #2
- new WildcardQuery(new Term("category", "*education*")); // #2
- FilteredQuery edBooksOnSpecial = // #2
- new FilteredQuery(educationBooks, filter); // #2
- TermQuery logoBooks = // #3
- new TermQuery(new Term("subject", "logo")); // #3
- BooleanQuery logoOrEdBooks = new BooleanQuery(); // #4
- logoOrEdBooks.add(logoBooks, BooleanClause.Occur.SHOULD); // #4
- logoOrEdBooks.add(edBooksOnSpecial, BooleanClause.Occur.SHOULD); // #4
- TopDocs hits = searcher.search(logoOrEdBooks, 10);
Payloads:相当于对文档分类,DefaultSimilarity,PayloadHelper,
- doc1.add(new Field("category", "foods|0.984 shopping|0.503", Field.Store.YES, Field.Index.ANALYZED));
- String queries = "category:foods content:egg";
- searcher.setSimilarity(new PayloadSimilarity());
- payloadSearcher.display(payloadSearcher.search(queries), start, end);
No comments:
Post a Comment