lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sadronmeldir <sadronmel...@gmail.com>
Subject Search By Phrase Not Working
Date Thu, 08 Oct 2009 04:44:18 GMT

Hello all,

I'm having some difficult getting queries on phrases to work properly, and I
can't figure out why. For example, a search for ("Heart of Fire") yields no
results when it should be returning two. 

Below is a snippet of my code. I'm probably overlooking something trivial,
but any help would be appreciated!



==============START CODE SNIPET==============
String indexDir = "tmp";
StandardAnalyzer aWrapper = new StandardAnalyzer(Version.LUCENE_CURRENT);
IndexWriter writer = new IndexWriter(SimpleFSDirectory.open(new
File(indexDir)), aWrapper, true, IndexWriter.MaxFieldLength.UNLIMITED);

.
.
.

Document doc = new Document();
doc.add(new Field("year", Integer.toString(line.getYear()), Field.Store.YES,
Field.Index.ANALYZED));
doc.add(new Field("month", Integer.toString(line.getMonth()),
Field.Store.YES, Field.Index.ANALYZED));
doc.add(new Field("day", Integer.toString(line.getDay()), Field.Store.YES,
Field.Index.ANALYZED));
doc.add(new Field("hour", Integer.toString(line.getHour()), Field.Store.YES,
Field.Index.ANALYZED));
doc.add(new Field("minute", Integer.toString(line.getMinute()),
Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.add(new Field("second", Integer.toString(line.getSecond()),
Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.add(new Field("userID", line.getUserID(), Field.Store.YES,
Field.Index.ANALYZED));
doc.add(new Field("channelID", line.getChannelID(), Field.Store.YES,
Field.Index.ANALYZED));
doc.add(new Field("text", line.getText(), Field.Store.YES,
Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
doc.add(new Field("detail", line.getDetail(), Field.Store.YES,
Field.Index.NOT_ANALYZED));

writer.addDocument(doc);

.
.
.

writer.optimize();
writer.close();

IndexReader ir = IndexReader.open(SimpleFSDirectory.open(new
File(indexDir)), true);
IndexSearcher is = new IndexSearcher(ir);
Analyzer analyzera = new StandardAnalyzer(Version.LUCENE_CURRENT);

QueryParser parser = new QueryParser("text", analyzera);
PhraseQuery query = (PhraseQuery) parser.parse("\"Rain of Fire\"");

System.out.println("Query: " + query.toString());

TopFieldCollector collector = TopFieldCollector.create(sort, 100000, false,
false, false, false);
is.search(query, collector);
===============END CODE SNIPET===============
-- 
View this message in context: http://www.nabble.com/Search-By-Phrase-Not-Working-tp25798292p25798292.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message