Mailing List Archive

PhraseQuery
I was wondering if anyone out there had tried the PhraseQuery class and
retrieved the results. I'm new to the whole search solution. I have a
need to do a exact phrase search. Any code sample would be really
appreciated.

Thanks.
-H


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: PhraseQuery [ In reply to ]
On Jun 28, 2004, at 2:59 PM, Hetan Shah wrote:

> I was wondering if anyone out there had tried the PhraseQuery class
> and retrieved the results. I'm new to the whole search solution. I
> have a need to do a exact phrase search. Any code sample would be
> really appreciated.

PhraseQuery query = new PhraseQuery();

for (int i=0; i < words.length; i++) {
query.add(new Term("field", phrase[i]));
}

That builds a PhraseQuery from a String[] of words and will be an exact
match (unless you called setSlop with something greater than zero).

Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: PhraseQuery [ In reply to ]
Thank you very much Erik,

Also wanted to find out if it would be possible to use the highlighter
class or functionality with demo3 that is included in the distribution
of Lucene?

It would be really cool to see that functionality in action.

thanks.
-H

Erik Hatcher wrote:

>
> On Jun 28, 2004, at 2:59 PM, Hetan Shah wrote:
>
>> I was wondering if anyone out there had tried the PhraseQuery class
>> and retrieved the results. I'm new to the whole search solution. I
>> have a need to do a exact phrase search. Any code sample would be
>> really appreciated.
>
>
> PhraseQuery query = new PhraseQuery();
>
> for (int i=0; i < words.length; i++) {
> query.add(new Term("field", phrase[i]));
> }
>
> That builds a PhraseQuery from a String[] of words and will be an
> exact match (unless you called setSlop with something greater than zero).
>
> Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: PhraseQuery [ In reply to ]
On Mar 16, 2006, at 5:10 AM, Waleed Tayea wrote:
> I'm using the QueryParser to parse and return a query of a search
> string
> of a single word. But the analyzer I uses emits another morphological
> tokens from that single word. How can I prevent the QueryParser of
> considering the search query as a PhraseQuery with the terms of that
> single word search string and the other morphological tokens. I just
> want to make it return a BooleanQuery with Boolean clauses of all
> tokens, each one with its own as a TermQuery.

You will need to override this behavior by subclassing QueryParser
and overriding getFieldQuery to create the BooleanQuery yourself.

If the tokens are emitted in the same position (increment of 0) and
you're using Lucene 1.9.x it will work differently in this case than
1.4.3 did - positions were not taken into account in 1.4.3, but are
in the latest version.

Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: PhraseQuery [ In reply to ]
Thanks Mike. I discovered that earlier.

Regards.



--
View this message in context: http://lucene.472066.n3.nabble.com/PhraseQuery-tp4299871p4300752.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: PhraseQuery [ In reply to ]
Thanks for the quick responses, i was having a bug in my code such that
i was building multiple PhraseQuery's instead of one PhraseQuery in a loop.

Then i was losing order of terms.

Best regards

On 1/24/20 12:54 PM, Michael Froh wrote:
> Did you check the Javadoc for PhraseQuery.Builder?
>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lucene.apache.org_core_6-5F5-5F0_core_org_apache_lucene_search_PhraseQuery.Builder.html&d=DwIBaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=nlG5z5NcNdIbQAiX-BKNeyLlULCbaezrgocEvPhQkl4&m=IKZsplnvxeAys8KTpnZUR9To3moViZLv2LQHnuL4uHQ&s=mgj0lNuzP2IfQzWZHxdRe4UQQ-n-e8Yy5abEIS1Ieik&e=
>
> Checking the source code, I see that the add method that takes a position
> argument will throw an IllegalArgumentException if you try to add a Term in
> a lower position than the previous Term. (That is, Term positions must be
> non-decreasing.)
>
> Hope that helps,
> Michael
>
> On Fri, 24 Jan 2020 at 09:45, <baris.kazar@oracle.com> wrote:
>
>> Hi,-
>>
>> how do i enforce the order of sequence of terms in the PhraseQuery
>> builder?
>> Lucene docs are very hard to understand in terms of api descriptions.
>>
>>
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__lucene.apache.org_core_6-5F5-5F0_core_org_apache_lucene_search_PhraseQuery.html&d=DwIBaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=nlG5z5NcNdIbQAiX-BKNeyLlULCbaezrgocEvPhQkl4&m=IKZsplnvxeAys8KTpnZUR9To3moViZLv2LQHnuL4uHQ&s=8d1QBLJg0ltQqzGEk_Z40SzkBZsgdjglTrmyjnJ0rbs&e=
>> Best regards
>>
>>
>> ---------------------------------------------------------------------
>> 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
Re: PhraseQuery [ In reply to ]
Right, i am getting now expected behavior.

In the docs i wish the New York example would be continued for clarity
and consistence.

Best regards

On 1/24/20 12:55 PM, Atri Sharma wrote:
> PhraseQuery enforces the order of terms specified and needs an exact
> match of order of terms unless slop is specified.
>
> When appending terms, term pos numbers need to be incremental in the builder
>
> On Fri, Jan 24, 2020 at 11:15 PM <baris.kazar@oracle.com> wrote:
>> Hi,-
>>
>> how do i enforce the order of sequence of terms in the PhraseQuery
>> builder?
>> Lucene docs are very hard to understand in terms of api descriptions.
>>
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__lucene.apache.org_core_6-5F5-5F0_core_org_apache_lucene_search_PhraseQuery.html&d=DwIBaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=nlG5z5NcNdIbQAiX-BKNeyLlULCbaezrgocEvPhQkl4&m=YTrEhjB-AYQP02G-oZgBw_-nGgrpoQxRk-rj1LzC_7Y&s=tFhbvjjjKk_Ud5XffGASKin-cHtEGc5SRQ1NKqxSFuU&e=
>> Best regards
>>
>>
>> ---------------------------------------------------------------------
>> 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