lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Spencer Tickner" <spencertick...@gmail.com>
Subject Extracting terms from a query splitting a phrase.
Date Tue, 05 Feb 2008 20:03:19 GMT
Hi List,

Thanks in advance for the help. I'm trying to extract terms from a
query. From the reading I've done a phrase such as "General Act" is
considered a term.
http://lucene.apache.org/java/docs/queryparsersyntax.html#Terms .
However when I'm doing testing to get the extractTerms of my query it
splits this into General and Act. I'm wondering if I'm missing or not
understanding something.

My test Java code is:

        private String FIELD_NAME = "rr_root";
        private Query query;
        private Hits hits = null;

	public void testSearch() throws Exception
	{
		doSearching("\"General Act\"");
		HashSet terms = new HashSet();
		query.extractTerms(terms);
		int i = 0;
		for (Iterator iter = terms.iterator(); iter.hasNext();)
		{
			i++;
			Term term = (Term)iter.next();
			System.out.println(i + " " + "term-" + term.text() + " field-" +
term.field());
		}
         }

	public void doSearching(String queryString) throws Exception
	{
		QueryParser parser=new QueryParser(FIELD_NAME, new WhitespaceAnalyzer());
		query = parser.parse(queryString);
		doSearching(query);
	}
	public void doSearching(Query unReWrittenQuery) throws Exception
	{
		searcher = aspect.getSearcher(); // searcher comming from a cahed class
		query=unReWrittenQuery.rewrite(aspect.getReader()); // reader
comming from a cached class
		System.out.println("Searching for: " + query.toString(FIELD_NAME));
		hits = searcher.search(query);
	}

The current output is:

Searching for: "General Act"
1 term-General field-rr_root
2 term-Act field-rr_root

The output I expect is:

Searching for: "General Act"
1 term-General Act field-rr_root

Thanks for any help.

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