536e32480cf89093ba8b82ff4e73b0a9ca6ac389
chmalee
  Fri Oct 28 13:29:33 2022 -0700
Fix multiTerm searches and plain chromosome searches, refs #29693

diff --git src/hg/hgSearch/hgSearch.c src/hg/hgSearch/hgSearch.c
index 2b5ef8d..4d669de 100644
--- src/hg/hgSearch/hgSearch.c
+++ src/hg/hgSearch/hgSearch.c
@@ -151,62 +151,61 @@
 hgFindTdbList = superList;
 hashTdbNames(superList, hgFindTrackHash);
 struct grp *g;
 for (g = hgFindGrpList; g != NULL; g = g->next)
     if (!sameString(g->name, "allTracks") && !sameString(g->name, "allTables"))
         hashStore(hgFindGroupHash, g->name);
 }
 
 
 void doQuery(struct jsonWrite *jw, char *db, struct searchCategory *categories, char *searchTerms, boolean measureTiming)
 /* Fire off a query. If the query results in a single position and we came from another CGI,
  * redirect right back to that CGI (except if we came from hgGateway redirect to hgTracks),
  * otherwise return the position list as JSON */
 {
 struct hgPositions *hgp = NULL;
-hgp = hgPositionsFind(db, searchTerms, "", "hgSearch", cart, FALSE, measureTiming, categories);
-if (hgp)
+char *chrom;
+int retWinStart = 0, retWinEnd = 0;
+boolean categorySearch = TRUE;
+hgp = genomePosCJ(jw, db, searchTerms, &chrom, &retWinStart, &retWinEnd, cart, categories, categorySearch);
+// at this point, if the search term wasn't a singlePos, we have written
+// out the JSON already. So now take care of the singlePos case
+if (hgp && hgp->singlePos)
     {
     // if we got an hgvs match to chromInfo (example: chrX:g.31500000_31600000del),
     // or just a plain position range was searched, we have to create the json
     // manually, cause the tdb lookups in hgPositionsJson() won't work
-    if (hgp->singlePos && hgp->posCount == 1 && hgp->tableList != NULL &&
-            sameString(hgp->tableList->name, "chromInfo"))
-        {
     struct hgPosTable *table = hgp->tableList;
     jsonWriteListStart(jw, "positionMatches");
     jsonWriteObjectStart(jw, NULL);
-        jsonWriteString(jw, "name", "chromInfo");
+    jsonWriteString(jw, "name", table->name);
     jsonWriteString(jw, "description", table->description);
     if (table->searchTime >= 0)
         jsonWriteNumber(jw, "searchTime", table->searchTime);
     jsonWriteListStart(jw, "matches");
 
     jsonWriteObjectStart(jw, NULL);
     char position[512];
-        safef(position, sizeof(position), "%s:%d-%d", hgp->singlePos->chrom, hgp->singlePos->chromStart, hgp->singlePos->chromEnd);
+    safef(position, sizeof(position), "%s:%d-%d", hgp->singlePos->chrom, retWinStart, retWinEnd);
     jsonWriteString(jw, "position", position);
     jsonWriteString(jw, "posName", hgp->query);
     jsonWriteObjectEnd(jw);
 
     jsonWriteListEnd(jw); // end matches
     jsonWriteObjectEnd(jw); // end one table
     jsonWriteListEnd(jw); // end positionMatches
     }
-    else
-        hgPositionsJson(jw, db, hgp, cart);
-    }
 }
 
 static void addCategoryFieldsToHash(struct hash *elementHash, struct searchCategory *category)
 {
 hashAdd(elementHash, "name", newJsonString(category->name));
 hashAdd(elementHash, "id", newJsonString(category->id));
 hashAdd(elementHash, "visibility", newJsonNumber((long)category->visibility));
 hashAdd(elementHash, "group", newJsonString(category->groupName));
 hashAdd(elementHash, "label", newJsonString(category->label));
 hashAdd(elementHash, "description", newJsonString(category->description));
 hashAdd(elementHash, "parents", newJsonString(slNameListToString(category->parents, ',')));
 hashAdd(elementHash, "priority", newJsonDouble(category->priority));
 }
 
 static boolean nonTrackCateg(struct searchCategory *categ)