[
http://issues.apache.org/jira/browse/LUCENE-130?page=comments#action_12373847 ]
Nadav Har'El commented on LUCENE-130:
-------------------------------------
toString(field) works very well, if you understand what it does. Perhaps the
javadoc isn't explicit enough on what it does and need to be improved.
To the original poster (from two years ago...), here a short explanation.
toString() is meant to be somewhat like a reverse of QueryParser. When you
build a QueryParser, you give it a "default field" and a string query. Whenever
the QueryParser sees a term with no field on it (say, the word "dog") it uses
the default field as the field; If the default field name given to QueryParser
is "content", a query of "dog" is equivalent to searching for "content:dog".
Now, if you run toString() on that generated query the string you'll get is
"content:dog". This is ugly, because it adds a "content:" (the default field
name you gave QueryParser) to every term in your query. In order to remove this
default field name, toString() needs to know what it is, so you pass it as a
parameter. So toString("content") remove that field name, and leaves only "dog".
Now, down to business: the Javadoc currently says about toString(field):
"Prints a query to a string, with 'field' as the default field for terms."
I would have changed this to
"Prints a query to a string, with 'field' assumed to be the default field
and ommitted."
(or something like that).
> org.apache.lucene.search.Query.toString(String field) ignores it's only
> parameter
> ---------------------------------------------------------------------------------
>
> Key: LUCENE-130
> URL: http://issues.apache.org/jira/browse/LUCENE-130
> Project: Lucene - Java
> Type: Bug
> Components: Search
> Versions: unspecified
> Environment: Operating System: All
> Platform: PC
> Reporter: Mark Orr
> Assignee: Lucene Developers
> Priority: Minor
> Attachments: BugTest.java
>
> The JavaDoc says:
> "Prints a query to a string, with field as the default field for terms.
> The representation used is one that is readable by QueryParser (although, if
> the query was created by the parser, the printed representation may not be
> exactly what was parsed). "
> But as Far as I can tell it doesn't matter what you pass it. It returns the
> same thing if you had called toString()
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]