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 DF52A10B2D for ; Tue, 10 Feb 2015 00:56:37 +0000 (UTC) Received: (qmail 48123 invoked by uid 500); 10 Feb 2015 00:56:36 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 48056 invoked by uid 500); 10 Feb 2015 00:56:36 -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 48034 invoked by uid 99); 10 Feb 2015 00:56:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Feb 2015 00:56:35 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of fogetti@gmail.com designates 209.85.217.174 as permitted sender) Received: from [209.85.217.174] (HELO mail-lb0-f174.google.com) (209.85.217.174) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Feb 2015 00:56:10 +0000 Received: by mail-lb0-f174.google.com with SMTP id f15so33260956lbj.5 for ; Mon, 09 Feb 2015 16:55:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=uYGoxprcw5hPt1FKgf67rFBeAfLy+SLY+4qU8lgSZvE=; b=zidJ7WojclXi7OFO8PXwNkg2fP8X613KwBrv9Qnos29r4HOd1ErpuWArxzvued/Jb1 k0eQqYdwKxRqDGrzBAU3XZ4F+HtMEYWJgASQdkrRpneRcfWTkRaItTBw8+ONhSkuX7ph JNPql4PCnE6L98cRcqcIHPB2O0rwz6AYXevg7Cz52jk8wa8urSi3HBC+zcllBfgKUv/7 ENE4fE6qPKY+cemgXr7zeUQI2B26n/na1zYHiIi6TTGlg8YNIlR27wfkS58CHcpO0Nc4 8laRtDNWkx9ku/phsaRXAGe2wrannVzpGShfzxW4eqhaprMauO1OpmI6gMzmJ+DncE1Z /w5A== MIME-Version: 1.0 X-Received: by 10.152.22.201 with SMTP id g9mr7149461laf.68.1423529723900; Mon, 09 Feb 2015 16:55:23 -0800 (PST) Received: by 10.25.168.141 with HTTP; Mon, 9 Feb 2015 16:55:23 -0800 (PST) In-Reply-To: References: Date: Tue, 10 Feb 2015 09:55:23 +0900 Message-ID: Subject: Re: Indexing and searching a DateTime range From: Gergely Nagy To: java-user@lucene.apache.org Content-Type: multipart/alternative; boundary=089e0158c308853695050eb157e8 X-Virus-Checked: Checked by ClamAV on apache.org --089e0158c308853695050eb157e8 Content-Type: text/plain; charset=UTF-8 Thank you Barry, I really appreciate your time to respond, Let me clarify this a little bit more. I think it was not clear. I know how to parse dates, this is not the question here. (See my previous email: "how can I pipe my converter logic into the indexing process?") All of your solutions guys would work fine if I wanted to index per-document. Which I do NOT want to do. What I would like to do to index per log line. I need to do a full text search, but with the additional requirement to filter those search hits by DateTime range. I hope this makes it clearer. So any suggestions how to do that? Sidenote: I saw that Alfresco implemented this analyzer, called DateTimeAnalyzer, but Alfresco is not open source. So I was wondering how to implement the same. Actually after wondering for 2 days, I became convinced that writing an Analyzer should be the way to go. I will post my solution later if I have a working code. 2015-02-10 8:50 GMT+09:00 Barry Coughlan : > Hi Gergely, > > Writing an analyzer would work but it is unnecessarily complicated. You > could just parse the date from the string in your input code and index it > in the LongField like this: > > SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S'Z'"); > format.setTimeZone(TimeZone.getTimeZone("UTC")); > long t = format.parse("2015-02-08 00:02:06.123Z INFO...").getTime(); > > Barry > > On Tue, Feb 10, 2015 at 12:21 AM, Gergely Nagy wrote: > > > Thank you for taking your time to respond Karthik, > > > > Can you show me an example how to convert DateTime to milliseconds? I > mean > > how can I pipe my converter logic into the indexing process? > > > > I suspect I need to write my own Analyzer/Tokenizer to achieve this. Is > > this correct? > > > > 2015-02-09 22:58 GMT+09:00 KARTHIK SHIVAKUMAR : > > > > > Hi > > > > > > Long time ago,.. I used to store datetime in millisecond . > > > > > > TermRangequery used to work in perfect condition.... > > > > > > Convert all datetime to millisecond and index the same. > > > > > > On search condition again convert datetime to millisecond and use > > > TermRangequery. > > > > > > With regards > > > Karthik > > > On Feb 9, 2015 1:24 PM, "Gergely Nagy" wrote: > > > > > > > Hi Lucene users, > > > > > > > > I am in the beginning of implementing a Lucene application which > would > > > > supposedly search through some log files. > > > > > > > > One of the requirements is to return results between a time range. > > Let's > > > > say these are two lines in a series of log files: > > > > 2015-02-08 00:02:06.852Z INFO... > > > > ... > > > > 2015-02-08 18:02:04.012Z INFO... > > > > > > > > Now I need to search for these lines and return all the text > > in-between. > > > I > > > > was using this demo application to build an index: > > > > > > > > > > > > > > http://lucene.apache.org/core/4_10_3/demo/src-html/org/apache/lucene/demo/IndexFiles.html > > > > > > > > After that my first thought was using a term range query like this: > > > > TermRangeQuery query = > > TermRangeQuery.newStringRange("contents", > > > > "2015-02-08 00:02:06.852Z", "2015-02-08 18:02:04.012Z", true, true); > > > > > > > > But for some reason this didn't return any results. > > > > > > > > Then I was Googling for a while how to solve this problem, but all > the > > > > datetime examples I found are searching based on a much simpler > field. > > > > Those examples usually use a field like this: > > > > doc.add(new LongField("modified", file.lastModified(), > Field.Store.NO > > )); > > > > > > > > So I was wondering, how can I index these log files to make a range > > query > > > > work on them? Any ideas? Maybe my approach is completely wrong. I am > > > still > > > > new to Lucene so any help is appreciated. > > > > > > > > Thank you. > > > > > > > > Gergely Nagy > > > > > > > > > > --089e0158c308853695050eb157e8--