On Wed, Nov 09, 2011 at 07:41:39PM +0200, goran kent wrote:
> On Mon, Nov 7, 2011 at 11:16 PM, Marvin Humphrey <[email protected]> 
> wrote:
> > The top_docs() method is where the search happens.  The results for a given
> > set of arguments should be deterministic for the life of a Searcher.
> 
> Just a quick positive note:  caching top_docs on all the search nodes
> works extremely well.  This simple approach gives us granular control
> over what's cached, and where (as opposed to a monolithic cache which
> is difficult to manage when it comes to refreshing views of indexes).

Thanks for passing that along!  I would not necessarily have thought to take
this approach, and we should remember that it worked out well when it comes
time to expose a caching API for our clustering support.

Brainstorming... perhaps SearchServer should offer a pluggable caching
mechanism for top_docs().... or maybe subclassing would work, so that there's
no need to monkey with the current implementation?

  package MySearchServer;
  use base qw( LucyX::Remote::SearchServer );

  ...

  sub top_docs {
      my ($self, %args) = @_;
      my $key = $args{num_wanted} . $args{query}->to_string;
      # Enable this when SortSpec gains a meaningful to_string() method.
      #$key .= $args{sort_spec}->to_string;
      my $result = $self->get_cache->lookup($key);
      if (!$result) {
          $result = $self->SUPER::top_docs(%args);
          $self->store_in_cache($key, $result);
      }
      return $result;
  }

That might make for a good Lucy::Docs::Cookbook entry.

Marvin Humphrey

Reply via email to