c6ce277e36a537437a04146c8fa7adebb40428ff
chmalee
  Wed May 15 12:10:42 2024 -0700
Libify some searching code so checkHgFindSpec can use it. Make checkHgFindSpec use the same code path as hgSearch so it can correctly test the search correctly, refs #33731

diff --git src/hg/checkHgFindSpec/checkHgFindSpec.c src/hg/checkHgFindSpec/checkHgFindSpec.c
index a7da341..c86c15c 100644
--- src/hg/checkHgFindSpec/checkHgFindSpec.c
+++ src/hg/checkHgFindSpec/checkHgFindSpec.c
@@ -4,36 +4,42 @@
  * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */
 #include "common.h"
 #include "options.h"
 #include "jksql.h"
 #include "hash.h"
 #include "dystring.h"
 #include "portable.h"
 #include "hdb.h"
 #include "hui.h"
 #include "cheapcgi.h"
 #include "cart.h"
 #include "hgFind.h"
 #include "hgFindSpec.h"
 #include "regexHelper.h"
 #include "genbank.h"
-
+#include "cartTrackDb.h"
 
 char *database = NULL;
 /* Need to get a cart in order to use hgFind. */
 struct cart *cart = NULL;
 
+/* Caches for searching */
+extern struct trackDb *hgFindTdbList;
+extern struct grp *hgFindGrpList;
+extern struct hash *hgFindGroupHash;
+extern struct hash *hgFindTrackHash;
+
 /* Command line option specifications */
 static struct optionSpec optionSpecs[] = {
     {"showSearches",    OPTION_BOOLEAN},
     {"checkTermRegex",  OPTION_BOOLEAN},
     {"exampleFor",      OPTION_STRING},
     {"checkIndexes",    OPTION_BOOLEAN},
     {"makeExamples",    OPTION_BOOLEAN},
     {NULL, 0}
 };
 
 
 void usage()
 {
 errAbort(
 "checkHgFindSpec - test and describe search specs in hgFindSpec tables.\n"
@@ -127,32 +133,34 @@
 	{
 	verbose(2, "no match %s: %s\n", hfs->searchName, hfs->termRegex);
 	}
     }
 endMs = clock1000();
 printf("\nTook %dms to determine multiple/additive searches.\n"
        "(These won't happen if it short-circuits.)\n\n",
        endMs - startMs);
 
 if (isNotEmpty(termToSearch))
     {
     cartSetString(cart, "db", database);
     char *position = cloneString(termToSearch);
     struct dyString *dyWarn = dyStringNew(0);
     startMs = clock1000();
+    hashTracksAndGroups(cart, database);
+    struct searchCategory *allCategories = getAllCategories(cart, database, hgFindGroupHash);
     struct hgPositions *hgp = hgFindSearch(cart, &position, &chrom, &chromStart, &chromEnd,
-                                           "checkHgFindSpec", dyWarn);
+                                           "checkHgFindSpec", dyWarn, allCategories);
     endMs = clock1000();
     if (isNotEmpty(dyWarn->string))
         warn("%s", dyWarn->string);
     if (hgp->singlePos != NULL)
 	{
 	struct hgPos *pos = hgp->singlePos;
 	char *table = "[No reported table!]";
 	char *name = pos->name ? pos->name : "";
 	char *browserName = pos->browserName ? pos->browserName : "";
 	char *description = pos->description ? pos->description : "";
 	if (hgp->tableList != NULL)
 	    table = hgp->tableList->name;
 	printf("\nSingle result for %s from %s: %s:%d-%d   [%s | %s | %s]\n",
 	       termToSearch, table, chrom, chromStart+1, chromEnd,
 	       name, browserName, description);