You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by Laxmilal Menaria <lm...@chambal.com> on 2007/06/18 15:24:51 UTC

Phrase Search

Hello everyone,

I am lucene user and tried to implement pharse query, But now getting some
logical problems in searching..

My index have 4 fields: Name, Address &  City  and 6 docs.
i.e  1. "Laxmilal Menaria", "Hiran Magri", "Udaipur",
     2.  "Mohan Sharma", "Hiran Magri Sec 10", "Udaipur"
     3.  "Rohit Bhargav", "Suraj pole", "Udaipur"
     4.  "Laxmilal", "Hiran Magri Sec 4", "Ahemdabad"
     5.  "Chandresh" , "Bihar", "Patna"
     6.  "James", "Hiran Magri 18", "Delhi"

Now search Address:"Hiran Magri" and got 4 results, But  I want 1 result
only(Document-1), so what should I do ?

My Search code is :
                    sQuery="Hiran Magri"
                    .
                    .
                     Dim lucQuery As Lucene.Net.Search.Query  = New
Lucene.Net.QueryParsers.QueryParser("Address", New
Lucene.Net.Analysis.Standard.StandardAnalyzer).Parse(sQuery)
                    Dim lucHits As Lucene.Net.Search.Hits =
lucIndexSearcher.Search(lucQuery)
                    Dim intHitCount As Integer = lucHits.Length


-- 
Thanks,
Laxmilal menaria

http://www.minalyzer.com/
http://www.chambal.com/

Re: Phrase Search

Posted by Laxmilal Menaria <lm...@chambal.com>.
Ok.. thanks, I have tried to index address field as UN_TOKENIZED and search
using above query, its return Nothing, How can I specified " NOT tokenize"
in query..

--Thanks,

On 6/18/07, Erick Erickson <er...@gmail.com> wrote:
>
> Phrase queries won't help you here....
>
> Your particular issue can be addressed, but I'm not sure it's a
> reasonable long-term solution....
>
> If you indexed your address field as UN_TOKENIZED, and
> did NOT tokenize your query, it should give you what you want.
> What's happening is that StandardAnalyzer is indexing indivdual
> tokens, not phrases. So, doc 1 has the tokens
> "hiran", "margi"
>
> Doc 2 has tokens.
> "hiran", "magri", "sec", and "10"
>
> and so on...
>
> Searching, even for phrases, on "hiran margi" matches
> 4 docs because those two tokens appear next to each other.
>
> If, on the other hand, you index your address field UN_TOKENIZED,
> then doc1 has a "token" of "hiran margi", while doc 2 has a token
> of "hiran magri sec 10". Doc2 won't match a query on
> "hiran margi" etc.
>
> But, this may not be a good solution because searching on
> "hiran" won't match *any* document. You might have to index
> the same fields two different ways to get all the behavior you
> want.
>
> Best
> Erick
>
> On 6/18/07, Laxmilal Menaria <lm...@chambal.com> wrote:
> >
> > Hello everyone,
> >
> > I am lucene user and tried to implement pharse query, But now getting
> some
> > logical problems in searching..
> >
> > My index have 4 fields: Name, Address &  City  and 6 docs.
> > i.e  1. "Laxmilal Menaria", "Hiran Magri", "Udaipur",
> >      2.  "Mohan Sharma", "Hiran Magri Sec 10", "Udaipur"
> >      3.  "Rohit Bhargav", "Suraj pole", "Udaipur"
> >      4.  "Laxmilal", "Hiran Magri Sec 4", "Ahemdabad"
> >      5.  "Chandresh" , "Bihar", "Patna"
> >      6.  "James", "Hiran Magri 18", "Delhi"
> >
> > Now search Address:"Hiran Magri" and got 4 results, But  I want 1 result
> > only(Document-1), so what should I do ?
> >
> > My Search code is :
> >                     sQuery="Hiran Magri"
> >                     .
> >                     .
> >                      Dim lucQuery As Lucene.Net.Search.Query  = New
> > Lucene.Net.QueryParsers.QueryParser("Address", New
> > Lucene.Net.Analysis.Standard.StandardAnalyzer).Parse(sQuery)
> >                     Dim lucHits As Lucene.Net.Search.Hits =
> > lucIndexSearcher.Search(lucQuery)
> >                     Dim intHitCount As Integer = lucHits.Length
> >
> >
> > --
> > Thanks,
> > Laxmilal menaria
> >
> > http://www.minalyzer.com/
> > http://www.chambal.com/
> >
>



-- 
Thanks,
Laxmilal menaria

http://www.minalyzer.com/
http://www.chambal.com/

Re: Phrase Search

Posted by Chris Hostetter <ho...@fucit.org>.
: Another good old trick is to index field values (tokenized) with
: appended special starting and ending tokens, e.g. instead of "Hiran
: Magri" use "_start_ Hiran Magri _end_". Then you can query for fields
: that are exactly equal to a phrase, while still retaining the
: possibility to search by individual terms and phrases not equal to the
: field value.

or build a SpanNearQuery, and then put it inside a SpanFirst query
configured to be as long as the number of terms (+desired
slop) in the SpanNearQuery.


-Hoss


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


Re: Phrase Search

Posted by Andrzej Bialecki <ab...@getopt.org>.
Erick Erickson wrote:
> Phrase queries won't help you here....
> 
> Your particular issue can be addressed, but I'm not sure it's a
> reasonable long-term solution....
> 
> If you indexed your address field as UN_TOKENIZED, and
> did NOT tokenize your query, it should give you what you want.
> What's happening is that StandardAnalyzer is indexing indivdual
> tokens, not phrases. So, doc 1 has the tokens
> "hiran", "margi"
> 
> Doc 2 has tokens.
> "hiran", "magri", "sec", and "10"
> 
> and so on...
> 
> Searching, even for phrases, on "hiran margi" matches
> 4 docs because those two tokens appear next to each other.
> 
> If, on the other hand, you index your address field UN_TOKENIZED,
> then doc1 has a "token" of "hiran margi", while doc 2 has a token
> of "hiran magri sec 10". Doc2 won't match a query on
> "hiran margi" etc.
> 
> But, this may not be a good solution because searching on
> "hiran" won't match *any* document. You might have to index
> the same fields two different ways to get all the behavior you
> want.

Another good old trick is to index field values (tokenized) with 
appended special starting and ending tokens, e.g. instead of "Hiran 
Magri" use "_start_ Hiran Magri _end_". Then you can query for fields 
that are exactly equal to a phrase, while still retaining the 
possibility to search by individual terms and phrases not equal to the 
field value.


-- 
Best regards,
Andrzej Bialecki     <><
  ___. ___ ___ ___ _ _   __________________________________
[__ || __|__/|__||\/|  Information Retrieval, Semantic Web
___|||__||  \|  ||  |  Embedded Unix, System Integration
http://www.sigram.com  Contact: info at sigram dot com


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


Re: Phrase Search

Posted by Erick Erickson <er...@gmail.com>.
Phrase queries won't help you here....

Your particular issue can be addressed, but I'm not sure it's a
reasonable long-term solution....

If you indexed your address field as UN_TOKENIZED, and
did NOT tokenize your query, it should give you what you want.
What's happening is that StandardAnalyzer is indexing indivdual
tokens, not phrases. So, doc 1 has the tokens
"hiran", "margi"

Doc 2 has tokens.
"hiran", "magri", "sec", and "10"

and so on...

Searching, even for phrases, on "hiran margi" matches
4 docs because those two tokens appear next to each other.

If, on the other hand, you index your address field UN_TOKENIZED,
then doc1 has a "token" of "hiran margi", while doc 2 has a token
of "hiran magri sec 10". Doc2 won't match a query on
"hiran margi" etc.

But, this may not be a good solution because searching on
"hiran" won't match *any* document. You might have to index
the same fields two different ways to get all the behavior you
want.

Best
Erick

On 6/18/07, Laxmilal Menaria <lm...@chambal.com> wrote:
>
> Hello everyone,
>
> I am lucene user and tried to implement pharse query, But now getting some
> logical problems in searching..
>
> My index have 4 fields: Name, Address &  City  and 6 docs.
> i.e  1. "Laxmilal Menaria", "Hiran Magri", "Udaipur",
>      2.  "Mohan Sharma", "Hiran Magri Sec 10", "Udaipur"
>      3.  "Rohit Bhargav", "Suraj pole", "Udaipur"
>      4.  "Laxmilal", "Hiran Magri Sec 4", "Ahemdabad"
>      5.  "Chandresh" , "Bihar", "Patna"
>      6.  "James", "Hiran Magri 18", "Delhi"
>
> Now search Address:"Hiran Magri" and got 4 results, But  I want 1 result
> only(Document-1), so what should I do ?
>
> My Search code is :
>                     sQuery="Hiran Magri"
>                     .
>                     .
>                      Dim lucQuery As Lucene.Net.Search.Query  = New
> Lucene.Net.QueryParsers.QueryParser("Address", New
> Lucene.Net.Analysis.Standard.StandardAnalyzer).Parse(sQuery)
>                     Dim lucHits As Lucene.Net.Search.Hits =
> lucIndexSearcher.Search(lucQuery)
>                     Dim intHitCount As Integer = lucHits.Length
>
>
> --
> Thanks,
> Laxmilal menaria
>
> http://www.minalyzer.com/
> http://www.chambal.com/
>