lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Spencer Tickner" <spencertick...@gmail.com>
Subject Phrase Search not returning results
Date Thu, 23 Aug 2007 19:04:50 GMT
Hi List,

Thanks in advance for the help. I'm creating a simple searching test
based on Query Parser and from what I've read it should have no
problems with a Phrase Search. However I can't seem to get any results
back.

I'm doing a simple index using the StandardAnalyzer. Output from the
indexing gives:
.......
 stored/uncompressed,indexed,tokenized<title:Auditor General Act>
......

I then have a simpleSearch class:

public class SimpleSearch {

	public Hits doSearch(String term, String field) throws IOException,
		CorruptIndexException, ParseException {
		FSDirectory directory = FSDirectory.getDirectory("<path_to_index>");
		IndexSearcher searcher = new IndexSearcher(directory);
		IndexReader reader;
		reader = IndexReader.open(directory);
		QueryParser parser = new QueryParser(field, new StandardAnalyzer());
		Query query =parser.parse(term);
		// Just a couple of tests to see if I can figure out what's going on
		System.out.println(query.toString() + "\n");
		System.out.println(query.rewrite(reader).toString() + "\n");
		return searcher.search(query);	
	}
	
	public static void main(String[] args) {
		SimpleSearch obj = new SimpleSearch();
		String strQuery = "Auditor General";
		Hits hits;
		try {
			hits = obj.doSearch(strQuery, "title");
		} catch (Exception e) {
			System.out.println("Error1: " + e.getMessage());
			return;
		}
		Document doc;
		for (int i = 0; i < hits.length(); i++) {
			
			try {
				doc = hits.doc(i);
			} catch (Exception e) {
				System.out.println("Error2: " + e.getMessage());
				return;
			}
			System.out.println(doc.get("title"));
		}
		
	}
}

When strQuery = "Auditor General" I get hits back as expected. However
when I change this to strQuery = "\"Auditor General\"" I get no
hits,,, and am confused. Anyone have any thoughts?

Thanks,

Spencer

---------------------------------------------------------------------
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