On Mon, Aug 6, 2012 at 9:38 AM, arjan <[email protected]> wrote:
> If there is no way to retrieve this from the
> $searcher->hits object, it could be done by doing two queries, one with
> MatchAllQuery and the actual query. I just tried this (below) and that
> works. However, it's not ideal.
What you need is a value-to-ordinal mapping for the entire index on the field
"epoch".
my %val_to_ord_map;
my $sort_spec = Lucy::Search::SortSpec->new(
rules => [Lucy::Search::SortRule->new(field => 'epoch')],
);
my $ord = 0;
my $all_hits = $searcher->hits(
query => Lucy::Search::MatchAllQuery->new,
sort_spec => $sort_spec,
num_wanted => $searcher->doc_max,
);
while (my $hit = $all_hits->next) {
$val_to_ord_map{$hit->{epoch}} = $ord++;
}
...
my $hits = $searcher->hits(
query => $query,
sort_spec => $sort_spec,
);
while (my $hit = $hits->next) {
my $ord = $val_to_ord_map{$hit->{epoch}};
...
}
Such a mapping needs to be fully regenerated every time the index is changed,
because inserting a new value into the middle will cause many ordinals to
increase.
Lucy can't offer that as a core feature because regenerating full-index data
structures is at odds with fast incremental index updates. However, if you
don't need near-real-time responsiveness (and you can afford the RAM), you can
generate the map yourself each time you open a new IndexSearcher.
HTH,
Marvin Humphrey