FAQ
Hi,

I'm trying to sort results by a NumericField but the results do not sort
(still appear in default score order). The NumericField was indexed using
the code below:

NumericField field = new NumericField(name,
NumericUtils.PRECISION_STEP_DEFAULT, Field.Store.YES, false);
field.setIntValue(value);
document.add(field);

The searcher uses the following code to attempt to sort at search:

Sort sortBySize = new Sort(new SortField[] { new SortField("subj",
SortField.INT) });
TopFieldDocs topDocs = searcher.search(tq, null, limit, sortBySize);

Any ideas please? Is this the right method of sorting using a NumericField?

Az

Search Discussions

  • Ian Lea at Mar 25, 2011 at 2:34 pm

    From the javadoc for SortField: Fields must be indexed in order to
    sort by them.
    From the javadoc for NumericField:
    public NumericField(String name,
    int precisionStep,
    Field.Store store,
    boolean index)

    --
    Ian.

    P.S. Read the javadocs!

    On Fri, Mar 25, 2011 at 2:23 PM, Azhar Jassal wrote:
    Hi,

    I'm trying to sort results by a NumericField but the results do not sort
    (still appear in default score order). The NumericField was indexed using
    the code below:

    NumericField field = new NumericField(name,
    NumericUtils.PRECISION_STEP_DEFAULT, Field.Store.YES, false);
    field.setIntValue(value);
    document.add(field);

    The searcher uses the following code to attempt to sort at search:

    Sort sortBySize = new Sort(new SortField[] { new SortField("subj",
    SortField.INT) });
    TopFieldDocs topDocs = searcher.search(tq, null, limit, sortBySize);

    Any ideas please? Is this the right method of sorting using a NumericField?

    Az
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • 石玉明 at Mar 26, 2011 at 1:26 am
    NumericField include int float double ... and so on. but your sort uses SortField.int . Maybe that is the key point.
    -- newbie of Lucene


    2011-03-26



    石玉明



    发件人: Azhar Jassal
    发送时间: 2011-03-25 22:23:46
    收件人: java-user@lucene.apache.org
    抄送:
    主题: Sorting by NumericField not working

    Hi,

    I'm trying to sort results by a NumericField but the results do not sort
    (still appear in default score order). The NumericField was indexed using
    the code below:

    NumericField field = new NumericField(name,
    NumericUtils.PRECISION_STEP_DEFAULT, Field.Store.YES, false);
    field.setIntValue(value);
    document.add(field);

    The searcher uses the following code to attempt to sort at search:

    Sort sortBySize = new Sort(new SortField[] { new SortField("subj",
    SortField.INT) });
    TopFieldDocs topDocs = searcher.search(tq, null, limit, sortBySize);

    Any ideas please? Is this the right method of sorting using a NumericField?

    Az
  • Uwe Schindler at Mar 26, 2011 at 11:19 am
    Hi,

    No, the problem is easy: To sort against a field you have to index it. The
    field is only stored. Later versions of Lucene will complain, if the field
    is not indexed (as far as I remember, there was a commit about this). But
    currently it is sorting against nothing, so it will do the default order.

    Data types are correct from your code!

    Please note: If you want to use the field *only* for sorting, but no numeric
    range queries, then use Integer.MAX_VALUE as precisionStep, else you index
    unneeded terms and bloat your index (see JavaDocs for explanation).

    Uwe

    -----
    Uwe Schindler
    H.-H.-Meier-Allee 63, D-28213 Bremen
    http://www.thetaphi.de
    eMail: uwe@thetaphi.de

    -----Original Message-----
    From: 石玉明
    Sent: Saturday, March 26, 2011 2:26 AM
    To: java-user@lucene.apache.org
    Subject: Re: Sorting by NumericField not working

    NumericField include int float double ... and so on. but your sort uses
    SortField.int . Maybe that is the key point.
    -- newbie of Lucene


    2011-03-26



    石玉明



    发件人: Azhar Jassal
    发送时间: 2011-03-25 22:23:46
    收件人: java-user@lucene.apache.org
    抄送:
    主题: Sorting by NumericField not working

    Hi,

    I'm trying to sort results by a NumericField but the results do not sort
    (still appear in default score order). The NumericField was indexed using
    the code below:

    NumericField field = new NumericField(name,
    NumericUtils.PRECISION_STEP_DEFAULT, Field.Store.YES, false);
    field.setIntValue(value);
    document.add(field);

    The searcher uses the following code to attempt to sort at search:

    Sort sortBySize = new Sort(new SortField[] { new SortField("subj",
    SortField.INT) });
    TopFieldDocs topDocs = searcher.search(tq, null, limit, sortBySize);

    Any ideas please? Is this the right method of sorting using a
    NumericField?
    Az

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedMar 25, '11 at 2:23p
activeMar 26, '11 at 11:19a
posts4
users4
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase