知识大全 Java Lucene排重实现group by

Posted 文字

篇首语:赋料扬雄敌,诗看子建亲。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 Java Lucene排重实现group by相关的知识,希望对你有一定的参考价值。

Java Lucene排重实现group by  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  package loongtao lucene test;

  import java io IOException;

  import apache lucene analysis standard StandardAnalyzer;

  import apache lucene document Document;

  import apache lucene document Field;

  import apache lucene document Field Index;

  import apache lucene document Field Store;

  import apache lucene index CorruptIndexException;

  import apache lucene index IndexWriter;

  import apache lucene index Term;

  import apache lucene index IndexWriter MaxFieldLength;

  import apache lucene search DuplicateFilter;

  import apache lucene search Filter;

  import apache lucene search IndexSearcher;

  import apache lucene search Query;

  import apache lucene search ScoreDoc;

  import apache lucene search TermQuery;

  import apache lucene search TopDocs;

  import apache lucene store Directory;

  import apache lucene store LockObtainFailedException;

  import apache lucene store RAMDirectory;

  import apache lucene util Version;

  public class DuplicateFilterTest

  public static void main(String[] args)

  Directory dir = new RAMDirectory();

  Document doc = new Document();

  doc add(new Field( id binbin Store YES Index NOT_ANALYZED));

  doc add(new Field( string haha Store YES Index NOT_ANALYZED));

  doc add(new Field( time Store YES Index NOT_ANALYZED));

  doc add(new Field( duplicate Store YES Index NOT_ANALYZED));

  Document doc = new Document();

  doc add(new Field( id yaoyao Store YES Index NOT_ANALYZED));

  doc add(new Field( string haha Store YES Index NOT_ANALYZED));

  doc add(new Field( time Store YES Index NOT_ANALYZED));

  doc

   add(new Field( duplicate Store YES

  Index NOT_ANALYZED));

  Document doc = new Document();

  doc add(new Field( id zhangjian Store YES Index NOT_ANALYZED));

  doc add(new Field( string haha Store YES Index NOT_ANALYZED));

  doc add(new Field( time Store YES Index NOT_ANALYZED));

  doc

   add(new Field( duplicate Store YES

  Index NOT_ANALYZED));

  Document doc = new Document();

  doc add(new Field( id liweicheng Store YES Index NOT_ANALYZED));

  doc add(new Field( string haha Store YES Index NOT_ANALYZED));

  doc add(new Field( time Store YES Index NOT_ANALYZED));

  doc

   add(new Field( duplicate Store YES

  Index NOT_ANALYZED));

  try

  IndexWriter indexWriter = new IndexWriter(dir

  new StandardAnalyzer(Version LUCENE_ ) true

  MaxFieldLength LIMITED);

  indexWriter addDocument(doc);

  indexWriter addDocument(doc );

  indexWriter addDocument(doc );

  indexWriter addDocument(doc );

  indexWriter close();

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

  Filter filter = new DuplicateFilter( duplicate );

  IndexSearcher indexSearcher = new IndexSearcher(dir);

  TopDocs top = indexSearcher search(query filter );

  ScoreDoc[] scoreDocs = top scoreDocs;

  for (ScoreDoc scoreDoc : scoreDocs)

  Document rdoc = indexSearcher doc(scoreDoc doc);

  System out print( id: +rdoc get( id ) +   排重ID: +rdoc get( duplicate ));

  Query queryDuplicate = new TermQuery(new Term( duplicate rdoc get( duplicate )));

  System out println( 转载: + indexSearcher search(queryDuplicate ) totalHits

  );

  

   catch (CorruptIndexException e)

  e printStackTrace();

   catch (LockObtainFailedException e)

  e printStackTrace();

   catch (IOException e)

  // TODO Auto generated catch block

  e printStackTrace();

  

  

cha138/Article/program/Java/hx/201311/25714

相关参考