e5297f22c5d7c1cb0b041b0ea4c66206a244c90b hiram Mon Sep 30 10:36:52 2024 -0700 add multiple word search to the hgGateway assembly search box function refs #32596 diff --git src/hg/lib/assemblyList.c src/hg/lib/assemblyList.c index 0010c69..1830b71 100644 --- src/hg/lib/assemblyList.c +++ src/hg/lib/assemblyList.c @@ -405,15 +405,55 @@ /* -------------------------------- End autoSql Generated Code -------------------------------- */ static char *_assemblyListTableName = NULL; char *assemblyListTableName() /* return the assemblyList table name from the environment, * or hg.conf, or use the default. Cache the result */ { if (_assemblyListTableName == NULL) _assemblyListTableName = cfgOptionEnvDefault("HGDB_ASSEMBLYLIST_STATUS_TABLE", assemblyListTableConfVariable, defaultAssemblyListTableName); return _assemblyListTableName; } + +char *asmListMatchAllWords(char *searchString) +/* given a multiple word search string, fix it up so it will be + * a 'match all words' MySQL FULLTEXT query, with the required + signs + * in front of the words when appropriate + */ +{ +struct dyString *allWords = dyStringNew(64); +int wordCount = wordCount = chopByWhite(searchString, NULL, 0); +/* single word ? simply return it, doesn't need anything */ +if (1 == wordCount) + dyStringPrintf(allWords, "%s", searchString); +else + { + char **words; + AllocArray(words, wordCount); + (void) chopByWhite(searchString, words, wordCount); + boolean inQuote = FALSE; + for (int i = 0; i < wordCount; ++i) + { + if (inQuote) + { + dyStringPrintf(allWords, " %s", words[i]); + if ('"' == lastChar(words[i])) + inQuote = FALSE; + } + else if ('"' == words[i][0]) + { /* "quoted string" becomes: +"quoted string" */ + dyStringPrintf(allWords, " +%s", words[i]); + inQuote = TRUE; + } + else if ('+' == words[i][0] || '-' == words[i][0]) + dyStringPrintf(allWords, " %s", words[i]); /* nothing needed */ + else + dyStringPrintf(allWords, " +%s", words[i]); /* add + to all words */ + } + } +/* trimSpaces will remove any leading or trailing white space */ +return trimSpaces(dyStringCannibalize(&allWords)); +}