java

位置:IT落伍者 >> java >> 浏览文章

Java Lucene排重实现group by


发布日期:2023年02月28日
 
Java Lucene排重实现group by

package comloongtaolucenetest;

import javaioIOException;

import orgapacheluceneanalysisstandardStandardAnalyzer;

import orgapachelucenedocumentDocument;

import orgapachelucenedocumentField;

import orgapachelucenedocumentFieldIndex;

import orgapachelucenedocumentFieldStore;

import orgapacheluceneindexCorruptIndexException;

import orgapacheluceneindexIndexWriter;

import orgapacheluceneindexTerm;

import orgapacheluceneindexIndexWriterMaxFieldLength;

import orgapachelucenesearchDuplicateFilter;

import orgapachelucenesearchFilter;

import orgapachelucenesearchIndexSearcher;

import orgapachelucenesearchQuery;

import orgapachelucenesearchScoreDoc;

import orgapachelucenesearchTermQuery;

import orgapachelucenesearchTopDocs;

import orgapachelucenestoreDirectory;

import orgapachelucenestoreLockObtainFailedException;

import orgapachelucenestoreRAMDirectory;

import orgapacheluceneutilVersion;

public class DuplicateFilterTest {

public static void main(String[] args) {

Directory dir = new RAMDirectory();

Document doc = new Document();

docadd(new Field(id binbin StoreYES IndexNOT_ANALYZED));

docadd(new Field(string haha StoreYES IndexNOT_ANALYZED));

docadd(new Field(time StoreYES IndexNOT_ANALYZED));

docadd(new Field(duplicate StoreYES IndexNOT_ANALYZED));

Document doc = new Document();

docadd(new Field(id yaoyao StoreYES IndexNOT_ANALYZED));

docadd(new Field(string haha StoreYES IndexNOT_ANALYZED));

docadd(new Field(time StoreYES IndexNOT_ANALYZED));

doc

add(new Field(duplicate StoreYES

IndexNOT_ANALYZED));

Document doc = new Document();

docadd(new Field(id zhangjian StoreYES IndexNOT_ANALYZED));

docadd(new Field(string haha StoreYES IndexNOT_ANALYZED));

docadd(new Field(time StoreYES IndexNOT_ANALYZED));

doc

add(new Field(duplicate StoreYES

IndexNOT_ANALYZED));

Document doc = new Document();

docadd(new Field(id liweicheng StoreYES IndexNOT_ANALYZED));

docadd(new Field(string haha StoreYES IndexNOT_ANALYZED));

docadd(new Field(time StoreYES IndexNOT_ANALYZED));

doc

add(new Field(duplicate StoreYES

IndexNOT_ANALYZED));

try {

IndexWriter indexWriter = new IndexWriter(dir

new StandardAnalyzer(VersionLUCENE_) true

MaxFieldLengthLIMITED);

indexWriteraddDocument(doc);

indexWriteraddDocument(doc);

indexWriteraddDocument(doc);

indexWriteraddDocument(doc);

indexWriterclose();

Query query = new TermQuery(new Term(string haha));

Filter filter = new DuplicateFilter(duplicate);

IndexSearcher indexSearcher = new IndexSearcher(dir);

TopDocs top = indexSearchersearch(query filter );

ScoreDoc[] scoreDocs = topscoreDocs;

for (ScoreDoc scoreDoc : scoreDocs) {

Document rdoc = indexSearcherdoc(scoreDocdoc);

Systemoutprint(id:+rdocget(id) + 排重ID: +rdocget(duplicate));

Query queryDuplicate = new TermQuery(new Term(duplicate rdocget(duplicate)));

Systemoutprintln(转载:+ indexSearchersearch(queryDuplicate )totalHits

);

}

} catch (CorruptIndexException e) {

eprintStackTrace();

} catch (LockObtainFailedException e) {

eprintStackTrace();

} catch (IOException e) {

// TODO Autogenerated catch block

eprintStackTrace();

}

}

}

               

上一篇:Java开发工具Jcreator使用技巧总结

下一篇:Java包导入机制的研究与解析