lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Trejkaz <>
Subject Re: Recommendation for doing a search plus collecting extra information?
Date Wed, 28 Feb 2018 22:28:38 GMT
On Mon, Oct 12, 2015 at 3:28 PM, Uwe Schindler <> wrote:
> Hi,
> it may sound a bit stupid, but you can do the following:
> If you search for a docvalues (previously fieldcache) field in lucene, the returned TopFieldDocs
contains also the field values
> that were sorted against. The ScoreDoc instances in this collection are actually FieldDoc
instances (cast them down):
> So my suggestion would be: sort primarily against score (SortField.SCORE), but add a
secondary sort field with the docvalues
> field you want to be part of your results. The results will be primarily sorted against
the score so you should still get the results
> in right order, but you can have the docvalues field as part of your TopFieldDocs
> (
collections after downcasting
> the ScoreDoc to Fieldoc (the sorted fields are saved as Object[] instances). Choose the
second FieldDoc field and cast
> it to your data type.

Well, this solution was working fine for a long time, but now we have
some users crying about the additional memory usage.

We're using this sort field:

    private static final SortedNumericSortField ID_SORT_FIELD =
        new SortedNumericSortField(LuceneFields.ID.getName(),

Since the field isn't sorted anything I think I can now change it to just:

    private static final SortField ID_SORT_FIELD =
        new SortField(LuceneFields.ID.getName(), SortField.Type.LONG);

Either way it ends up creating a LongComparator, though, which seems
to be what is being complained about. The memory usage of
LongComparator seems totally fine to me and it's using what seems to
be the minimum storage for what it's doing, so it's not like it can be
improved, but maybe there is a way to make a comparator that doesn't
have to store a copy of the data in memory?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message