Hi,I am checking a txt file with entries against an index generated with Lucene. Of the enclosed Searcher.java class, I use the isInLex(String noun) method, i.e. I read every line of the txt file and compare using isInLex(String noun) against the index. If it's contained it returns true otherwise it returns false.
The entire comparison is started from the enclosed Merger.java class. I read here (http://issues.apache.org/jira/browse/LUCENE-307?page=comments#action_12417477) and after that I tried to close the reader (is.close() in the Searcher.java class), but the problem persists.
I would be grateful for some tip as this is my first approach to Lucene... tia Pasquale
package lexicon; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.Directory; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.Hits; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.search.Query; public class Searcher { private final String INDEXDIR = "C:/luceneindex"; public boolean isInLex(String noun){ boolean found = false; try { Directory fsDir = FSDirectory.getDirectory(INDEXDIR, false); IndexSearcher is = new IndexSearcher(fsDir); QueryParser parser = new QueryParser("contents", new StandardAnalyzer()); Query query = parser.parse(noun); Hits hits = is.search(query); if (hits.length() >=1){ found = true; } } catch (Exception e){ System.err.println(e.getMessage()); } return found; } }
package lexicon; import java.io.*; import java.util.Vector; import lexicon.Searcher; import file.LineCounter; public class Merger { private Searcher s; private Vector v; private String to; public void merge (String from, String to){ this.to = to; String element; s = new Searcher(); v = new Vector(); try{ InputStreamReader isr = new InputStreamReader(new FileInputStream(from)); BufferedReader bf = new BufferedReader(isr); element = bf.readLine(); while (element != null){ if (!s.isInLex(element)){ v.add(element); } element = bf.readLine(); } } catch (Exception e){ System.err.print("Error: "+ e.getMessage()); System.exit(-1); } System.out.println(LineCounter.getNumberOfRows("C:/lexpool/NounsSenzaFreq.txt") + " lines in the Baroni file."); System.out.println(v.size() + " entries to be added."); //fillLexicon(v); } private void fillLexicon(Vector v){ //TODO: write a procedure that takes the vector and stores its content to disk } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]