From: Bill Erickson Date: Thu, 12 Sep 2019 15:37:18 +0000 (-0400) Subject: query string runner X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=626c50a515d6850067820633188a7f2dcd66157b;p=working%2FEvergreen.git query string runner Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl b/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl index 1a8fb178e7..810167eda1 100755 --- a/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl +++ b/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl @@ -7,6 +7,10 @@ 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'; @@ -27,7 +31,7 @@ sub help { $0 - Performs a series of canned bib record searches + Performs query string searches. HELP exit(0); @@ -35,79 +39,8 @@ HELP help() if $help; -my $queries = [{ - - # Title search AND subject search AND MARC tag=100 search - bool => { - 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"; +print "Connecting to OpenSRF...\n"; OpenSRF::System->bootstrap_client(config_file => $osrf_config); Fieldmapper->import( IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); @@ -116,27 +49,57 @@ OpenILS::Utils::CStoreEditor::init(); my $es = OpenILS::Elastic::BibSearch->new($cluster); $es->connect; -print "Searching...\n"; -for my $query_part (@$queries) { +print <; + chomp $query_string if $query_string; + + next unless $query_string; my $query = { - _source => ['id', 'title|maintitle'] , # return only the ID field - from => 0, - size => 5, - sort => [{'_score' => 'desc'}], - query => $query_part + _source => ['id', 'title|maintitle'] , # return only a few fields + from => 0, + size => 10, + sort => [{'_score' => 'desc'}], + query => { + query_string => { + query => $query_string, + default_operator => 'AND', + # Combine scores for matched indexes + type => 'most_fields', + # Search all keyword text indexes by default. + default_field => 'keyword|keyword.text' + } + } }; - 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"; + + for my $hit (@{$results->{hits}->{hits}}) { + printf("Record: %-8d | Score: %-11f | Title: %s\n", + $hit->{_id}, $hit->{_score}, + $hit->{_source}->{'title|maintitle'} + ); + } }