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 Dave Seltzer <ds...@tveyes.com> on 2012/07/11 18:40:51 UTC

Lucene 3.5 Query Parser Question

Hello,

I'm interested in searching a MemoryIndex to find occurrences of HashTags.

To do this I'm trying to use the following query:
#* -#[0 TO 9]

My goal with this query is to look for any word starting with "#" except
for words like "#1".

However, when I parse this query, the query parser turns it into this:
+content:#* -content:# +content:[0 TO 9]

Effectively the QueryParser is splitting up the "#" and the "[0 TO 9]"

The same behavior occurs when I run this: #* -(#[0 TO 9])

Can anyone help me rewrite this query?

Thanks so much

-Dave

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


Re: Lucene 3.5 Query Parser Question

Posted by Ian Lea <ia...@gmail.com>.
I think you'll have to build the query up in code.  RegexQuery in the
contrib queries package should be able to take care of #[0-9].

BooleanQuery bq = new BooleanQuery();
PrefixQuery pq = new PrefixQuery(...) // #
RegexQuery rq = new RegexQuery(...) // #[0-9]
bq.add(pq, ....);
bq.add(rq, ...);

and search using bq.

Or you could extend QueryParser to produce the queries you need.  I'd
do it the first way.


--
Ian.


On Wed, Jul 11, 2012 at 5:40 PM, Dave Seltzer <ds...@tveyes.com> wrote:
> Hello,
>
> I'm interested in searching a MemoryIndex to find occurrences of HashTags.
>
> To do this I'm trying to use the following query:
> #* -#[0 TO 9]
>
> My goal with this query is to look for any word starting with "#" except
> for words like "#1".
>
> However, when I parse this query, the query parser turns it into this:
> +content:#* -content:# +content:[0 TO 9]
>
> Effectively the QueryParser is splitting up the "#" and the "[0 TO 9]"
>
> The same behavior occurs when I run this: #* -(#[0 TO 9])
>
> Can anyone help me rewrite this query?
>
> Thanks so much
>
> -Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>

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