Data-SearchEngine-Solr

 view release on metacpan or  search on metacpan

lib/Data/SearchEngine/Solr.pm  view on Meta::CPAN


            # Necessary to skip some of the non-hash pieces, like
            # correctlySpelled in the extended results
            next unless ref($data) eq 'HASH';

            if(exists($data->{origFreq})) {
                # Only present in the extended results
                $result->set_spell_frequency($sword, $data->{origFreq});
            }

            my $suggdata = $data->{suggestion};
            if(defined($suggdata) && ref($suggdata) eq 'ARRAY') {
                foreach my $sugg (@{ $suggdata }) {

                    if(ref($sugg) eq 'HASH') {
                        # This handles "extended results" from the spellcheck
                        # component...
                        $result->set_spell_suggestion($sugg->{word},
                            Data::SearchEngine::Results::Spellcheck::Suggestion->new(
                                original_word => $sword,
                                word        => $sugg->{word},
                                frequency   => $sugg->{freq}
                            )
                        );
                    } else {
                        # This handles non-"extended results" from the spellcheck
                        # component...
                        $result->set_spell_suggestion($sugg,
                            Data::SearchEngine::Results::Spellcheck::Suggestion->new(
                                original_word => $sword,
                                word    => $sugg,
                            )
                        );
                    }
                }
            }
        }
    }

    foreach my $doc ($resp->docs) {

        my %values;
        foreach my $fn ($doc->field_names) {
            my @n_values = $doc->values_for($fn);
            if (scalar(@n_values) > 1) {
                @{$values{$fn}} = @n_values;
            } else {
                $values{$fn} = $n_values[0];
            }
        }

        $result->add(Data::SearchEngine::Item->new(
            id      => $doc->value_for('id'),
            values  => \%values,
        ));
    }

    return $result;
}

sub update {
    my $self = shift;

    $self->add(@_);
}

1;



=pod

=head1 NAME

Data::SearchEngine::Solr

=head1 VERSION

version 0.20

=head1 SYNOPSIS

  my $solr = Data::SearchEngine::Solr->new(
    url => 'http://localhost:8983/solr',
    options => {
        fq => 'category:Foo',
        facets => 'true'
    }
  );

  my $query = Data::SearchEngine::Query->new(
    count => 10,
    page => 1,
    query => 'ice cream',
  );

  my $results = $solr->search($query);

  foreach my $item ($results->items) {
    print $item->get_value('name')."\n";
  }

=head1 DESCRIPTION

Data::SearchEngine::Solr is a L<Data::SearchEngine> backend for the Solr
search server.

=head1 NAME

Data::SearchEngine::Solr - Data::SearchEngine backend for Solr

=head1 SOLR FEATURES

=head2 FILTERS

This module uses the values from Data::SearchEngine::Query's C<filters> to
populate the C<fq> parameter.  Before talking to Solr we iterate over the
filters and add the filter's value to C<fq>.

  $query->filters->{'last name watson'} = 'last_name:watson';



( run in 0.569 second using v1.01-cache-2.11-cpan-df04353d9ac )