+ my $authtypecode = $record->{authtype};
+ my $rs = $schema->resultset('AuthType')
+ ->search( { authtypecode => $authtypecode } );
+
+ # FIXME there's an assumption here that we will get a result.
+ # the original code also makes an assumption that some provided
+ # authtypecode may sometimes be used instead of the one stored
+ # with the record. It's not documented why this is the case, so
+ # it's not reproduced here yet.
+ my $authtype = $rs->single;
+ my $auth_tag_to_report = $authtype ? $authtype->auth_tag_to_report : "";
+ my $marc = $self->decode_record_from_result(@_);
+ my $mainentry = $marc->field($auth_tag_to_report);
+ my $reported_tag;
+ if ($mainentry) {
+ foreach ( $mainentry->subfields() ) {
+ $reported_tag .= '$' . $_->[0] . $_->[1];
+ }
+ }
+ # Turn the resultset into a hash
+ $result{authtype} = $authtype ? $authtype->authtypetext : $authtypecode;
+ $result{reported_tag} = $reported_tag;
+
+ # Reimplementing BuildSummary is out of scope because it'll be hard
+ $result{summary} =
+ C4::AuthoritiesMarc::BuildSummary( $marc, $result{authid},
+ $authtypecode );
+ $result{used} = $self->count_auth_use($bib_searcher, $authid);
+ push @records, \%result;
+ }
+ );
+ return ( \@records, $res->total );
+}
+
+=head2 count_auth_use
+
+ my $count = $auth_searcher->count_auth_use($bib_searcher, $authid);
+
+This runs a search to determine the number of records that reference the
+specified authid. C<$bib_searcher> must be something compatible with
+elasticsearch, as the query is built in this function.
+
+=cut
+
+sub count_auth_use {
+ my ($self, $bib_searcher, $authid) = @_;
+
+ my $query = {
+ query => {
+ bool => {
+# query => { match_all => {} },
+ filter => { term => { an => $authid } }
+ }
+ }
+ };
+ $bib_searcher->count($query);
+}
+
+=head2 simple_search_compat
+
+ my ( $error, $marcresults, $total_hits ) =
+ $searcher->simple_search( $query, $offset, $max_results, %options );
+
+This is a simpler interface to the searching, intended to be similar enough to
+L<C4::Search::SimpleSearch>.
+
+Arguments:
+
+=over 4
+
+=item C<$query>
+
+A thing to search for. It could be a simple string, or something constructed
+with the appropriate QueryBuilder module.
+
+=item C<$offset>
+
+How many results to skip from the start of the results.
+
+=item C<$max_results>
+
+The max number of results to return. The default is 100 (because unlimited
+is a pretty terrible thing to do.)
+
+=item C<%options>
+
+These options are unused by Elasticsearch
+
+=back
+
+Returns:
+
+=over 4
+
+=item C<$error>
+
+if something went wrong, this'll contain some kind of error
+message.
+
+=item C<$marcresults>
+
+an arrayref of MARC::Records (note that this is different from the
+L<C4::Search> version which will return plain XML, but too bad.)
+
+=item C<$total_hits>
+
+the total number of results that this search could have returned.
+
+=back
+
+=cut
+
+sub simple_search_compat {
+ my ($self, $query, $offset, $max_results) = @_;
+
+ return ('No query entered', undef, undef) unless $query;
+
+ my %options;
+ $offset = 0 if not defined $offset or $offset < 0;
+ $options{offset} = $offset;
+ $max_results //= 100;
+
+ unless (ref $query) {
+ # We'll push it through the query builder to sanitise everything.
+ my $qb = Koha::SearchEngine::QueryBuilder->new({index => $self->index});
+ (undef,$query) = $qb->build_query_compat(undef, [$query]);
+ }
+ my $results = $self->search($query, undef, $max_results, %options);
+ my @records;
+ $results->each(sub {
+ my $marc = $self->decode_record_from_result(@_);