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: How to get field names and types from an IndexSearcher
Date Fri, 01 Feb 2013 11:43:48 GMT
On Fri, Feb 1, 2013 at 3:17 AM, Rolf Veen <rolf.veen@gmail.com> wrote:
> On Thu, Jan 31, 2013 at 9:55 PM, Michael McCandless
> <lucene@mikemccandless.com> wrote:
>
>> But are you wanting to, eg, make a NumericRangeQuery if you detect the
>> field was indexed numerically, and otherwise a TermRangeQuery, or
>> something...?  (Not easy)
>
> This is what I want, yes. But I begin to understand that this is not possible
> without storing additional meta-data as neither the index nor the documents
> preserve the type info (correct me if I'm wrong). On the other hand, since once
> a field (name) has been typified (by auto-detection or a configuration file),
> in my case the field will maintain its type across documents and can thus
> be an index property. And since auto-detection is not very robust, I think I'll
> end needing a schema or type definition after all (field name to type mapping),
> which is not difficult to implement (or use Solr, I guess).

There is actually one way to check if a field was indexed numerically:
you can seek to the first term in the field, and attempt to parse it
as a long/float/etc., and if that throws a NumberFormatException, it
was indexed numerically.

Ie, numeric fields are indexed using the formats from
oal.util.NumericUtils, which will not parse as "normal" numbers.

This is what Lucene's FieldCache does to check how to decode numeric
values when uninverting ...

Mike McCandless

http://blog.mikemccandless.com

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