ccda596950ffdad4d7560c1bb660b31c1bd3b55a hiram Mon Sep 30 11:07:54 2024 -0700 put a limit on genark returned list refs #32596 diff --git src/hg/hgGateway/hgGateway.c src/hg/hgGateway/hgGateway.c index 94186b8..7598059 100644 --- src/hg/hgGateway/hgGateway.c +++ src/hg/hgGateway/hgGateway.c @@ -941,42 +941,49 @@ { jsonWriteObjectStart(jw, NULL); jsonWriteString(jw, "genome", gHubMatch->gcAccession); jsonWriteString(jw, "db", gHubMatch->asmName); jsonWriteString(jw, "hubUrl", gHubMatch->hubUrl); jsonWriteString(jw, "scientificName", gHubMatch->scientificName); // Add a category label for customized autocomplete-with-categories. jsonWriteString(jw, "category", "UCSC GenArk - bulk-annotated assemblies from NCBI Genbank/RefSeq"); jsonWriteString(jw, "value", gHubMatch->asmName); // Use just the db as label, since shortLabel is included in the category label. jsonWriteStringf(jw, "label", "%s - %s", gHubMatch->commonName, gHubMatch->scientificName); jsonWriteObjectEnd(jw); } } +/* maximum limit of how many matches to display from genark */ +#define GENARK_LIMIT 20 + static struct gHubMatch *filterGenarkMatches(char *genarkHubUrl, struct genark *matchList) /* Turn the sql results into a struct gHubMatch list */ { struct genark *match; struct gHubMatch *ret = NULL; +int c = 0; for (match = matchList; match != NULL; match = match->next) { + ++c; // the match contains tab-sep accession, hubUrl, asmName, scientificName, commonName char hubUrl[PATH_LEN+1]; safef(hubUrl, sizeof(hubUrl), "%s/%s", genarkHubUrl, match->hubUrl); slAddHead(&ret, gHubMatchNew(match->gcAccession, hubUrl, match->asmName, match->scientificName, match->commonName, -1)); + if (c > GENARK_LIMIT) + break; } if (ret) slReverse(&ret); return ret; } static struct gHubMatch *filterAssemblyListMatches(struct sqlConnection *conn, char *asmListTable, char *term, char *genarkPrefix, boolean wildCard) { struct gHubMatch *ret = NULL; struct dyString *query = dyStringNew(64); /* LIMIT of 100 will allow enough results to include some genArk assemblies */ if (wildCard) sqlDyStringPrintf(query, "SELECT * FROM %s WHERE MATCH(name, commonName, scientificName, clade, description, refSeqCategory, versionStatus, assemblyLevel) AGAINST ('%s*' IN BOOLEAN MODE) AND browserExists=1 ORDER BY priority LIMIT 100", asmListTable, term); else @@ -984,31 +991,31 @@ struct sqlResult *sr = sqlGetResult(conn, query->string); dyStringFree(&query); char **row; int c = 0; while ((row = sqlNextRow(sr)) != NULL) { struct assemblyList *el = assemblyListLoadWithNull(row); if (isGenArk(el->name)) { ++c; char genarkUrl[PATH_MAX]; safef(genarkUrl, sizeof(genarkUrl), "%s/%s", genarkPrefix, el->hubUrl); slAddHead(&ret, gHubMatchNew(el->name, genarkUrl, NULL, el->scientificName, el->commonName, *el->priority)); } - if ( c > 20 ) /* allow only 20 genArk returns */ + if ( c > GENARK_LIMIT) /* limit genArk returns */ break; } sqlFreeResult(&sr); if (ret) slReverse(&ret); return ret; } /* static struct gHubMatch *filterAssemblyListMatche */ static struct gHubMatch *searchGenark(char *term) /* Search through the genark table (or assemblyList table) for hubs matches term */ { char *genarkPrefix = cfgOption("genarkHubPrefix"); if (genarkPrefix == NULL)