You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Antony Bowesman <ad...@teamware.com> on 2007/02/25 22:40:57 UTC

QueryParser oddity with PrefixQuery

In certain cases, I use a modified QueryParser which does not allow "field:" 
syntax.  While testing variants of Prefix and Wildcard Query, I came across an 
oddity with getPrefixQuery().  The standard getPrefixQuery() (2.1) is given 
termStr without the trailing *, so the check

if (!allowLeadingWildcard && termStr.startsWith("*"))
   throw new ParseException("'*' not allowed as first character in PrefixQuery");

only triggers if you parse the String "**", in which case the PrefixQuery is 
then created with Term(field, "*"); whereas if you parse "*", getWildcardQuery() 
is called.

So it's not obvious that the test "termStr.startsWith("*"))" can ever occur, so 
this code seems redundant.

After Doron's latest patch http://issues.apache.org/jira/browse/LUCENE-813, if 
you parse "**" it now calls getWildcardQuery().

Antony



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


Re: QueryParser oddity with PrefixQuery

Posted by Doron Cohen <DO...@il.ibm.com>.
I agree, might be a redundant check now. This test was added when the query
parser was enhanced to optionally allow leading wild card (revision 468291
),
but this case calls getWildCardQuery(), not getPrefixQuery().

Still, the check seems harmless - sort of defensive - protecting against
the
case that a bug in query parser would identify such a query as prefix
rather
than wildcard (although this is not very likely.)

Doron

Antony Bowesman wrote:

> In certain cases, I use a modified QueryParser which does not allow
"field:"
> syntax.  While testing variants of Prefix and Wildcard Query, I
cameacross an
> oddity with getPrefixQuery().  The standard getPrefixQuery() (2.1) is
given
> termStr without the trailing *, so the check
>
> if (!allowLeadingWildcard && termStr.startsWith("*"))
>    throw new ParseException("'*' not allowed as first character in
> PrefixQuery");
>
> only triggers if you parse the String "**", in which case the PrefixQuery
is
> then created with Term(field, "*"); whereas if you parse "*",
> getWildcardQuery()
> is called.
>
> So it's not obvious that the test "termStr.startsWith("*"))" can
> ever occur, so
> this code seems redundant.
>
> After Doron's latest patch
http://issues.apache.org/jira/browse/LUCENE-813
> , if
> you parse "**" it now calls getWildcardQuery().
>
> Antony


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