MARC expert search working
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 27 Jul 2011 22:21:31 +0000 (18:21 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 27 Jul 2011 22:21:31 +0000 (18:21 -0400)
This just needs the JS row cloning so you can search on multiple terms
at a time.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/web/css/skin/default/opac/style.css
Open-ILS/web/templates/default/opac/parts/advanced/expert.tt2

index ea33fa0..2a9e5cd 100644 (file)
@@ -133,7 +133,14 @@ sub load_rresults {
 
     $ctx->{page} = 'rresult';
 
-    return $self->item_barcode_shortcut if $cgi->param("qtype") eq "item_barcode";
+    if ($cgi->param("_special")) {
+        return $self->marc_expert_search if scalar($cgi->param("tag"));
+        return $self->item_barcode_shortcut if (
+            $cgi->param("qtype") and ($cgi->param("qtype") eq "item_barcode")
+        );
+        return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+    }
+
 
     my $page = $cgi->param('page') || 0;
     my $facet = $cgi->param('facet');
@@ -255,4 +262,62 @@ sub item_barcode_shortcut {
         return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
     }
 }
+
+# like item_barcode_search, this can't take all the usual search params, but
+# this one will at least do site, limit and page
+sub marc_expert_search {
+    my ($self) = @_;
+
+    my @tags = $self->cgi->param("tag");
+    my @subfields = $self->cgi->param("subfield");
+    my @terms = $self->cgi->param("term");
+
+    my $query = [];
+    for (my $i = 0; $i < scalar @tags; $i++) {
+        push @$query, {
+            "term" => $terms[$i],
+            "restrict" => [{"tag" => $tags[$i], "subfield" => $subfields[$i]}]
+        };
+    }
+
+    # loc, limit and offset
+    my $page = $self->cgi->param("page") || 0;
+    my $limit = $self->_get_search_limit;
+    my $org_unit = $self->cgi->param("loc") || $self->ctx->{aou_tree}->()->id;
+    my $offset = $page * $limit;
+
+    if (my $search = create OpenSRF::AppSession("open-ils.search")) {
+        my $results = $search->request(
+            "open-ils.search.biblio.marc", {
+                "searches" => $query, "org_unit" => $org_unit
+            }, $limit, $offset
+        )->gather(1);
+
+        if (defined $U->event_code($results)) {
+            $self->apache->log->warn(
+                "open-ils.search.biblio.marc returned event: " .
+                $U->event_code($results)
+            );
+            return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+        }
+
+        my ($facets, @data) = $self->get_records_and_facets(
+            # filter out nulls that will turn up here
+            [ grep { $_ } @{$results->{ids}} ],
+            undef, {flesh => "{holdings_xml,mra}"}
+        );
+
+        $self->ctx->{records} = [@data];
+        $self->ctx->{search_facets} = {};
+
+        $self->ctx->{page_size} = $limit;
+        $self->ctx->{hit_count} = $results->{count};
+
+        return Apache2::Const::OK;
+    } else {
+        $self->apache->log->warn("couldn't connect to open-ils.search");
+        return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+    }
+}
+
 1;
index 6ea13c5..6a0a19a 100644 (file)
@@ -1014,3 +1014,4 @@ a.dash-link:hover { text-decoration: underline !important; }
 .invisible { visibility: hidden; }
 .rdetail-extras-summary { margin: 10px; }
 .staff-hold { background-color: #eee; }
+.expert-search tbody tr th { text-align: right; padding-left: 2em; }
index 35b11ab..640b4f2 100644 (file)
@@ -1,3 +1,24 @@
-<!-- <form id="adv_search_form" action="[% ctx.opac_root %]/results" method="GET"> -->
+<form id="adv_search_form" action="[% ctx.opac_root %]/results" method="GET">
     <div class="header_middle">[% l("Expert Search") %]</div>
-<!-- </form> -->
+    <input type="hidden" name="_special" value="1" />
+    <table class="expert-search">
+        <tbody id="rows_here">
+            <tr id="clone_this">
+                <th>[% l("Tag:") %]</th>
+                <td><input type="text" name="tag" size="3" /></td>
+                <th>[% l("Subfield:") %]</th>
+                <td><input type="text" name="subfield" size="1" /></td>
+                <th>[% l("Value:") %]</th>
+                <td><input type="text" name="term" size="16" /></td>
+            </tr>
+        </tbody>
+        <tfoot>
+            <tr>
+                <td colspan="2"><a href="javascript:alert('XXX coming soon');">[ [% l("Add row") %] ]</a></td>
+                <td colspan="4">
+                    <input type="image" src="[% ctx.media_prefix %]/images/search_btn.gif" alt="[% l('Search') %]" title="[% l('Search') %]" />
+                </td>
+            </tr>
+        </tfoot>
+    </table>
+</form>