How to get unique results from the Lucene index?

I am trying to search from lucene index. I want to get unique results, but also return duplicate results. I searched on google and found that this can be done using the collector. How can i achieve this?

I am using the following code:

File outputdir= new File("path upto lucene directory");
Directory directory = FSDirectory.open(outputdir);
IndexSearcher= new IndexSearcher(directory,true);

QueryParser queryparser = new QueryParser(Version.LUCENE_36, "keyword", new StandardAnalyzer(Version.LUCENE_36));

Query query = queryparser.parse("central");

topdocs = indexSearcher.search(query, maxhits);
ScoreDoc[] score = topdocs.scoreDocs;
int length = score.length;
+4
source share
4 answers

You should have a field called, for example, "duplicate", and set the value to "true" for the time of indexing, when the index already has a duplicate.

So you can search

Query query = queryparser.parse("central -duplicate:true");
+2
source

Do you index content before each search?

, , script , , Lucene , . , .

+1

, .

-, . , - . . , .

-, IndexSearcher.search. collector TopDocsCollector TopFieldDocCollector collect. collect, , Set doc, 0, super.collect(doc,score) Lucene. , Lucene .

0

:

  • - , .

  • - DuplicateFilter

DuplicateFilter df = new DuplicateFilter("Key"); df.setKeepMode(DuplicateFilter.KM_USE_LAST_OCCURRENCE); TopDocs hits = searcher.search(query, df, 10);

0

All Articles