lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: PhraseQuery
Date Mon, 10 Oct 2016 19:43:47 GMT
PhraseQuery will not work against StringField: that field indexes the
entire string as a single token.

Try running it against the TextField instead?

Mike McCandless

http://blog.mikemccandless.com


On Wed, Oct 5, 2016 at 6:52 PM, lukes <mail2lokesh@gmail.com> wrote:
> Hi all,
>
>   I am trying to do phrase query search, but hitting into problem of not
> getting any results. Basically, i am indexing the document with some fields
> in it(String, Text, Numbers and so on). My basic queries are working, but
> when i am trying to do PhraseQueries i am not finding any results. I am
> using lucene 5.5.0 and below is my psuedo sample code, please let me know if
> i am missing something.
>
> // I am using standardAnalyzer;
> // index
> Document doc = new Document();
> String value = "iPod touch has leapt from the distant past—okay";
> doc.add(new StringField("summary_s",value , Field.Store.YES));
> doc.add(new TextField("summary_t", value, Field.Store.YES));
> indexWriter.addDocument(doc);
> indexWriter.commit();
>
>
> // search
> BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
> PhraseQuery.Builder builder = new PhraseQuery.Builder();
> mpq.add(new Term("summary_s", "leapt distant"));
> mpq.setSlop(10);
> builder.add(new Term("summary_s_en", "leapt distant"));
> booleanQuery.add(builder.build(), Occur.MUST)
>
> List<Query> cl = new ArrayList<Query>();
> cl.add(booleanQuery.build());
> DisjunctionMaxQuery mq = new DisjunctionMaxQuery(cl, 1);
> TopDocs topDocs = indexSearcher.search(mq, 10);
>
> Am i missing something ? Also for PhraseQuery, i should be querying against
> StringField, is my assumption right ?
>
> Regards.
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/PhraseQuery-tp4299871.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
>

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


Mime
View raw message