You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Brittany Jacobs <bj...@jbmanagement.com> on 2008/08/08 17:20:11 UTC
Need help searching
I want to search all the documents for a string.
So I have the following. But Hits isn't returning anything.
What am I doing wrong? Thanks in advance.
File f = new File("AddressData.txt");
IndexWriter writer;
try {
writer = new IndexWriter("C:\\", new StandardAnalyzer(), true);
FileInputStream fstream = new FileInputStream("AddressData.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
Document doc = new Document();
doc.add(new Field("filename", f.getCanonicalPath(), Field.Store.YES,
Field.Index.TOKENIZED));
doc.add(new Field("line", strLine, Field.Store.YES,
Field.Index.TOKENIZED));
writer.addDocument(doc);
}
in.close();
writer.close();
IndexSearcher iSearch = new IndexSearcher("C:\\");
Term term = new Term("line", "KOREA");
PhraseQuery query = new PhraseQuery();
query.add(term);
Hits hits = iSearch.search(query);
}
} catch (CorruptIndexException e) {
e.printStackTrace();
} catch (LockObtainFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
---
Brittany
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org