From: Bill Erickson Date: Thu, 12 Sep 2019 15:36:07 +0000 (-0400) Subject: Rename; add utf8 bits X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7d8356360b1d6be601c37185946f43828e947ff2;p=working%2FEvergreen.git Rename; add utf8 bits Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/support-scripts/test-scripts/elastic-search-samples.pl b/Open-ILS/src/support-scripts/test-scripts/elastic-search-samples.pl new file mode 100755 index 0000000000..6eb3501b52 --- /dev/null +++ b/Open-ILS/src/support-scripts/test-scripts/elastic-search-samples.pl @@ -0,0 +1,146 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Getopt::Long; +use Time::HiRes qw/time/; +use OpenSRF::Utils::JSON; +use OpenILS::Utils::Fieldmapper; +use OpenILS::Elastic::BibSearch; + +use utf8; +binmode(STDIN, ':utf8'); +binmode(STDOUT, ':utf8'); + +my $help; +my $osrf_config = '/openils/conf/opensrf_core.xml'; +my $cluster = 'main'; +my $index = 'bib-search'; +my $quiet = 0; +my $query_string; + +GetOptions( + 'help' => \$help, + 'osrf-config=s' => \$osrf_config, + 'cluster=s' => \$cluster, + 'quiet' => \$quiet, +) || die "\nSee --help for more\n"; + +sub help { + print < { + must => [{ + multi_match => { + query => 'ready', + fields => ['title|*.text*'], + operator => 'and', + type => 'most_fields' + } + }, { + multi_match => { + query => 'puzzle', + fields => ['subject|*.text*'], + operator => 'and', + type => 'most_fields' + } + }, { + nested => { + path => 'marc', + query => { + bool => { + must => [{ + multi_match => { + query => 'cline', + fields => ['marc.value*'], + operator => 'and', + type => 'most_fields' + } + }, { + term => {'marc.tag' => 100} + }] + } + } + } + }] + } +}, { + # Author search + bool => { + must => [{ + multi_match => { + query => 'Cuthbert Morton Girdlestone', + fields => ['author|*text*'], + operator => 'and', + type => 'most_fields' + } + }] + } +}, { + # Personal author exact match search + bool => { + must => [{ + term => {'author|personal' => 'Rowling, J. K.'} + }] + } +}, { + # Main title search + bool => { + must => [{ + multi_match => { + query => 'ready player', + fields => ['title|maintitle.text*'], + operator => 'and', + type => 'most_fields' + } + }] + } +}]; + +# connect to osrf... +print "Connecting...\n"; +OpenSRF::System->bootstrap_client(config_file => $osrf_config); +Fieldmapper->import( + IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); +OpenILS::Utils::CStoreEditor::init(); + +my $es = OpenILS::Elastic::BibSearch->new($cluster); +$es->connect; + +print "Searching...\n"; +for my $query_part (@$queries) { + + my $query = { + _source => ['id', 'title|maintitle'] , # return only the ID field + from => 0, + size => 5, + sort => [{'_score' => 'desc'}], + query => $query_part + }; + + print OpenSRF::Utils::JSON->perl2JSON($query) . "\n\n" unless $quiet; + + my $start = time(); + my $results = $es->search($query); + my $duration = substr(time() - $start, 0, 6); + + print OpenSRF::Utils::JSON->perl2JSON($results) . "\n\n" unless $quiet; + + print "Search returned ".$results->{hits}->{total}. + " hits with a reported duration of ".$results->{took}."ms.\n"; + print "Full round-trip time was $duration seconds.\n\n"; +} +