What I am trying to do is to create the query based on the field in which user enters the keywords.

I have the following fields.

All the Words:
The Exact Phrase:
Any of the Words:

For All the words and Any of the words I am able to use Query. For The Exact Phrase I want to use the PhraseQuery. That is what I was showing in the code snippet. My mistake in not commenting out the line where I was per-pending and appending the quotation marks, which is taken care by the PhraseQuery. So how would one go about creating the different queries and then do the actual search.

Thanks.
-H

Erik Hatcher wrote:

On Jul 27, 2004, at 11:42 AM, Hetan Shah wrote:

Works for me.
Here is what I am striving to achieve.

phraseString =     request.getParameter("phrase");
if (phraseString.length() > 0){
    phraseQueryString = "\""+phraseString+("\"");
    phraseQuery = true;
    queryString = phraseQueryString;
}

if(phraseQuery){
    PhraseQuery pQuery = new PhraseQuery();
    pQuery.add(new Term("contents", phraseString));
    pQuery.setSlop(0);
    QueryParser qP = new QueryParser();
    query = qP.parse(phraseString);
}


I don't understand what you're attempting in the above. You don't make a new Term and add it to a PhraseQuery instance with the term having quotes around it - it is QueryParser that deals with quoted strings and interpreting it into a PhraseQuery.

Are you using pQuery? Or query? You've got two Query instances there - query is the one you probably want.

    Erik


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to