Lucene学习总结-高级查询

Field cache:在一个IndexReader生命周期内,用于排序。

Sort:Sort.RELEVANCE,Sort.INDEXORDER,按照Field排序new Sort("category"),升序new Sort("pubmonth", true),

IndexSearcher searcher = new IndexSearcher(directory);
TopDocs results = searcher.search(query, null, 20, sort);

多个Field排序:

new Sort(new SortField[]{
new SortField("category"),
SortField.FIELD_SCORE,
new SortField("pubmonth", SortField.INT, true)
})

MultiPhraseQuery:类似于PhraseQuery,可以设置多个短语的查询。

MultiPhraseQuery query = new MultiPhraseQuery();
query.add(new Term[] { // #1
new Term("field", "quick"), // #1
new Term("field", "fast") // #1
});
query.add(new Term("field", "fox"));
TopDocs hits = searcher.search(query, 10);
query.setSlop(1);
hits = searcher.search(query, 10);

SpanTermQuery:没神马特殊。

SpanFirstQuery:从开头开始的n个term包含查询项。

SpanFirstQuery sfq = new SpanFirstQuery(brown, 2);

SpanQuery,不能用QueryParser。

过滤查询:

String jan1 = TestUtil.parseDate("2004-01-01");
String jan31 = TestUtil.parseDate("2004-01-31");
String dec31 = TestUtil.parseDate("2004-12-31");
RangeFilter filter = new RangeFilter("modified", jan1, dec31, true, true);
Filter filter = new FieldCacheTermsFilter("pubmonth",new String[] {"199910","200406"});
TermQuery categoryQuery = new TermQuery(new Term("category", "/philosophy/eastern"));
Filter categoryFilter = new QueryWrapperFilter(categoryQuery);
Filter prefixFilter = new PrefixFilter(new Term("pubmonth", "19"));

MultiSearcher:

MultiSearcher searcher = new MultiSearcher(searchers);
// range spans documents across both indexes
RangeQuery query = new RangeQuery("animal", "h", "t", true, true);// #3
query.setConstantScoreRewrite(true);
TopDocs hits = searcher.search(query, 10);

ParallelMultiSearcher:

远程查询:

LocateRegistry.createRegistry(1099);
Searchable[] searchables = new Searchable[ALPHABET.length()];
Searcher multiSearcher = new MultiSearcher(searchables);
RemoteSearchable multiImpl = new RemoteSearchable(multiSearcher);
Naming.rebind("//localhost/LIA_Multi", multiImpl);
Searcher parallelSearcher = new ParallelMultiSearcher(searchables);
RemoteSearchable parallelImpl = new RemoteSearchable(parallelSearcher);
Naming.rebind("//localhost/LIA_Parallel", parallelImpl);

TermFreqVector:

FieldSelector:

 

你可能感兴趣的:(Lucene学习总结-高级查询)