Return fields where terms used, also return multiple authorities
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 26 Apr 2013 20:58:33 +0000 (16:58 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 3 May 2013 13:57:49 +0000 (09:57 -0400)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
Open-ILS/src/templates/opac/browse.tt2

index 5e6fa8b..fbbe7bf 100644 (file)
@@ -6915,10 +6915,12 @@ CREATE INDEX CONCURRENTLY browse_entry_sort_value_idx
 -- CREATE INDEX CONCURRENTLY browse_entry_sort_value_idx_desc
 --    ON metabib.browse_entry USING BTREE (sort_value DESC);
 
-CREATE TYPE metabib.slim_browse_entry AS (
+CREATE TYPE metabib.flat_browse_entry_appearance AS (
     browse_entry BIGINT,
     value TEXT,
-    authority BIGINT
+    fields TEXT,
+    authorities TEXT,
+    sources INT
 );
 
 
@@ -7004,7 +7006,7 @@ CREATE OR REPLACE FUNCTION metabib.browse(
     context_loc_group   INT DEFAULT NULL,
     result_limit        INT DEFAULT 10,
     result_offset       INT DEFAULT 0   -- Can be negative!
-) RETURNS SETOF metabib.slim_browse_entry AS $p$
+) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
 DECLARE
     joins               TEXT;
     where_clause        TEXT;
@@ -7012,7 +7014,7 @@ DECLARE
     result_query        TEXT;
     pivot_sort_value    TEXT;
     f                   RECORD;
-    r                   metabib.slim_browse_entry%ROWTYPE;
+    r                   metabib.flat_browse_entry_appearance%ROWTYPE;
     use_offset          INT;
 BEGIN
     pivot_sort_value := metabib.browse_pivot(
@@ -7031,7 +7033,17 @@ BEGIN
     where_clause := joins_and_where[2];
 
     result_query :=
-        'SELECT mbe.id, mbe.value, mbedm.authority, mbe.sort_value
+        'SELECT mbe.id, mbe.value, mbe.sort_value,
+            ARRAY_TO_STRING(
+                (SELECT ARRAY_AGG(field) FROM (
+                    SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.def)) AS field
+                ) y),
+                $$,$$
+            ) AS fields,
+            ARRAY_TO_STRING(ARRAY_AGG(mbedm.authority), $$,$$) AS authorities,
+            (SELECT COUNT(source) FROM (
+                SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.source)) AS source
+            ) x) sources
         FROM metabib.browse_entry mbe ' ||
         joins ||
         'WHERE ' || where_clause;
@@ -7041,12 +7053,12 @@ BEGIN
         use_offset := result_offset;
         result_query := result_query ||
             ' mbe.sort_value >= ' || quote_literal(pivot_sort_value) ||
-        ' GROUP BY 1,2,3,4 ORDER BY mbe.sort_value ';
+        ' GROUP BY 1,2,3 ORDER BY mbe.sort_value ';
     ELSE
         -- Step 1 of 2 to deliver what the user wants with a negative offset:
         result_query := result_query ||
             ' mbe.sort_value < ' || quote_literal(pivot_sort_value) ||
-        ' GROUP BY 1,2,3,4 ORDER BY mbe.sort_value DESC ';
+        ' GROUP BY 1,2,3 ORDER BY mbe.sort_value DESC ';
 
         use_offset := ABS(result_offset) - result_limit;
         IF use_offset < 0 THEN
@@ -7072,7 +7084,9 @@ BEGIN
     FOR f IN EXECUTE result_query LOOP
         r.browse_entry := f.id;
         r.value := f.value;
-        r.authority := f.authority;
+        r.fields := f.fields;
+        r.authorities := f.authorities;
+        r.sources := f.sources;
 
         RETURN NEXT r;
     END LOOP;
@@ -7086,7 +7100,7 @@ CREATE OR REPLACE FUNCTION metabib.browse(
     context_loc_group   INT DEFAULT NULL,
     result_limit        INT DEFAULT 10,
     result_offset       INT DEFAULT 0   -- Can be negative!
-) RETURNS SETOF metabib.slim_browse_entry AS $p$
+) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
 BEGIN
     RETURN QUERY SELECT * FROM metabib.browse(
         (SELECT COALESCE(ARRAY_AGG(id), ARRAY[]::INT[])
index 04655f9..5543d54 100644 (file)
@@ -11,7 +11,7 @@
     %]
 
     <div id="search-wrapper">
-        [%# XXX TODO Give searchbar smarts so we can just do:
+        [%# XXX TODO Give searchbar.tt2 more smarts so we can just do:
           # INCLUDE "opac/parts/searchbar.tt2" %]
         <div id="search-tools">
             <span class="search_catalog_lbl">[% l('Search the Catalog') %]</span>
                     </span>
                 [% ELSE %]
                     [% FOR result IN ctx.browse_results %]
-                        [% result.value | html %]</br><!-- XXX TODO serious -->
+                    <div class="browse-result">
+                        <span class="browse-result-value">[% result.value | html %]</span>
+                        <span class="browse-result-value">([% result.sources %])</span>
+                    </div>
                     [% END %]
                 [% END %]
                 </div>