LP1844418 ES rebasing
authorBill Erickson <berickxx@gmail.com>
Wed, 27 Oct 2021 17:26:03 +0000 (13:26 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 13 Jun 2022 20:02:46 +0000 (16:02 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts

index 434ebdd..121d10b 100644 (file)
@@ -204,10 +204,14 @@ export class ElasticService {
             const marcQuery = new BoolQuery();
             const tag = ms.tags[idx];
             const subfield = ms.subfields[idx];
+
+            /*
+             * Un-comment this if supporting match ops for marc searches.
             const matchOp = ms.matchOp[idx];
 
             this.appendMatchOp(
                 marcQuery, matchOp, 'marc.value.text*', 'marc.value', value);
+            */
 
             if (tag) {
                 marcQuery.must(new TermQuery('marc.tag', tag));
@@ -354,5 +358,36 @@ export class ElasticService {
                 return;
         }
     }
+
+    formatFacets(facets: any) {
+        const facetData = {};
+        Object.keys(facets).forEach(ebfId => {
+            const facetHash = facets[ebfId];
+
+            const ebfData = [];
+            Object.keys(facetHash).forEach(value => {
+                const count = facetHash[value];
+                ebfData.push({value : value, count : count});
+            });
+
+            const parts = ebfId.split('|');
+            const fclass = parts[0];
+            const fname = parts[1];
+
+            if (!facetData[fclass]) { facetData[fclass] = {}; }
+
+            facetData[fclass][fname] = {
+                // 'cmfLabel' is what the higher-level code seeks
+                cmfLabel : ebfId, // TODO
+                valueList : ebfData.sort((a, b) => {
+                    if (a.count > b.count) { return -1; }
+                    if (a.count < b.count) { return 1; }
+                    return a.value < b.value ? -1 : 1;
+                })
+            };
+        });
+
+        return facetData;
+    }
 }