ctx.resultIds = [];
}
+ console.debug(`Search found ${result.count} and ` +
+ `returned ${result.ids.length} record IDs`);
+
result.ids.forEach((blob, idx) => ctx.addResultId(blob[0], idx));
}
ctx.currentResultIds(), ctx.searchOrg.id(), depth)
.pipe(map(summary => {
// Responses are not necessarily returned in request-ID order.
+ summary.record.id(Number(summary.record.id())); // ensure int
const idx = ctx.currentResultIds().indexOf(summary.record.id());
if (ctx.result.records) {
// May be reset when quickly navigating results.
use OpenILS::Utils::CStoreEditor q/:funcs/;
use OpenSRF::Utils::Cache;
use Encode;
+use OpenILS::Elastic::BibSearch;
use OpenSRF::Utils::Logger qw/:logger/;
$user_offset = ($user_offset >= 0) ? $user_offset : 0;
$user_limit = ($user_limit >= 0) ? $user_limit : 10;
+ # TODO TODO check settings/db to see if elasticsearch is
+ # enabled for bib-search.
+ return elastic_search($search_hash->{query}, $user_offset, $user_limit);
# we're grabbing results on a per-superpage basis, which means the
# limit and offset should coincide with superpage boundaries
return cache_facets($facet_key, $new_ids, $IAmMetabib, $ignore_facet_classes) if $docache;
}
+
+sub elastic_search {
+ my ($query, $offset, $limit) = @_;
+
+ # TODO visibility limits on holdings summaries
+ my ($site) = ($query =~ /site\(([^\)]+)\)/);
+ $query =~ s/site\(([^\)]+)\)//g;
+
+ my $elastic_query = {
+ _source => ['id'] , # return only the ID field
+# sort => [
+# {'title.raw' => 'asc'},
+# {'author.raw' => 'asc'},
+# '_score'
+# ],
+ size => $limit,
+ from => $offset,
+ query => {
+ bool => {
+ must => {
+ query_string => {
+ default_field => 'keyword',
+ query => $query
+ }
+ }
+ }
+ }
+ };
+
+ my $es = OpenILS::Elastic::BibSearch->new('main');
+ $es->connect;
+ my $results = $es->search($elastic_query);
+
+ return {count => 0} unless $results;
+
+ return {
+ count => $results->{hits}->{total},
+ ids => [
+ map { [$_->{_id}, undef, $_->{_score}] }
+ grep {defined $_} @{$results->{hits}->{hits}}
+ ]
+ };
+
+}
+
sub fetch_display_fields {
my $self = shift;
my $conn = shift;
use strict;
use warnings;
use DBI;
+use Time::HiRes qw/time/;
use OpenSRF::Utils::Logger qw/:logger/;
use OpenSRF::Utils::SettingsClient;
use OpenILS::Utils::CStoreEditor qw/:funcs/;
use Search::Elasticsearch;
-use Data::Dumper;
+use OpenSRF::Utils::JSON;
sub new {
my ($class, $cluster) = @_;
my ($self, $query) = @_;
my $result;
+ my $duration;
+
+ $logger->info("ES searching " . OpenSRF::Utils::JSON->perl2JSON($query));
eval {
+ my $start_time = time;
$result = $self->es->search(
index => $self->index_name,
body => $query
);
+ $duration = time - $start_time;
};
if ($@) {
$logger->error("ES search failed with $@");
- $logger->error("ES failed query: " . Dumper($query));
return undef;
}
+ $logger->info(
+ sprintf("ES search found %d results in %f seconds.",
+ $result->{hits}->{total}, substr($duration, 0, 6)
+ )
+ );
+
return $result;
}