Return-Path: X-Original-To: apmail-lucene-java-user-archive@www.apache.org Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D28A810039 for ; Tue, 16 Dec 2014 17:21:21 +0000 (UTC) Received: (qmail 15864 invoked by uid 500); 16 Dec 2014 17:21:12 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 15803 invoked by uid 500); 16 Dec 2014 17:21:12 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 15790 invoked by uid 99); 16 Dec 2014 17:21:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Dec 2014 17:21:11 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jpountz@gmail.com designates 209.85.217.180 as permitted sender) Received: from [209.85.217.180] (HELO mail-lb0-f180.google.com) (209.85.217.180) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Dec 2014 17:21:06 +0000 Received: by mail-lb0-f180.google.com with SMTP id l4so11114052lbv.25 for ; Tue, 16 Dec 2014 09:18:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=d5pPCfW3At2+N3AIgBXivtKNyjSpNE0L88McvqzpPvI=; b=uAoTiyq3rG1qwLzCpoLJXIZsD8L48upRUJNrPd8003VSwlU2pgFe5omNh7TelbjLto OszXoh/b1rJFxJ10PZRtSfoNUP52lwK1cnfA2J5vUboefIrhS+VHl6DnXOcVXHK9Bl9v M1TF8Og/3Zej9iGGkTbGUUF7kOIfpzvv3rxyHaDwm8JGvwAA7hIxm45jcOLBleiDWHWp YYjQYgSnQ2/rSKBI60Rg0vaHcaJQWBimv1XEe6jfYVnYo/Y86yDO8EH2POiLmahmMWSk BKgmN8j8i2bOLIuWcbStpqo+aJG/4C2mQQITE7tqbljTfdXMpwuZ2cOrBqp/KKjLN8Gl tfSg== X-Received: by 10.112.156.169 with SMTP id wf9mr36640591lbb.85.1418750310026; Tue, 16 Dec 2014 09:18:30 -0800 (PST) MIME-Version: 1.0 Received: by 10.112.83.5 with HTTP; Tue, 16 Dec 2014 09:18:09 -0800 (PST) In-Reply-To: References: From: Adrien Grand Date: Tue, 16 Dec 2014 18:18:09 +0100 Message-ID: Subject: Re: Lucene DocValuesField, SortedDocValuesField usage for filtering and sorting To: java-user@lucene.apache.org Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked by ClamAV on apache.org On Tue, Dec 16, 2014 at 3:25 PM, Piotr Idzikowski 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 newLongRange(String field, > FieldCache.LongParser parser, Long lowerVal, Long upperVal, boolean > includeLower, boolean includeUpper) {* > * return new FieldCacheRangeFilter(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 * 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: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org