Skip to content

Instantly share code, notes, and snippets.

@michail-nikolaev
Created September 9, 2012 22:35
Show Gist options
  • Save michail-nikolaev/3687728 to your computer and use it in GitHub Desktop.
Save michail-nikolaev/3687728 to your computer and use it in GitHub Desktop.
Java - Lucene in RAM - withpit tokenizer
RAMDirectory ramDirectory = new RAMDirectory();
Analyzer analyzer = new SimpleAnalyzer(Version.LUCENE_36);
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, analyzer);
int processed = 0;
try {
IndexWriter writer = new IndexWriter(ramDirectory, config);
writer.commit();
......
IndexReader reader = IndexReader.open(ramDirectory);
IndexSearcher searcher = new IndexSearcher(reader);
TopDocs docs = searcher.search(new FuzzyQuery(new Term(ALIAS, alias), 0.8f), 10);
if (docs.totalHits > 0) {
for (int q = 0; q < docs.scoreDocs.length; q++) {
String synonym = searcher.doc(docs.scoreDocs[q].doc).get(ALIAS);
......
Document document = new Document();
document.add(new Field(ALIAS, alias, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
writer.addDocument(document);
writer.commit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment