748b06ac95ff2a3957be3845bd3594984e3cc3cf chmalee Wed Aug 17 19:21:48 2022 -0700 Rename test cgi to official name. Always search everything, only show categories that have matches in the result list. Add /search endpoint to hubApi, add code to search help docs in hgSuggest but don't call it yet in autoComplete.js. Minor fixups so search result links work correctly. Fixing up old programs that call hgPositionsFind diff --git src/hg/hgSuggest/hgSuggest.c src/hg/hgSuggest/hgSuggest.c index f073de4..8085dd7 100644 --- src/hg/hgSuggest/hgSuggest.c +++ src/hg/hgSuggest/hgSuggest.c @@ -1,33 +1,36 @@ /* hgGeneSuggest - suggest a gene. */ /* Copyright (C) 2013 The Regents of the University of California * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */ #include "common.h" #include "jksql.h" #include "hdb.h" #include "cheapcgi.h" #include "htmshell.h" #include "dystring.h" #include "jsonParse.h" #include "jsonWrite.h" #include "suggest.h" #include "genbank.h" +#include "hgFind.h" +#include "trix.h" // Optional CGI param type can specify what kind of thing to suggest (default: gene) #define ALT_OR_PATCH "altOrPatch" +#define HELP_DOCS "helpDocs" void suggestGene(char *database, char *table, char *prefix) /* Print out a Javascript list of objects describing genes that start with prefix. */ { struct dyString *str = dyStringNew(10000); dyStringPrintf(str, "[\n"); int exact = cgiOptionalInt("exact", 0); boolean hasKnownCanonical = sameString(table, "knownCanonical"); initGenbankTableNames(database); char query[2048]; if(exact) { // NOTE that exact is no longer used by the UI as of v271, but there are still some robots // using it so we still support it. @@ -212,62 +215,89 @@ { struct slPair *aliasMatches = queryChromAlias(conn, term, TRUE); writeValLabelMatches(jw, aliasMatches, ""); if (aliasMatches == NULL) { struct slPair *aliasMatches = queryChromAlias(conn, term, FALSE); writeValLabelMatches(jw, aliasMatches, ""); } } hFreeConn(&conn); jsonWriteListEnd(jw); puts(jw->dy->string); jsonWriteFree(&jw); } +void suggestHelpPage(char *prefix) +/* Print out a Javascript list of objects describing help pages that start with prefix. */ +{ +struct jsonWrite *jw = jsonWriteNew(); +jsonWriteListStart(jw, NULL); +char *lowered = cloneString(prefix); +char *keyWords[16]; +int keyCount; +tolowers(lowered); +keyCount = chopLine(lowered, keyWords); +struct trix *helpTrix = openStaticTrix(helpDocsTrix); +struct trixSearchResult *tsr, *tsrList = trixSearch(helpTrix, keyCount, keyWords, tsmExpand); +int i; +for (i = 0, tsr = tsrList; i < 25 && tsr != NULL; i++, tsr = tsr->next) + { + jsonWriteObjectStart(jw, NULL); + jsonWriteString(jw, "value", tsr->itemId); // value is necessary + jsonWriteString(jw, "category", "helpDocs"); // hardcode this for client + jsonWriteObjectEnd(jw); + } +jsonWriteListEnd(jw); +puts(jw->dy->string); +jsonWriteFree(&jw); +} + char *checkParams(char *database, char *prefix, char *type) /* If we don't have valid CGI parameters, quit with a Bad Request HTTP response. */ { pushWarnHandler(htmlVaBadRequestAbort); pushAbortHandler(htmlVaBadRequestAbort); if(prefix == NULL || database == NULL) errAbort("%s", "Missing prefix and/or db CGI parameter"); if (! hDbIsActive(database)) errAbort("'%s' is not a valid, active database", htmlEncode(database)); -if (isNotEmpty(type) && differentString(type, ALT_OR_PATCH)) +if (isNotEmpty(type) && differentString(type, ALT_OR_PATCH) && differentString(type, HELP_DOCS)) errAbort("'%s' is not a valid type", type); char *table = NULL; -if (! sameOk(type, ALT_OR_PATCH)) +if (! sameOk(type, ALT_OR_PATCH) && !sameOk(type, HELP_DOCS)) { char *knownDatabase = hdbDefaultKnownDb(database); struct sqlConnection *conn = hAllocConn(knownDatabase); table = connGeneSuggestTable(conn); hFreeConn(&conn); if(table == NULL) errAbort("gene autosuggest is not supported for db '%s'", database); } popWarnHandler(); popAbortHandler(); return table; } int main(int argc, char *argv[]) { long enteredMainTime = clock1000(); cgiSpoof(&argc, argv); char *database = cgiOptionalString("db"); char *prefix = cgiOptionalString("prefix"); char *type = cgiOptionalString("type"); char *table = checkParams(database, prefix, type); puts("Content-Type:text/plain"); puts("\n"); if (sameOk(type, ALT_OR_PATCH)) suggestAltOrPatch(database, prefix); +else if (sameOk(type, HELP_DOCS)) + suggestHelpPage(prefix); else suggestGene(database, table, prefix); cgiExitTime("hgSuggest", enteredMainTime); return 0; }