64cf5265a375948af55b9237cd3fd91f8749f0e2
kent
  Sat Jan 30 08:56:53 2021 -0800
Making facetFieldsFromFieldedTable return the subtable that it has selected out, which is a bit more useful.

diff --git src/hg/lib/facetField.c src/hg/lib/facetField.c
index a41107c..f9924dc 100644
--- src/hg/lib/facetField.c
+++ src/hg/lib/facetField.c
@@ -378,52 +378,49 @@
     if (perRowFacetFields(fieldCount, row, nullVal, ffArray))
 	++selectedRowCount;
     }
 
 facetFieldsFromSqlTableFinish(ffList, facetValCmpUseCountDesc);
 
 /* Clean up and go home */
 dyStringFree(&query);
 sqlFreeResult(&sr);
 
 if (pSelectedRowCount)
     *pSelectedRowCount = selectedRowCount;
 return ffList;
 }
 
-struct facetField *facetFieldsFromFieldedTable(struct fieldedTable *ft, char *selectedFields,
-    struct facetField *ffArray[], int *retSelectedRowCount)
+struct fieldedTable *facetFieldsFromFieldedTable(struct fieldedTable *ft, char *selectedFields,
+    struct facetField *ffArray[])
 /* Get a facetField list and initialize arrays based on selected fields from table 
  * ffArray must be big enough to hold all fields in table */
 {
-struct facetField *ffList = facetFieldsFromSqlTableInit(ft->fields, ft->fieldCount, 
+int fieldCount = ft->fieldCount;
+struct fieldedTable *subTable = fieldedTableNew(ft->name, ft->fields, fieldCount);
+struct facetField *ffList = facetFieldsFromSqlTableInit(ft->fields, fieldCount, 
     selectedFields, ffArray);
-
 struct fieldedRow *fr;
-int selectedRowCount = 0;
-int fieldCount = ft->fieldCount;
 for (fr = ft->rowList; fr != NULL; fr = fr->next)
     {
     if (perRowFacetFields(fieldCount, fr->row, "", ffArray))
-	++selectedRowCount;
+	{
+	fieldedTableAdd(subTable, fr->row, fieldCount, fr->id);
+	}
     }
-
 facetFieldsFromSqlTableFinish(ffList, facetValCmpUseCountDesc);
-
-if (retSelectedRowCount != NULL)
-    *retSelectedRowCount = selectedRowCount;
-return ffList;
+return subTable;
 }
 
 struct facetVal *facetValMajorPlusOther(struct facetVal *list, double minRatio)
 /* Return a list of only the tags that are over minRatio of total tags.
  * If there are tags that have smaller amounts than this, lump them together
  * under "other".  Returns a new list. Use slFreeList() to free the result.  */
 {
 /* Figure out total and minimum count to not be lumped into other */
 long total = 0;
 struct facetVal *tc;
 for (tc = list; tc != NULL; tc = tc->next)
     total += tc->useCount;
 long minCount = round(minRatio * total);
 
 /* Loop through and copy ones over threshold to new list, and lump rest