Home » Core Java » apache » Page 8

apache

Create Lucene Index

package com.javacodegeeks.lucene; import java.io.File; import java.io.FileReader; import java.io.IOException; import org.apache.lucene.analysis.SimpleAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.FSDirectory; public class SimpleFileIndexer { public static void main(String[] args) throws Exception { File indexDir = new File("C:/index/"); File dataDir = new File("C:/programs/eclipse/workspace/"); String suffix = "java"; SimpleFileIndexer indexer = new SimpleFileIndexer(); int numIndex = indexer.index(indexDir, dataDir, suffix); System.out.println("Total files indexed " + ...

Read More »

Did you mean feature with Apache Lucene Spell-Checker

package com.javacodegeeks.lucene.spellcheck; import java.io.File; import org.apache.lucene.search.spell.PlainTextDictionary; import org.apache.lucene.search.spell.SpellChecker; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; public class SimpleSuggestionService { public static void main(String[] args) throws Exception { File dir = new File("c:/spellchecker/"); Directory directory = FSDirectory.open(dir); SpellChecker spellChecker = new SpellChecker(directory); spellChecker.indexDictionary( new PlainTextDictionary(new File("c:/fulldictionary00.txt"))); String wordForSuggestions = "hwllo"; int suggestionsNumber = 5; String[] suggestions = spellChecker. suggestSimilar(wordForSuggestions, suggestionsNumber); if (suggestions!=null && suggestions.length>0) ...

Read More »