60f1001d3a232c29adb505f3c38c0469e0151b09
galt
  Wed Jan 31 16:43:20 2018 -0800
adding selectedRowCount

diff --git src/hg/lib/facetField.c src/hg/lib/facetField.c
index 41e6ee4..691acb8 100644
--- src/hg/lib/facetField.c
+++ src/hg/lib/facetField.c
@@ -48,31 +48,31 @@
 facetField->currentVal = facetVal;
 }
 
 static struct facetField *facetFieldNew(char *fieldName)
 /* Create a new facetField structure */
 {
 struct facetField *facetField;
 AllocVar(facetField);
 facetField->fieldName = cloneString(fieldName);
 facetField->valHash = hashNew(0);
 facetField->allSelected = TRUE;  // default to all values selected
 return facetField;
 }
 
 struct facetField *facetFieldsFromSqlTable(struct sqlConnection *conn, char *table, char *fields[], int fieldCount, 
-    char *nullVal, char *where, char *selectedFields)
+    char *nullVal, char *where, char *selectedFields, int *pSelectedRowCount)
 /* Return a list of facetField, one for each field of given table */
 {
 
 /* Make query string */
 struct dyString *query = dyStringNew(0);
 sqlDyStringPrintf(query, "select %s", fields[0]);
 int i;
 for (i=1; i<fieldCount; ++i)
     {
     sqlDyStringPrintf(query, ",");
     sqlDyStringPrintf(query, "%s", fields[i]);
     }
 sqlDyStringPrintf(query, " from %s", table);
 if (where != NULL)
     sqlDyStringPrintf(query, " where %-s", where); // trusting where-clause
@@ -114,71 +114,75 @@
 	    {
 	    if (sameString(ffArray[i]->fieldName, selectedFields))
 		{
 		struct slName *el;
 		for (el=valList; el; el=el->next)
 		    {
 		    uglyf("adding selected field %s val %s\n", selectedFields, el->name);
 		    facetFieldAdd(ffArray[i], el->name, TRUE);
 		    }
 		}
 	    }
 	selectedFields = end+1;
 	}
     }
 
+int selectedRowCount = 0;
 
 /* Scan through result saving it in list. */
 struct sqlResult *sr = sqlGetResult(conn, query->string);
 char **row;
 while ((row = sqlNextRow(sr)) != NULL)
     {
     int totalSelectedFacets = 0;
     for (i=0; i<fieldCount; ++i)
 	{
 	char *val = row[i];
 	if (val == NULL)
 	    val = nullVal;
 	if (val != NULL)
 	    {
 	    facetFieldAdd(ffArray[i], val, FALSE);
 	    if (ffArray[i]->currentVal->selected)
 		++totalSelectedFacets;
 	    }
 	}
 
     if (totalSelectedFacets == fieldCount)
 	{
 	// include this row in the final resultset
+	++selectedRowCount;
 	}
     for (i=0; i<fieldCount; ++i)
 	{
 	// disregard one's self.
 	if ((totalSelectedFacets - (int)ffArray[i]->currentVal->selected) == (fieldCount - 1))
 	    ffArray[i]->currentVal->selectCount++;
 	    // shown on GUI to guide choosing by user
 	}
 
     }
 
 /* Sort lists */
 for (ff = ffList; ff != NULL; ff = ff->next)
     slSort(&ff->valList, facetValCmpUseCountDesc);
 
 /* Clean up and go home */
 dyStringFree(&query);
 sqlFreeResult(&sr);
+if (pSelectedRowCount)
+    *pSelectedRowCount = selectedRowCount;
 return ffList;
 }
 
 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);