[
https://issues.apache.org/jira/browse/LUCENE-4673?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13548881#comment-13548881
]
Hoss Man commented on LUCENE-4673:
----------------------------------
I really don't understand why we completely eliminated the helpful javadoc that
tried to explain this to people back in the day (circa Lucene 2.9)...
{noformat}
/** Prints a query to a string, with <code>field</code> assumed to be the
* default field and omitted.
* <p>The representation used is one that is supposed to be readable
* by {@link org.apache.lucene.queryParser.QueryParser QueryParser}. However,
* there are the following limitations:
* <ul>
* <li>If the query was created by the parser, the printed
* representation may not be exactly what was parsed. For example,
* characters that need to be escaped will be represented without
* the required backslash.</li>
* <li>Some of the more complicated queries (e.g. span queries)
* don't have a representation that can be parsed by QueryParser.</li>
* </ul>
*/
public abstract String toString(String field);
{noformat}
...it wasn't perfect, but it could have been improved instead of deleted...
{noformat}
Prints a query to a string, with <code>field</code> assumed to be the default
field and omitted.
<p>The String representation generated is visually similar to that parsed by
{@link org.apache.lucene.queryParser.QueryParser QueryParser} for convinience,
however it is not guaranteed to produce an identical query object when parsed,
since not all permutations of Query objects can be created by the QueryParser.
{noformat}
> TermQuery.toString() doesn't play nicely with whitespace
> --------------------------------------------------------
>
> Key: LUCENE-4673
> URL: https://issues.apache.org/jira/browse/LUCENE-4673
> Project: Lucene - Core
> Issue Type: Bug
> Components: core/search
> Affects Versions: 4.0-BETA, 4.1, 3.6.2
> Reporter: Itamar Syn-Hershko
>
> A TermQuery where term.text() contains whitespace outputs incorrect string
> representation: field:foo bar instead of field:"foo bar". A "correct"
> representation is such that could be parsed again to the correct Query object
> (using the correct analyzer, yes, but still).
> This may not be so critical, but in our system we use Lucene's QP to parse
> and then pre-process and optimize user queries. To do that we use
> Query.toString on some clauses to rebuild the query string.
> This can be easily resolved by always adding quote marks before and after the
> term text in TermQuery.toString. Testing to see if they are required or not
> is too much work and TermQuery is ignorant of quote marks anyway.
> Some other scenarios which could benefit from this change is places where
> escaped characters are used, such as URLs.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
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]