Skip to main content.
home | support | download

Back to List Archive

Re: [swish-e] faceted search feature in Swish3

From: Peter Karman <peter(at)not-real.peknet.com>
Date: Mon Oct 12 2009 - 18:32:58 GMT
Thomas den Braber wrote on 10/12/2009 01:07 PM:
> Peter,
> 
> Great, just what I am looking for !
> Is there also an option to limit to the x most popululair values? 

Not in the swish_xapian tool. swish_xapian is just a development tool 
and example of how to use libswish3 with xapian. The current 
implementation does not sort or limit the facets. That's up to the user. 
swish_xapian just dumps the facets to stdout, much like it does the 
search results. It's a command-line tool anyway, so for things like the 
web you'd want to use the xapian bindings directly.

If you are using swish_xapian you're most likely using it for indexing, 
and then searching using one of the native bindings for xapian. You can 
implement the FacetFinder in the calling code of your bindings. The 
xapian feature is the MatchDecider (or if you are using the 1.1.x xapian 
devel branch, the MatchSpy).

As soon as I can figure out how to package SWISH::3 for cpan, there will 
be a SWISH::Prog::Xapian implementation that has the faceted search 
feature using the Perl bindings of Search::Xapian. Then you'll be able 
to do something close to:

  my $searcher = SWISH::Prog::Xapian::Searcher->new();
  my $results  = $searcher->search(
      'foo or bar',
      facets => [qw( color )]
  );
  while ( my $result = $results->next ) {
     printf("hit: %s\n", $result->swishtitle);
  }
  my $facets = $results->facets_for('color')->sort_by_count;
  for my $color (@$facets) {
      printf("color: %s (%d)\n", $color->str, $color->count);
  }

I wrote a faceted search server with Search::Xapian last week in just a 
few hours. It's a very nice API, imo. My facet-building code looks like:

     my %facets;
     my @facet_names = qw( color size magiclove );
     # prop_ids are defined in swish.xml header in index dir.
     # real code just reads that file.
     my %prop_ids = ( color => 10, size => 11, magiclove => 12 );
     $matches = $enq->get_mset( 

         $offset, $size, 

         sub { 

             my ($doc) = @_; 

             for my $facet (@facet_names) { 

 

                 # \003 is the SWISH_TOKENPOS_BUMPER 

                 # that delineates multiple values 

                 for my $value ( 

                    split( /\003/, $doc->get_value( $prop_ids{$facet} ) 
)
                 ) 

                 { 

                     $facets{$facet}->{$value}++; 

                 } 

             } 

             return $doc; 

         } 

     );
 

> 
> If you look on the photo site from gettyimages.com you have something like
> that, it shows all popular properties found in the search results and I
> would love to have that in my application.

yes, that's the idea of faceted search.

-- 
Peter Karman  .  http://peknet.com/  .  peter(at)not-real.peknet.com
_______________________________________________
Users mailing list
Users@lists.swish-e.org
http://lists.swish-e.org/listinfo/users
Received on Mon Oct 12 14:33:03 2009