Mailing List Archive

SpanNearQuery for phrases
Hi all,

I want to compute the co-occurrence frequency of two phrases within a
certain distance.

I also get the information from the website that SpanNearQuery can also
implement this, and some snippet code as follow:



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);



But in my program the error "incompatible type " happened at the last line,
as phrB is an array, while phrA is only a common variable.



Any solution to problem? Or some other ways?



Best,

Allen
Re: SpanNearQuery for phrases [ In reply to ]
SpanQuery a = new SpanTermQuery...
SpanQuery b = new SpanTermQuery...

SpanNearQuery snq = new SpanNearQuery(new SpanQuery[]{a, b}, 20, false)

Or something like that. No need for the nested arrays.



On Nov 30, 2007, at 7:45 AM, fzsu wrote:

> Hi all,
>
> I want to compute the co-occurrence frequency of two phrases within a
> certain distance.
>
> I also get the information from the website that SpanNearQuery can
> also
> implement this, and some snippet code as follow:
>
>
>
> 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);
>
>
>
> But in my program the error "incompatible type " happened at the
> last line,
> as phrB is an array, while phrA is only a common variable.
>
>
>
> Any solution to problem? Or some other ways?
>
>
>
> Best,
>
> Allen
>
>
>

--------------------------
Grant Ingersoll
http://lucene.grantingersoll.com

Lucene Helpful Hints:
http://wiki.apache.org/lucene-java/BasicsOfPerformance
http://wiki.apache.org/lucene-java/LuceneFAQ