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 "Agrawal, Aashish (IT)" <Aa...@morganstanley.com> on 2008/10/23 05:48:46 UTC

How to use regexQuery along with fuzzy logic capabilities

Hi, 
 
I want to use lucene for a simple search engine. If I use the code like
this, 
QueryParser parser = new QueryParser(field, analyzer);
Query query = parser.parse(line);
searcher.search(query) 
above code doesn't give me regular expression search power, while at the
other hand if I use the below code, 
RegexQuery rexquery = new RegexQuery(new Term(field, line));
searcher.search(rexquery)., 
I don't get the fuzzy logic and other search abilities which I get using
the analyzer.
 
I am not java expert, could you please give me a simple example on this
? 
 
thanks
Aashish Agrawal
--------------------------------------------------------

NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.

Re: example on RegexQuery

Posted by Erick Erickson <er...@gmail.com>.
query.toString() is your friend, as is Luke <G>. Two things are
often the problem here.
1> your index doesn't contain what you think it does. Luke helps a LOT here.
2> your regex isn't doing what you think, toString() whould help here

Best
Erick

On Sun, Oct 26, 2008 at 11:36 PM, Agrawal, Aashish (IT) <
Aashish.Agrawal@morganstanley.com> wrote:

> Hi Steven
>
> thanks for pointing to the example of RegexQuery.
>
> I have a simple code snippet which is not working, not sure if I am
> using it incorrectly.
> ----
>      RegexQuery query = new RegexQuery (new Term (field, line));
>      query.setRegexImplementation(new JavaUtilRegexCapabilities());
>      System.out.println("Searching for: " + query.toString(field));
>      Hits hits = searcher.search(query);
> --------
>
> I am searching a sample file like below -
> ---
> agrawal fdfdf
> fsdfafasf 3495549584
> fsfsfs fsffsf r4e3fdere j4343
> ---------
>
> when I search this file with pattern -
> .*4343*
> .*[a-z]4343
> j4343
> or even search for   3495549584
>
> all are failing with result no match found..
>
> could you point me what is wrong here ?? Also if I try to search *4343*,
> it throws exception,, shouldn't * at start be  allowed with regexQuery ?
>
>
> thanks
> Aashish Agrawal
>
> -----Original Message-----
> From: Steven A Rowe [mailto:sarowe@syr.edu]
> Sent: Saturday, October 25, 2008 12:31 AM
> To: java-user@lucene.apache.org
> Subject: RE: example on RegexQuery
>
> Hi Aashish,
>
> On 10/24/2008 at 3:35 AM, Agrawal, Aashish (IT) wrote:
> > I want to use lucene for a simple search engine  with regex support .
> > I tried using RegexQuery.. but seems I am missing something.
> > Is there any working exmaple on using RegexQuery ??
>
> How about TestRegexQuery?:
>
> <http://svn.apache.org/viewvc/lucene/java/tags/lucene_2_4_0/contrib/rege
> x/src/test/org/apache/lucene/search/regex/TestRegexQuery.java?view=marku<http://svn.apache.org/viewvc/lucene/java/tags/lucene_2_4_0/contrib/regex/src/test/org/apache/lucene/search/regex/TestRegexQuery.java?view=marku>
> p>
>
> Steve
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> --------------------------------------------------------
>
> NOTICE: If received in error, please destroy and notify sender. Sender does
> not intend to waive confidentiality or privilege. Use of this email is
> prohibited when received in error.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

RE: example on RegexQuery

Posted by Steven A Rowe <sa...@syr.edu>.
Hi Aashish,

On 10/26/2008 at 11:36 PM, Agrawal, Aashish (IT) wrote:
> I am searching a sample file like below -
> ---
> agrawal fdfdf
> fsdfafasf 3495549584
> fsfsfs fsffsf r4e3fdere j4343
> ---------
> 
> when I search this file with pattern -
> .*4343*
> .*[a-z]4343
> j4343
> or even search for   3495549584
> 
> all are failing with result no match found..

Have you tried searching for terms without digits, e.g. 'f(df)+'?  It is possible that the analyzer you're using at index time is not including digits.  As Erick suggested, look inside your index with Luke.

> Also if I try to search *4343*, it throws exception,,
> shouldn't * at start be allowed with regexQuery ?

In Java's regular expression language, '*' is a repeat operator, and must follow the regular expression to be repeated (like '.' or 'a' or '[a-z]') -- probably what you mean is: '.*4343.*'

Steve


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


RE: example on RegexQuery

Posted by "Agrawal, Aashish (IT)" <Aa...@morganstanley.com>.
Hi Steven

thanks for pointing to the example of RegexQuery. 

I have a simple code snippet which is not working, not sure if I am
using it incorrectly. 
----
      RegexQuery query = new RegexQuery (new Term (field, line)); 
      query.setRegexImplementation(new JavaUtilRegexCapabilities());
      System.out.println("Searching for: " + query.toString(field));
      Hits hits = searcher.search(query); 
--------

I am searching a sample file like below - 
---
agrawal fdfdf
fsdfafasf 3495549584
fsfsfs fsffsf r4e3fdere j4343  
---------

when I search this file with pattern - 
.*4343*
.*[a-z]4343
j4343
or even search for   3495549584

all are failing with result no match found..

could you point me what is wrong here ?? Also if I try to search *4343*,
it throws exception,, shouldn't * at start be  allowed with regexQuery ?


thanks
Aashish Agrawal

-----Original Message-----
From: Steven A Rowe [mailto:sarowe@syr.edu] 
Sent: Saturday, October 25, 2008 12:31 AM
To: java-user@lucene.apache.org
Subject: RE: example on RegexQuery 

Hi Aashish,

On 10/24/2008 at 3:35 AM, Agrawal, Aashish (IT) wrote:
> I want to use lucene for a simple search engine  with regex support .
> I tried using RegexQuery.. but seems I am missing something.
> Is there any working exmaple on using RegexQuery ??

How about TestRegexQuery?:

<http://svn.apache.org/viewvc/lucene/java/tags/lucene_2_4_0/contrib/rege
x/src/test/org/apache/lucene/search/regex/TestRegexQuery.java?view=marku
p>

Steve

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

NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.

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


RE: example on RegexQuery

Posted by Steven A Rowe <sa...@syr.edu>.
Hi Aashish,

On 10/24/2008 at 3:35 AM, Agrawal, Aashish (IT) wrote:
> I want to use lucene for a simple search engine  with regex support .
> I tried using RegexQuery.. but seems I am missing something.
> Is there any working exmaple on using RegexQuery ??

How about TestRegexQuery?:

<http://svn.apache.org/viewvc/lucene/java/tags/lucene_2_4_0/contrib/regex/src/test/org/apache/lucene/search/regex/TestRegexQuery.java?view=markup>

Steve

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


RE: example on RegexQuery

Posted by "Agrawal, Aashish (IT)" <Aa...@morganstanley.com>.
Hi, 
 
I want to use lucene for a simple search engine  with regex support .
I tried using RegexQuery.. but seems I am missing something.
Is there any working exmaple on using RegexQuery ??
 
thanks
Aashish Agrawal
--------------------------------------------------------

NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.

RE: How to use regexQuery along with fuzzy logic capabilities

Posted by "Agrawal, Aashish (IT)" <Aa...@morganstanley.com>.
any comments / help on this question ?
 
thanks, 
Aashish
 
 Hi, 
 
I want to use lucene for a simple search engine. If I use the code like
this, 
QueryParser parser = new QueryParser(field, analyzer);
Query query = parser.parse(line);
searcher.search(query) 
above code doesn't give me regular expression search power, while at the
other hand if I use the below code, 
RegexQuery rexquery = new RegexQuery(new Term(field, line));
searcher.search(rexquery)., 
I don't get the fuzzy logic and other search abilities which I get using
the analyzer.
 
I am not java expert, could you please give me a simple example on this
? 
 
thanks
Aashish Agrawal
--------------------------------------------------------

NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.

Re: How to use regexQuery along with fuzzy logic capabilities

Posted by Hasan Diwan <ha...@gmail.com>.
I seem to recall running the SimpleQueryParser first. If that throws an Exception, I then ran it with the RegexQueryParser with a reduced score. Hth
Sent via BlackBerry by AT&T

-----Original Message-----
From: "Agrawal, Aashish \(IT\)" <Aa...@morganstanley.com>

Date: Thu, 23 Oct 2008 12:48:46 
To: <ja...@lucene.apache.org>
Subject: How to use regexQuery along with fuzzy logic capabilities


Hi, 
 
I want to use lucene for a simple search engine. If I use the code like
this, 
QueryParser parser = new QueryParser(field, analyzer);
Query query = parser.parse(line);
searcher.search(query) 
above code doesn't give me regular expression search power, while at the
other hand if I use the below code, 
RegexQuery rexquery = new RegexQuery(new Term(field, line));
searcher.search(rexquery)., 
I don't get the fuzzy logic and other search abilities which I get using
the analyzer.
 
I am not java expert, could you please give me a simple example on this
? 
 
thanks
Aashish Agrawal
--------------------------------------------------------

NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.