lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Taylor <paul_t...@fastmail.fm>
Subject Re: How do you properly use NumericField
Date Mon, 12 Oct 2009 16:32:27 GMT
Uwe Schindler wrote:
> Can you print the upper and lower term or the term you received in
> newRangeQuery and newTermQuery also to System.out? Maybe it is converted
> somehow by your Analyzer, that is used for parsing the query.
>
> -----
> Uwe Schindler
> H.-H.-Meier-Allee 63, D-28213 Bremen
> http://www.thetaphi.de
> eMail: uwe@thetaphi.de
>
>   
Its okay I've given up on NumericField itself now but just use 
NumericUtils which isn't giving me the performance advantages but is 
working okay for what I want to do

So when indexing I do
doc.add(new Field(field.getName(), NumericUtils.intToPrefixCoded(val), 
Field.Store.YES, Field.Index.ANALYZED);


and my Query Parser looks like this:

public class MusicbrainzQueryParser extends QueryParser {

    public MusicbrainzQueryParser(String field, Analyzer a) {
        super(field, a);
    }

    protected Query newTermQuery(Term term) {
        if (
                (term.field() == TrackIndexField.DURATION.getName()) ||
                        (term.field() == 
TrackIndexField.QUANTIZED_DURATION.getName()) ||
                        (term.field() == 
TrackIndexField.TRACKNUM.getName()) ||
                        (term.field() == 
TrackIndexField.NUM_TRACKS.getName())
                ) {
            TermQuery tq = new TermQuery(new Term(term.field(), 
NumericUtils.intToPrefixCoded(Integer.parseInt(term.text()))));
            return tq;
        } else {
            return super.newTermQuery(term);
        }
    }

    public Query newRangeQuery(String field,
                               String part1,
                               String part2,
                               boolean inclusive) {

        if (
                (field.equals(TrackIndexField.DURATION.getName())) ||
                
(field.equals(TrackIndexField.QUANTIZED_DURATION.getName())) ||
                (field.equals(TrackIndexField.TRACKNUM.getName())) ||
                (field.equals(TrackIndexField.NUM_TRACKS.getName()))
            )
        {
            part1 = NumericUtils.intToPrefixCoded(Integer.parseInt(part1));
            part2 = NumericUtils.intToPrefixCoded(Integer.parseInt(part2));
        }
        TermRangeQuery query = (TermRangeQuery)
                super.newRangeQuery(field, part1, part2,inclusive);
        return query;
    }
}

and to display the value I use

String duration = doc.get(TrackIndexField.DURATION);
            if (duration != null) {
                
System.out.prinltn(BigInteger.valueOf(NumericUtils.prefixCodedToInt(duration)));
            }


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