lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rahman Mukras" <rahman.muk...@googlemail.com>
Subject Re: Adding a PhraseQuery to a PhraseQuery
Date Wed, 23 May 2007 13:05:04 GMT
>
>
> > Hi all, I would like to add a PhraseQuery to a PhraseQuery so that
> > > I can be
> > > able to allow slop between phrases and terms. Something like:
> > >
> > > ----
> > > PhraseQuery mainPQ = new PhraseQuery();
> > > PhraseQuery subPQ   = new PhraseQuery();
> > >
> > > subPQ.add(new Term("contents","great"));
> > > subPQ.add(new Term("contents","actor"));
> > >
> > > mainPQ.add(subPQ);
> > > mainPQ.add(new Term("contents","Jean"));
> > > mainPQ.setSlop(20);
> >
> > You'll need to use SpanNearQuery instead.
> >
> >         Erik
> >
>
The following snippet did the trick

SpanQuery   phrA = new SpanTermQuery(new Term("contents","Jean"));
SpanQuery[] phrB = new SpanQuery[2];

phrB[0] = new SpanTermQuery(new Term("contents","great"));
phrB[1] = new SpanTermQuery(new Term("contents","actor"));

SpanNearQuery query=new SpanNearQuery(new SpanQuery[]{phrA,phrB},20,false);

Thanks,
Rahman.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message