Sorry, my mistake.  I glanced at your message and leapt to
the wrong conclusion.  Don't know what is wrong in your code
but since I had been meaning to get to grips with Date
searching in Lucene but had never made time to do so, have
knocked up a test program, attached to this message, which
creates a small index and searches on a few ranges, including
0 to 2008269714990, and it seems to work fine.  Perhaps it
may help you track down your problem.

If not, and you still want help, I suggest you post the
simplest possible program that demonstrates the problem.



--
Ian.
[EMAIL PROTECTED]



Jan Stövesand wrote:
> 
> Hi,
> 
> it is no typo. I thought that a DateFilter will return everything between
> "from" (0) and "to" (2008269714990), specified in the parameter list.
> 
> Jan
> 
> > -----Ursprüngliche Nachricht-----
> > Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]Im
> > Auftrag von Ian Lea
> > Gesendet: Freitag, 14. Dezember 2001 12:40
> > An: Lucene Users List
> > Betreff: Re: Can't get a DateFilter to work
> >
> >
> > Could be just a typo in the email message, but 1008269714990 !=
> > 2008269714990.
> >
> >
> > --
> > Ian.
> > [EMAIL PROTECTED]
> >
> > Jan Stövesand wrote:
> > >
> > > Hi,
> > >
> > > I really tried everything to get a DateFilter to work but I failed. :-(
> > >
> > > What I did was:
> > >
> > > Indexing:
> > >
> > > doc.add( Field.Keyword("last-modifed",
> > > DateField.timeToString( timeInMillies ) );
> > >
> > > e.g.
> > > millies: 1008269714990
> > > field value: 0cv6xr772
> > >
> > > If i submit a "normal" query, looking for 0cv6xr772 I find the
> > entry, i.e.
> > > the entry should be indexed correctly.
> > > If I search for a text in the body of the element I find about
> > 30 entries
> > > including the one mentioned above with last-midified=0cv6xr772.
> > >
> > > If I repeat the same query with
> > >
> > > DateFilter filter=new DateFilter("last-modified", 0, 2008269714990);
> > > Hits hits = searcher.search(query, filter);
> > >
> > > I do not get any results. What am I doing wrong?
> > > Any help appreciated.
> > >
> > > JAn
> >
> > --
import java.util.Date;
import org.apache.lucene.queryParser.*; 
import org.apache.lucene.search.*; 
import org.apache.lucene.index.*; 
import org.apache.lucene.analysis.*; 
import org.apache.lucene.analysis.standard.*;
import org.apache.lucene.document.*; 
import org.apache.lucene.store.*;

/** Simple program to play with DateFilter stuff.
 *
 *  To compile and run on unix, save to e.g. /tmp/LuceneDateTest.java and
 *  <pre>
 *   $ cd /tmp
 *   $ CLASSPATH=./:/some/where/lucene.jar; export CLASSPATH
 *   $ javac LuceneDateTest.java
 *   $ java LuceneDateTest
 *  </pre>
 *  
 *  Adjust as appropriate for other platforms.
 *
 *  Creates a RAMDirectory, adds some documents with dates and
 *    searches on date ranges.
 */


public class LuceneDateTest { 
    
    RAMDirectory ramdir;
    Analyzer analyzer;
    IndexWriter writer;
    IndexReader reader;
    Searcher searcher;
    Date start;
    Date middle;
    Date end;

    public LuceneDateTest() {
        analyzer = new StandardAnalyzer(); 
        ramdir = new RAMDirectory();
    }


    public static void main(String args[]) throws Exception { 
        LuceneDateTest ld = new LuceneDateTest();
        ld.load();
        ld.search();
    }
    
    
    void load() throws Exception {
        start = new Date();
        writer = new IndexWriter(ramdir, analyzer, true); 
        add("doc1");
        add("doc2");
        middle = new Date();
        add("doc3");
        add("doc4");
        writer.close();
        end = new Date();
    }   
    
    
    
    void add(String id) throws Exception {
        Document d = new Document();
        d.add(Field.Keyword("id", id));
        String lmod = DateField.timeToString(System.currentTimeMillis());
        String lmod2 = DateField.timeToString(1008269714990L);
        d.add(Field.Keyword("last-modified", lmod));
        d.add(Field.Keyword("last-mod2", lmod2));
        System.out.println("Adding id:"+id+
                           ", last-modified: "+lmod+
                           ", last-mod2: "+lmod2);
        writer.addDocument(d);
    }
    
    

    void search() throws Exception {
        reader = IndexReader.open(ramdir);
        searcher = new IndexSearcher(reader);
        
        DateFilter filter;
        Query query = QueryParser.parse("d*", "id", analyzer);
        
        filter = new DateFilter("last-modified",
                                start,
                                end);
        search(query, filter, "start to end (4): ");
        
        filter = new DateFilter("last-modified",
                                middle,
                                end);
        search(query, filter, "middle to end (2): ");

        filter = new DateFilter("last-modified",
                                0,
                                System.currentTimeMillis());
        search(query, filter, "0 to now (4): ");

        
        filter = new DateFilter("last-mod2",
                                0,
                                2008269714990L);
        search(query, filter, "0 to 2008269714990 (4): ");
    }


    void search(Query query, Filter filter, String s) throws Exception {
        Hits hits = searcher.search(query, filter);
        System.out.println(s+hits.length());
        for (int i = 0; i < hits.length(); i++) {
            System.out.println("    " + 
                               hits.doc(i).get("id") + " " +
                               hits.doc(i).get("last-modified")+" "+
                               hits.doc(i).get("last-mod2"));
        }
    }
}


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to