return cache_facets($facet_key, $new_ids, $IAmMetabib, $ignore_facet_classes) if $docache;
}
-sub passthrough_fetch_display_fields {
+sub fetch_display_fields {
my $self = shift;
my $conn = shift;
my $highlight_map = shift;
my @records = @_;
- return $U->storagereq(
- 'open-ils.storage.fetch.metabib.display_field.highlight',
- $highlight_map,
- @records
- ) if (@records == 1);
+ unless (@records) {
+ $conn->respond_complete;
+ return;
+ }
- return $U->storagereq(
- 'open-ils.storage.fetch.metabib.display_field.highlight.atomic',
- $highlight_map,
- \@records
- );
+ my $hl_map_string = "''::HSTORE";
+ if (ref($highlight_map) =~ /HASH/) {
+ $hl_map_string = "";
+ for my $tsq (keys %$highlight_map) {
+ my $field_list = join(',', @{$$highlight_map{$tsq}});
+ $hl_map_string .= ' || ' if $hl_map_string;
+ $hl_map_string .= "hstore(($tsq)\:\:TEXT,'$field_list')";
+ }
+ }
+
+ my $e = new_editor();
+
+ for my $record ( @records ) {
+ next unless $record;
+ $conn->respond(
+ $e->json_query(
+ {from => ['search.highlight_display_fields', $record, $hl_map_string]}
+ )
+ );
+ }
+
+ return undef;
}
__PACKAGE__->register_method(
- method => 'passthrough_fetch_display_fields',
+ method => 'fetch_display_fields',
api_name => 'open-ils.search.fetch.metabib.display_field.highlight'
);
die("Cannot initialize $parser!") unless ($parser->initialization_complete);
}
-sub fetch_highlighted_display_fields {
- my $self = shift;
- my $client = shift;
- my $records = shift;
- my $highlight_map = shift;
-
- unless ($records) {
- $client->respond_complete;
- return;
- }
-
- my $hl_map_string = "''::HSTORE";
- if (ref($highlight_map)) {
- $hl_map_string = "";
- for my $tsq (keys %$highlight_map) {
- my $field_list = join(',', @{$$highlight_map{$tsq}});
- $hl_map_string .= ' || ' if $hl_map_string;
- $hl_map_string .= "hstore(($tsq)\:\:TEXT,'$field_list')";
- }
- }
-
- my $sth = metabib::metarecord_source_map->db_Main->prepare(
- "SELECT * FROM search.highlight_display_fields(?, $hl_map_string)"
- );
-
- $records = [$records] unless ref($records);
- for my $record ( @$records ) {
- next unless $record;
- $sth->execute($record);
- my $rows = $sth->fetchall_arrayref({});
- $client->respond($rows);
- }
-
- return undef;
-}
-__PACKAGE__->register_method(
- api_name => 'open-ils.storage.fetch.metabib.display_field.highlight',
- method => 'fetch_highlighted_display_fields',
- api_level => 1,
- stream => 1
-);
-
-
sub ordered_records_from_metarecord { # XXX Replace with QP-based search-within-MR
my $self = shift;
my $client = shift;
use constant ANON_CACHE_MYLIST => 'mylist';
use constant ANON_CACHE_STAFF_SEARCH => 'staffsearch';
-use constant DEBUG_TIMING => 0;
+use constant DEBUG_TIMING => 1;
sub new {
my($class, $apache, $ctx) = @_;
$self->cgi(new CGI);
$self->timelog("New page");
+ # Add a timelog helper to the context
+ $self->ctx->{timelog} = sub { return $self->timelog(@_) };
+
OpenILS::Utils::CStoreEditor->init; # just in case
$self->editor(new_editor());
return $U->simplereq(
'open-ils.search',
'open-ils.search.fetch.metabib.display_field.highlight',
- $id,
- $ctx->{query_struct}{additional_data}{highlight_map}
+ $ctx->{query_struct}{additional_data}{highlight_map},
+ map {int($_)} @$id
);
};
CREATE TYPE search.highlight_result AS ( id BIGINT, source BIGINT, field INT, value TEXT, highlight TEXT );
-CREATE OR REPLACE FUNCTION search.highlight_display_fields(
+CREATE OR REPLACE FUNCTION search.highlight_display_fields_impl(
rid BIGINT,
tsq TEXT,
field_list INT[] DEFAULT '{}'::INT[],
CREATE OR REPLACE FUNCTION search.highlight_display_fields(
rid BIGINT,
- tsq_map HSTORE, -- { '(a | b) & c' => '1,2,3,4', ...}
+ tsq_map TEXT, -- { '(a | b) & c' => '1,2,3,4', ...}
css_class TEXT DEFAULT 'oils_SH',
hl_all BOOL DEFAULT TRUE,
minwords INT DEFAULT 5,
delimiter TEXT DEFAULT ' ... '
) RETURNS SETOF search.highlight_result AS $f$
DECLARE
- tsq TEXT;
- fields TEXT;
- afields INT[];
- seen INT[];
+ tsq_hstore TEXT;
+ tsq TEXT;
+ fields TEXT;
+ afields INT[];
+ seen INT[];
BEGIN
- FOR tsq, fields IN SELECT key, value FROM each(tsq_map) LOOP
+ IF (tsq_map ILIKE 'hstore%') THEN
+ EXECUTE 'SELECT ' || tsq_map INTO tsq_hstore;
+ ELSE
+ tsq_hstore := tsq_map::HSTORE;
+ END IF;
+
+ FOR tsq, fields IN SELECT key, value FROM each(tsq_hstore) LOOP
SELECT ARRAY_AGG(unnest::INT) INTO afields
FROM unnest(regexp_split_to_array(fields,','));
seen := seen || afields;
RETURN QUERY
- SELECT * FROM search.highlight_display_fields(
+ SELECT * FROM search.highlight_display_fields_impl(
rid, tsq, afields, css_class, hl_all,minwords,
maxwords, shortwords, maxfrags, delimiter
);
('creators', 37, TRUE),
('subject', 16, TRUE),
('isbn', 18, TRUE),
- ('series_title', 1, FALSE),
+ ('series_title', 1, TRUE),
('subject_geographic', 11, TRUE),
('subject_name', 12, TRUE),
('subject_temporal', 13, TRUE),
-- Map display field names to config.metabib_field entries
INSERT INTO config.display_field_map (name, field, multi) VALUES
- ('series_title', 1, FALSE),
+ ('series_title', 1, TRUE),
('subject_geographic', 11, TRUE),
('subject_name', 12, TRUE),
('subject_temporal', 13, TRUE),
CREATE TYPE search.highlight_result AS ( id BIGINT, source BIGINT, field INT, value TEXT, highlight TEXT );
-CREATE OR REPLACE FUNCTION search.highlight_display_fields(
+CREATE OR REPLACE FUNCTION search.highlight_display_fields_impl(
rid BIGINT,
tsq TEXT,
field_list INT[] DEFAULT '{}'::INT[],
CREATE OR REPLACE FUNCTION search.highlight_display_fields(
rid BIGINT,
- tsq_map HSTORE, -- { '(a | b) & c' => '1,2,3,4', ...}
+ tsq_map TEXT, -- { '(a | b) & c' => '1,2,3,4', ...}
css_class TEXT DEFAULT 'oils_SH',
hl_all BOOL DEFAULT TRUE,
minwords INT DEFAULT 5,
delimiter TEXT DEFAULT ' ... '
) RETURNS SETOF search.highlight_result AS $f$
DECLARE
- tsq TEXT;
- fields TEXT;
- afields INT[];
- seen INT[];
+ tsq_hstore HSTORE;
+ tsq TEXT;
+ fields TEXT;
+ afields INT[];
+ seen INT[];
BEGIN
- FOR tsq, fields IN SELECT key, value FROM each(tsq_map) LOOP
+
+ IF (tsq_map ILIKE 'hstore%') THEN
+ EXECUTE 'SELECT ' || tsq_map INTO tsq_hstore;
+ ELSE
+ tsq_hstore := tsq_map::HSTORE;
+ END IF;
+
+ FOR tsq, fields IN SELECT key, value FROM each(tsq_hstore) LOOP
SELECT ARRAY_AGG(unnest::INT) INTO afields
FROM unnest(regexp_split_to_array(fields,','));
seen := seen || afields;
RETURN QUERY
- SELECT * FROM search.highlight_display_fields(
+ SELECT * FROM search.highlight_display_fields_impl(
rid, tsq, afields, css_class, hl_all,minwords,
maxwords, shortwords, maxfrags, delimiter
);
args.display_fields = {};
args.hl = {};
IF !CGI.param('no_highlight') && !search.no_highlight;
+
+ junk = ctx.timelog('Fetching of highlighted display fields for bib(s) ' _ args.df_bib_list.list.join(', '));
args.display_field_list = ctx.fetch_display_fields(args.df_bib_list.list);
+ junk = ctx.timelog('Finished fetch of highlighted display fields for bib(s) ' _ args.df_bib_list.list.join(', '));
+ junk = ctx.timelog('Mapping highlighted display fields for bib(s) ' _ args.df_bib_list.list.join(', '));
FOR df IN args.display_field_list;
df_map = ctx.search_cdfm('field', df.field).0;
df_name = df_map.name();
args.hl.$df_name = df.highlight || df.value;
END;
END;
+ junk = ctx.timelog('Finished mapping highlighted display fields for bib(s) ' _ args.df_bib_list.list.join(', '));
END;
# Map item types to schema.org types; impedance mismatch :(