FAQ
Hi all.


I've been dealing with a small problem when searching and trying to sort
and filter on a NumericField using Lucene 2.9.2; the result never comes back
as expected. Here are some snippets of my code, so you might take a look and
reference me or help me out to solve this problem.


At document creation, I add the field like this:
doc.add(new NumericField("PuntosJobSense", Field.Store.YES,
false).setIntValue(Integer.parseInt(puntosJS)));

When searching, I use a sort field and a Filter:

SortField sf = new SortField("PuntosPatrocinadas", SortField.INT,
true);
Sort sortOrder = new Sort(sf);
Filter nf = NumericRangeFilter.newIntRange("PuntosPatrocinadas", 0,
Integer.MAX_VALUE, true, true);
hits = searcher.search(query, nf, MAX_DOC_SEARCH,
sortOrder).scoreDocs;

the only "query" parameter that I'm passing so far is "date modified" that
uses the date the document was added to the index. If I don't use this
search and simply search without filter nor sorting, everything is ok.

Hope someone can help me out.
Eduardo



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

Search Discussions

  • Uwe Schindler at Jul 6, 2010 at 6:31 pm
    Hi Eduardo,

    For sorting or a NumericRangeQuery, the field must be *indexed*. Storing has
    no effect at all, it's only needed, if you want to show the value in search
    results. That is important for *any* type of field (not only NumericField).

    Uwe

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

    -----Original Message-----
    From: Eduardo Pierdant
    Sent: Tuesday, July 06, 2010 7:49 PM
    To: java-user@lucene.apache.org
    Subject: Question: searching on a NumericField, with sort and filter


    Hi all.


    I've been dealing with a small problem when searching and trying to sort and
    filter on a NumericField using Lucene 2.9.2; the result never comes back as
    expected. Here are some snippets of my code, so you might take a look and
    reference me or help me out to solve this problem.


    At document creation, I add the field like this:
    doc.add(new NumericField("PuntosJobSense", Field.Store.YES,
    false).setIntValue(Integer.parseInt(puntosJS)));

    When searching, I use a sort field and a Filter:

    SortField sf = new SortField("PuntosPatrocinadas", SortField.INT,
    true);
    Sort sortOrder = new Sort(sf);
    Filter nf = NumericRangeFilter.newIntRange("PuntosPatrocinadas",
    0, Integer.MAX_VALUE, true, true);
    hits = searcher.search(query, nf, MAX_DOC_SEARCH,
    sortOrder).scoreDocs;

    the only "query" parameter that I'm passing so far is "date modified" that
    uses the date the document was added to the index. If I don't use this search
    and simply search without filter nor sorting, everything is ok.

    Hope someone can help me out.
    Eduardo



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


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Eduardo Pierdant at Jul 6, 2010 at 6:43 pm
    Works perfectly now, thx!

    -----Original Message-----
    From: Uwe Schindler
    Sent: martes, 06 de julio de 2010 01:31 p.m.
    To: java-user@lucene.apache.org
    Subject: RE: Question: searching on a NumericField, with sort and filter

    Hi Eduardo,

    For sorting or a NumericRangeQuery, the field must be *indexed*. Storing has
    no effect at all, it's only needed, if you want to show the value in search
    results. That is important for *any* type of field (not only NumericField).

    Uwe

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

    -----Original Message-----
    From: Eduardo Pierdant
    Sent: Tuesday, July 06, 2010 7:49 PM
    To: java-user@lucene.apache.org
    Subject: Question: searching on a NumericField, with sort and filter


    Hi all.


    I've been dealing with a small problem when searching and trying to
    sort and
    filter on a NumericField using Lucene 2.9.2; the result never comes
    back as
    expected. Here are some snippets of my code, so you might take a look
    and reference me or help me out to solve this problem.


    At document creation, I add the field like this:
    doc.add(new NumericField("PuntosJobSense", Field.Store.YES,
    false).setIntValue(Integer.parseInt(puntosJS)));

    When searching, I use a sort field and a Filter:

    SortField sf = new SortField("PuntosPatrocinadas", SortField.INT,
    true);
    Sort sortOrder = new Sort(sf);
    Filter nf = NumericRangeFilter.newIntRange("PuntosPatrocinadas",
    0, Integer.MAX_VALUE, true, true);
    hits = searcher.search(query, nf, MAX_DOC_SEARCH,
    sortOrder).scoreDocs;

    the only "query" parameter that I'm passing so far is "date modified"
    that uses the date the document was added to the index. If I don't use
    this search
    and simply search without filter nor sorting, everything is ok.

    Hope someone can help me out.
    Eduardo



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


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


    ---------------------------------------------------------------------
    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
postedJul 6, '10 at 5:49p
activeJul 6, '10 at 6:43p
posts3
users2
websitelucene.apache.org

2 users in discussion

Eduardo Pierdant: 2 posts Uwe Schindler: 1 post

People

Translate

site design / logo © 2022 Grokbase