5b8fdca0d6014f4b2f363724ee91f096ef62eae5 chmalee Thu Sep 30 12:21:57 2021 -0700 Get hub track selection box and hgTrackUi links working on track search diff --git src/hg/lib/hubSearchText.c src/hg/lib/hubSearchText.c index 5442219..aab9395 100644 --- src/hg/lib/hubSearchText.c +++ src/hg/lib/hubSearchText.c @@ -286,61 +286,61 @@ dyStringPrintf(modifiedTerms, "+%s ", hyphenatedTerms[j]); else { dyStringPrintf(modifiedTerms, "+%s* ", hyphenatedTerms[j]); } } } return dyStringCannibalize(&modifiedTerms); } void getHubSearchResults(struct sqlConnection *conn, char *hubSearchTableName, char *hubSearchTerms, bool checkLongText, char *dbFilter, struct hash *hubLookup, struct hash **searchResultHashRet, struct slName **hubsToPrintRet, char *extra) /* Find hubs, genomes, and tracks that match the provided search terms. * Return all hits that satisfy the (optional) supplied assembly filter. - * if checkLongText is FALSE, skip searching within the long description text entries */ + * if checkLongText is FALSE, skip searching within the long description text entries + * the string 'extra' is used for additional mysql filter(s) by the caller and + * must be escaped by them */ { char *cleanSearchTerms = cloneString(hubSearchTerms); if (isNotEmpty(cleanSearchTerms)) tolowers(cleanSearchTerms); bool isStrictSearch = FALSE; char *modifiedSearchTerms = modifyTermsForHubSearch(cleanSearchTerms, isStrictSearch); struct hubSearchText *hubSearchResultsList = NULL; struct dyString *query = dyStringNew(100); char *noLongText = NULL; if (!checkLongText) - noLongText = cloneString("textLength = 'Short' and"); + noLongText = cloneString("textLength = 'Short'"); else noLongText = cloneString(""); sqlDyStringPrintf(query, "select * from %s where ", hubSearchTableName); -// sqlDyStringPrintf complains about spaces in %s strings and -// extra has already been escaped so add it on here -dyStringPrintf(query, "%s %s", noLongText, extra); -if (isNotEmpty(modifiedSearchTerms)) - { +// caller has manually escaped extra, so safe to dyStringPrintf: if (isNotEmpty(extra)) + dyStringPrintf(query, "%s %s", extra, + (isNotEmpty(noLongText) || isNotEmpty(modifiedSearchTerms)) ? "and ": ""); +if (isNotEmpty(noLongText)) + dyStringPrintf(query, "%s %s", noLongText, isNotEmpty(modifiedSearchTerms) ? "and " : ""); +if (isNotEmpty(modifiedSearchTerms)) { - sqlDyStringPrintf(query, " and "); - } sqlDyStringPrintf(query, "match(text) against ('%s' in boolean mode)" " order by match(text) against ('%s' in boolean mode)", modifiedSearchTerms, modifiedSearchTerms); } - struct sqlResult *sr = sqlGetResult(conn, dyStringContents(query)); char **row; while ((row = sqlNextRow(sr)) != NULL) { struct hubSearchText *hst = hubSearchTextLoadWithNullGiveContext(row, cleanSearchTerms); // Skip rows where the long text matched the more lax MySQL search (punctuation just // splits terms into two words, so "rna-seq" finds "rna" and "seq" separately, but // not the more strict rules used to find context for the search terms. if ((hst->textLength == hubSearchTextLong) && isEmpty(hst->text)) continue; char *hubUrl = hst->hubUrl; struct hubEntry *hubInfo = hashFindVal(hubLookup, hubUrl); if (hubInfo == NULL) continue; // Search table evidently includes a hub that's not on this server. Skip it. char *db = cloneString(hst->db);