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: IllegalStateException in SpanTermQuery
Date Wed, 14 Aug 2013 14:18:02 GMT
OK I see why your test in 3.5 was passing: if you just run
SpanTermQuery alone, the hit count will be correct, because it never
needs to access positions (I suspect?).

Ie, a SpanTermQuery alone is like running TermQuery.

It's when SpanTermQuery is used inside other SpanQuerys that positions
will be needed, and your 3.5 should fail at that point.

Mike McCandless

http://blog.mikemccandless.com


On Wed, Aug 14, 2013 at 12:22 AM, Yonghui Zhao <zhaoyonghui@gmail.com> wrote:
> In our old code, we create the filed like this.
>
>                Field metaField = new Field(name,strVal,fldDef.store,
> Index.NOT_ANALYZED_NO_NORMS);
>                 metaField.setOmitNorms(true);
>                 *metaField.setIndexOptions(IndexOptions.DOCS_ONLY);*
>                 luceneDoc.add(metaField);
>
>
> The test case is quite simple, it only checks numhits.
>
>   public void testSpanTermQuery() throws Exception {
>     String req = "{\"query\":{\"span_term\":{\"color\":\"red\"}}}";
>     JSONObject res = search(new JSONObject(req));
>     assertEquals("numhits is wrong", 2160, res.getInt("numhits"));
>   }
>
> The query is interpreted to   "return new SpanTermQuery(new Term(field,
> spanterm));"
>
> In lucene 3.5 no exception is found and test is passed.
>
>
>
>
>
>
> 2013/8/13 Michael McCandless <lucene@mikemccandless.com>
>
>> All span queries require positions to work; older Lucene released
>> failed to catch you if you tried to use a span query on a field that
>> did not index positions, but now Lucene 4.x does catch you (this is an
>> improvement).
>>
>> You should double check your unit test: it really should not have been
>> passing in Lucene 3.5 if it did not index positions ...
>>
>> Mike McCandless
>>
>> http://blog.mikemccandless.com
>>
>>
>> On Tue, Aug 13, 2013 at 7:41 AM, Yonghui Zhao <zhaoyonghui@gmail.com>
>> wrote:
>> > One of my UT is passed In lucene 3.5, but it is failed in lucene4.3.
>> > The exception is:
>> >
>> > IllegalStateException("field \"" + term.field() + "\" was indexed without
>> > position data; cannot run SpanTermQuery (term=" + term.text() + ")");
>> >
>> >
>> > After I change index option of the field from DOCS_ONLY to
>> > DOCS_AND_FREQS_AND_POSITIONS, the test is passed.
>> >
>> > I am wondering what's the reason of this limit in lucene 4.3.
>> >
>> > Thanks
>>
>> ---------------------------------------------------------------------
>> 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