SHARE
TWEET

Untitled

a guest Feb 21st, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. File index = new File("C:/MyIndex");
  2.     Directory indexDir = FSDirectory.open(index);
  3.     StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
  4.     IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, analyzer);
  5.     IndexWriter writer = new IndexWriter(indexDir, config);
  6.  
  7.     Document doc = new Document();
  8.     doc.add(new Field("My Data", Integer.toString(Id) , Field.Store.YES, Field.Index.NO));
  9.  
  10. indexDir.close();
  11.    
  12. File indexDir = new File("C:/CustomerInnovation");
  13.     Directory directory = FSDirectory.open(indexDir);
  14.     IndexReader reader = IndexReader.open(directory);
  15.     IndexSearcher searcher = new IndexSearcher(reader);
  16.     Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
  17.     QueryParser parser = new QueryParser(Version.LUCENE_36, " ", new StandardAnalyzer(Version.LUCENE_36));
  18.     Query query = parser.parse(searchQuery);
  19.     log.debug("searchQuery: " + searchQuery);
  20.     log.debug("query: " + query.toString());
  21.     int hits = 100;
  22.     int hitsPerPage = 10;
  23.     TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
  24.     searcher.search(query, collector);
  25.     int returned = collector.topDocs().totalHits;
  26.     log.debug("returned: " + returned);
  27.  
  28.     ScoreDoc[] numHits = collector.topDocs().scoreDocs;
  29.     List<Document> results = new ArrayList<Document>();
  30.  
  31.     for (int i = 0; i < numHits.length; i++) {
  32.         int docId = numHits[i].doc;
  33.         Document d = searcher.doc(docId);
  34.         results.add(d);
  35.         log.debug(d.get("customername"));
  36.     }
  37.  
  38.     log.debug("Found: " + numHits.length);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top