Each Query object has getter methods for each of its fields. If a field is a nested Query object, you will then have to recursively process it. Be prepared to do lots of "instanceof" conditionals. None of this is hard, just lots of dog work. Consult the Javadoc for the getter methods.

And when you write your instanceof conditionals, be sure to include an "else" that displays the actual class name so that you can then add yet another instanceof.

Now, what you are really looking for is the TermQuery, that has a field name - that's what you want to change.

After you have called all of the getters, you create a new Query object of the current type (the type you referenced in the "instanceof") and return that new Query object. Recursion would return the new Query object.

-- Jack Krupansky

-----Original Message----- From: Puneet Pawaia
Sent: Saturday, July 06, 2013 12:54 PM
To: java-user@lucene.apache.org
Subject: Re: Forcing lucene to use specific field when processing parsed query

Hi Uwe
Unfortunately, at the stage I am required to do this,  I do not have the
query text. I only have the parsed query.
I thought of iterating through the query clauses etc but could not find how
to. What function allows me to do this ?
Regards
Puneet Pawaia
On 6 Jul 2013 20:06, "Uwe Schindler" <u...@thetaphi.de> wrote:

Hi,

You can only do this manually with instanceof checks and walking through
BooleanClauses.

The better way to fix your problem would be to change your query parser,
e.g. by overriding getFieldQuery and other protected methods to enforce a
specific field while parsing the query string.

Uwe



Puneet Pawaia <puneet.paw...@gmail.com> schrieb:
>Hi all,
>
>I am using Lucene.Net 3.0.3 and need to search in a specific field
>(ignoring any fields specified in the query). I am given a parsed
>Lucene
>Query so I am unable to generate a parsed query with my required field.
>
>Is there any functionality in Lucene that allows me to loop through the
>terms of the query and change the field ? The given query would be a
>complex query where there would be spans, clauses etc.
>
>Or perhaps there is some way of forcing Lucene to ignore the fields
>given
>in the parsed query and used a specified field only.
>
>Any help would be most appreciated.
>
>Regards
>Puneet Pawaia

--
Uwe Schindler
H.-H.-Meier-Allee 63, 28213 Bremen
http://www.thetaphi.de


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

Reply via email to