"Contains" query parsed to PrefixQuery

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

"Contains" query parsed to PrefixQuery

dontspamterry
Hi all,

I was experimenting with queries using wildcard on an untokenized field and noticed that a query with both a starting and trailing wildcard, e.g. *abc*, gets parsed to the PrefixQuery *abc. I did enable the leading wildcard in the QueryParser to allow the query above to be parsed so I'm wondering is there any way to get the query parser to parse *abc* as a WildcardQuery and not a PrefixQuery, short of overriding the applicable query parser methods? I don't think the parser treats every query with a trailing wildcard as a PrefixQuery because when I tried, a*b*, it got parsed to a WildcardQuery. Thanks for any insight!

-Terry
Reply | Threaded
Open this post in threaded view
|

Re: "Contains" query parsed to PrefixQuery

Chris Hostetter-3

: gets parsed to the PrefixQuery *abc. I did enable the leading wildcard in
: the QueryParser to allow the query above to be parsed so I'm wondering is

are you sure you called setAllowLeadingWildcard(true) first?

Are you using using 1.9 or earlier ... if so are you calling the
static parse(String,String,Analyzer) instance? it doesn't know anything
about hte other settings you can set on instances of QueryParser.


-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: "Contains" query parsed to PrefixQuery

dontspamterry
I'm using 2.1.0 and I'm calling setAllowLeadingWildcard(true) first on my QueryParser instance. I'm using a PerFieldAnalyzerWrapper where the field of interest uses the WhiteSpaceAnalyzer.

-Terry

hossman_lucene wrote
: gets parsed to the PrefixQuery *abc. I did enable the leading wildcard in
: the QueryParser to allow the query above to be parsed so I'm wondering is

are you sure you called setAllowLeadingWildcard(true) first?

Are you using using 1.9 or earlier ... if so are you calling the
static parse(String,String,Analyzer) instance? it doesn't know anything
about hte other settings you can set on instances of QueryParser.


-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Reply | Threaded
Open this post in threaded view
|

Re: "Contains" query parsed to PrefixQuery

Chris Hostetter-3

: I'm using 2.1.0 and I'm calling setAllowLeadingWildcard(true) first on my
: QueryParser instance. I'm using a PerFieldAnalyzerWrapper where the field of
: interest uses the WhiteSpaceAnalyzer.

could you send some code demonstrating the probelm you areseeing?  ideally
in the form of a small self contained JUnit test.




-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: "Contains" query parsed to PrefixQuery

dontspamterry
Here you go:

import junit.framework.TestCase;

import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.WildcardQuery;

public class WildcardQueryTest extends TestCase
{
        private QueryParser qp;
       
        protected void setUp() throws Exception
        {
                super.setUp();
               
                WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer();
                qp = new QueryParser("name", analyzer);
                qp.setAllowLeadingWildcard(true);
        }
       
        public void testContainsQuery() throws Exception
        {
                // Trailing wildcard parses to PrefixQuery
                String predicate = "name:Hom*";
                Query q = qp.parse(predicate);
                assertEquals(predicate + " parsed to PrefixQuery", PrefixQuery.class, q.getClass());
               
                // Leading wildcard parses to WildcardQuery
                predicate = "name:*omer";
                q = qp.parse(predicate);
                assertEquals(predicate + " parsed to WildcardQuery", WildcardQuery.class, q.getClass());
               
                // Middle wildcard parses to WildcardQuery
                predicate = "name:H*r";
                q = qp.parse(predicate);
                assertEquals(predicate + " parsed to WildcardQuery", WildcardQuery.class, q.getClass());
               
                // Leading and trailing wildcards parse to PrefixQuery
                predicate = "name:*om*";
                q = qp.parse(predicate);
                assertEquals(predicate + " parsed to PrefixQuery", PrefixQuery.class, q.getClass());
               
                // Leading and middle wildcards parse to WildcardQuery
                predicate = "name:*ar*e";
                q = qp.parse(predicate);
                assertEquals(predicate + " parsed to WildcardQuery", WildcardQuery.class, q.getClass());
               
                // Middle and trailing wildcards parse to WildcardQuery
                predicate = "name:ar*e*";
                q = qp.parse(predicate);
                assertEquals(predicate + " parsed to WildcardQuery", WildcardQuery.class, q.getClass());
        }
       
        protected void tearDown() throws Exception
        {
                super.tearDown();
        }
}


hossman_lucene wrote
: I'm using 2.1.0 and I'm calling setAllowLeadingWildcard(true) first on my
: QueryParser instance. I'm using a PerFieldAnalyzerWrapper where the field of
: interest uses the WhiteSpaceAnalyzer.

could you send some code demonstrating the probelm you areseeing?  ideally
in the form of a small self contained JUnit test.




-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
adb
Reply | Threaded
Open this post in threaded view
|

Re: "Contains" query parsed to PrefixQuery

adb
In reply to this post by dontspamterry
It's a bug in 2.1, fixed by Doron Cohen

http://issues.apache.org/jira/browse/LUCENE-813

Antony


dontspamterry wrote:

> Hi all,
>
> I was experimenting with queries using wildcard on an untokenized field and
> noticed that a query with both a starting and trailing wildcard, e.g. *abc*,
> gets parsed to the PrefixQuery *abc. I did enable the leading wildcard in
> the QueryParser to allow the query above to be parsed so I'm wondering is
> there any way to get the query parser to parse *abc* as a WildcardQuery and
> not a PrefixQuery, short of overriding the applicable query parser methods?
> I don't think the parser treats every query with a trailing wildcard as a
> PrefixQuery because when I tried, a*b*, it got parsed to a WildcardQuery.
> Thanks for any insight!
>
> -Terry


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]