On Tue, Dec 16, 2014 at 3:25 PM, Piotr Idzikowski
<[email protected]> wrote:
> So for instance if I store documents with ie creation date and I have a
> data (millions of documents) from last let's say 3 years and I'd like to do
> range filter to get socs from some month only is it better to use ordinary
> numeric query instead of FieldCacheRangeQuery?
Yes.
>> Both FieldCacheRangeFilter and FieldCacheTermsFilter would work on the
>> same SortedDocValues field. What makes you think you need two fields ?
>>
> Code:
> FieldCacheRangeFilter
>
> *public static FieldCacheRangeFilter<Long> newLongRange(String field,
> FieldCache.LongParser parser, Long lowerVal, Long upperVal, boolean
> includeLower, boolean includeUpper) {*
> * return new FieldCacheRangeFilter<Long>(field, parser, lowerVal,
> upperVal, includeLower, includeUpper) {*
> * @Override*
> * public DocIdSet getDocIdSet(AtomicReaderContext context, Bits
> acceptDocs) throws IOException {*
> * final long inclusiveLowerPoint, inclusiveUpperPoint;*
> * if (lowerVal != null) {*
> * long i = lowerVal.longValue();*
> * if (!includeLower && i == Long.MAX_VALUE)*
> * return null;*
> * inclusiveLowerPoint = includeLower ? i : (i + 1L);*
> * } else {*
> * inclusiveLowerPoint = Long.MIN_VALUE;*
> * }*
> * if (upperVal != null) {*
> * long i = upperVal.longValue();*
> * if (!includeUpper && i == Long.MIN_VALUE)*
> * return null;*
> * inclusiveUpperPoint = includeUpper ? i : (i - 1L);*
> * } else {*
> * inclusiveUpperPoint = Long.MAX_VALUE;*
> * }*
>
> * if (inclusiveLowerPoint > inclusiveUpperPoint)*
> * return null;*
>
> * final FieldCache.Longs values =
> FieldCache.DEFAULT.getLongs(context.reader(), field,
> (FieldCache.LongParser) parser, false);*
> * return new FieldCacheDocIdSet(context.reader().maxDoc(),
> acceptDocs) {*
> * @Override*
> * protected boolean matchDoc(int doc) {*
> * final long value = values.get(doc);*
> * return value >= inclusiveLowerPoint && value <=
> inclusiveUpperPoint;*
> * }*
> * };*
> * }*
> * };*
> * }*
>
> FieldCacheTermsFilter:
>
> *@Override*
> * public DocIdSet getDocIdSet(AtomicReaderContext context, Bits
> acceptDocs) throws IOException {*
> * final SortedDocValues fcsi =
> getFieldCache().getTermsIndex(context.reader(), field);*
> * final FixedBitSet bits = new FixedBitSet(fcsi.getValueCount());*
> * for (int i=0;i<terms.length;i++) {*
> * int ord = fcsi.lookupTerm(terms[i]);*
> * if (ord >= 0) {*
> * bits.set(ord);*
> * }*
> * }*
The FieldCacheRangeFilter you copied is for longs indeed, but there is
also a newStringRange method that works on sorted doc values.
--
Adrien
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]