Hi Marvin,

Completely clear, both the solution as why Lucy can't offer it as a core feature. And good that you mentioned: generate always and only when you open a new searchindexer.

Thanx,
Arjan.


On 08/06/2012 08:53 PM, Marvin Humphrey wrote:
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


--
Met vriendelijke groet,
Arjan Widlak

Bezoek onze site op:
http://www.unitedknowledge.nl

United Knowledge, inhoud en techniek
Bilderdijkstraat 79N
1015 CT Amsterdam
T +31 (0)20 737 1851
F +31 (0)84 877 0399
[email protected]
http://www.unitedknowledge.nl

M +31 (0)6 2427 1444
E [email protected]

Reply via email to