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 Arlei Ferreira Farnetani Junior <fa...@gmail.com> on 2013/03/12 01:45:37 UTC

Example phrase query with lucene version 4

Hello, could someone give me an example of how to conduct a search in an
already built index with Lucene 4 mode phrase query using a specific
analyzer. I tested here with the phrase the search query did not work, so would
appreciate a small example of how to pursue the example of a simple sentence in
a text, for example: The mouse gnawed the clothes of the king of Rome.

Re: Example phrase query with lucene version 4

Posted by Arlei Ferreira Farnetani Junior <fa...@gmail.com>.
In this case you are not using more search PhraseQuery the type that
existed in previous versions ... I would like to use this PhraseQuery by
having the possibility of bidding I use the property and thus enable
setSlop have more content between words.

So it is not recommended to use more Phrasequery?

I thought I had some syntax more this method in version 4 of lucene.

Example:

                PhraseQuery query = new PhraseQuery();
query.setSlop(slop);
for (int i = 0; i < phrase.length; i++) {
query.add(new Term("content", phrase[i]));
}
int hitsPerPage = 10000;
TopScoreDocCollector collector = TopScoreDocCollector.create(
5 * hitsPerPage, false);
indexSearcher.search(query, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
int hitCount = collector.getTotalHits();
                ....

2013/3/12 Ian Lea <ia...@gmail.com>

> QueryParser qp = new QueryParser(Version.whatever, "somefield", new
> WhateverAnalyzer());
> Query q = qp.parse("\"The mouse gnawed the clothes of the king of Rome\"");
>
> and q should be a PhraseQuery if I've got the quoting right.  Some of
> those words might be stop words which might cause you problems
> although probably not if you use the same analyzer and stop word list
> at indexing and search time.
>
> Search using q as you would for any other sort of query.
>
> See also
> http://wiki.apache.org/lucene-java/LuceneFAQ#Why_am_I_getting_no_hits_.2BAC8_incorrect_hits.3F
> .
>
>
> --
> Ian.
>
>
> On Tue, Mar 12, 2013 at 12:45 AM, Arlei Ferreira Farnetani Junior
> <fa...@gmail.com> wrote:
> > Hello, could someone give me an example of how to conduct a search in an
> > already built index with Lucene 4 mode phrase query using a specific
> > analyzer. I tested here with the phrase the search query did not work,
> so would
> > appreciate a small example of how to pursue the example of a simple
> sentence in
> > a text, for example: The mouse gnawed the clothes of the king of Rome.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>


--

Re: Example phrase query with lucene version 4

Posted by Ian Lea <ia...@gmail.com>.
QueryParser qp = new QueryParser(Version.whatever, "somefield", new
WhateverAnalyzer());
Query q = qp.parse("\"The mouse gnawed the clothes of the king of Rome\"");

and q should be a PhraseQuery if I've got the quoting right.  Some of
those words might be stop words which might cause you problems
although probably not if you use the same analyzer and stop word list
at indexing and search time.

Search using q as you would for any other sort of query.

See also http://wiki.apache.org/lucene-java/LuceneFAQ#Why_am_I_getting_no_hits_.2BAC8_incorrect_hits.3F.


--
Ian.


On Tue, Mar 12, 2013 at 12:45 AM, Arlei Ferreira Farnetani Junior
<fa...@gmail.com> wrote:
> Hello, could someone give me an example of how to conduct a search in an
> already built index with Lucene 4 mode phrase query using a specific
> analyzer. I tested here with the phrase the search query did not work, so would
> appreciate a small example of how to pursue the example of a simple sentence in
> a text, for example: The mouse gnawed the clothes of the king of Rome.

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