Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to search a file with lucene
    primarykey
    data
    text
    <p>I want to do a search for a query within a file "fdictionary.txt" containing a list of words (230,000 words) written line by line. any suggestion why this code is not working? The spell checking part is working and gives me the list of suggestions (I limited the length of the list to 1). what I want to do is to search that fdictionary and if the word is already in there, do not call spell checking. My Search function is not working. It does not give me error! Here is what I have implemented:</p> <pre><code>public class SpellCorrection { public static File indexDir = new File("/../idxDir"); public static void main(String[] args) throws IOException, FileNotFoundException, CorruptIndexException, ParseException { Directory directory = FSDirectory.open(indexDir); SpellChecker spell = new SpellChecker(directory); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_20, null); File dictionary = new File("/../fdictionary00.txt"); spell.indexDictionary(new PlainTextDictionary(dictionary), config, true); String query = "red"; //kne, console String correctedQuery = query; //kne, console if (!search(directory, query)) { String[] suggestions = spell.suggestSimilar(query, 1); if (suggestions != null) {correctedQuery=suggestions[0];} } System.out.println("The Query was: "+query); System.out.println("The Corrected Query is: "+correctedQuery); } public static boolean search(Directory directory, String queryTerm) throws FileNotFoundException, CorruptIndexException, IOException, ParseException { boolean isIn = false; IndexReader indexReader = IndexReader.open(directory); IndexSearcher indexSearcher = new IndexSearcher(indexReader); Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_20); Term term = new Term(queryTerm); Query termQuery = new TermQuery(term); TopDocs hits = indexSearcher.search(termQuery, 100); System.out.println(hits.totalHits); if (hits.totalHits &gt; 0) { isIn = true; } return isIn; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload