27aa980683134b5ff14cbaf5bdcbe563eb4af207
tdreszer
Wed Apr 6 08:19:34 2011 -0700
Moved common name and description matching code into search lib and removed it from hgFileSearch and hgTracks/searchTracks.c
diff --git src/hg/lib/search.c src/hg/lib/search.c
index 614a28e..d43ecf1 100644
--- src/hg/lib/search.c
+++ src/hg/lib/search.c
@@ -239,15 +239,71 @@
buf,(mdbSelect->val ? (char *)mdbSelect->val: ""));
}
//else if (searchBy == cvSearchByDateRange || searchBy == cvSearchByIntegerRange)
// {
// // TO BE IMPLEMENTED
// }
dyStringPrintf(output," \n", row);
dyStringPrintf(output,"\n");
}
dyStringPrintf(output,"
|
", cols);
return dyStringCannibalize(&output);
}
+
+static boolean searchMatchToken(char *string, char *token)
+{
+// do this with regex ? Would require all sorts of careful parsing for ()., etc.
+if (string == NULL)
+ return (token == NULL);
+if (token == NULL)
+ return TRUE;
+
+if (!strchr(token,'*') && !strchr(token,'?'))
+ return (strcasestr(string,token) != NULL);
+
+char wordWild[1024];
+safef(wordWild,sizeof wordWild,"*%s*",token);
+return wildMatch(wordWild, string);
+
+}
+
+boolean searchNameMatches(struct trackDb *tdb, struct slName *wordList)
+// returns TRUE if all words in preparsed list matches short or long label
+// A "word" can be "multiple words" (parsed from quoteed string).
+{
+if (tdb->shortLabel == NULL || tdb->longLabel == NULL)
+ return (wordList != NULL);
+
+struct slName *word = wordList;
+for(; word != NULL; word = word->next)
+ {
+ if (!searchMatchToken(tdb->shortLabel,word->name)
+ && !searchMatchToken(tdb->longLabel, word->name))
+ return FALSE;
+ }
+return TRUE;
+}
+
+boolean searchDescriptionMatches(struct trackDb *tdb, struct slName *wordList)
+// returns TRUE if all words in preparsed list matches html description page.
+// A "word" can be "multiple words" (parsed from quoteed string).
+// Because description contains html, quoted string match has limits.
+// DANGER: this will alter html of tdb struct (replacing \n with ' ', so the html should not be displayed after.
+{
+if (tdb->html == NULL)
+ return (wordList != NULL);
+
+if (strchr(tdb->html,'\n'))
+ strSwapChar(tdb->html,'\n',' '); // DANGER: don't own memory. However, this CGI will use html for no other purpose
+
+struct slName *word = wordList;
+for(; word != NULL; word = word->next)
+ {
+ if (!searchMatchToken(tdb->html,word->name))
+ return FALSE;
+ }
+return TRUE;
+}
+