af3a143571e5aa064eab75c34f9444b35413b562 chmalee Tue Nov 30 15:28:15 2021 -0800 Add snippet support to trix searching. Required changing the wordPos from the first highest matching wordIndex to the wordIndex of the actual span. Have trixContextIndex create a second level index for fast retrieval of line offsets in original text file used by ixIxx. Create a simple UI for navigating hgFind search results. diff --git src/index/trixSearch/trixSearch.c src/index/trixSearch/trixSearch.c index 5d3d30d..831a452 100644 --- src/index/trixSearch/trixSearch.c +++ src/index/trixSearch/trixSearch.c @@ -17,73 +17,84 @@ "usage:\n" " trixSearch file word(s)\n" "options:\n" " -maxReturn=%d - maximum number of matches to return\n" " -full - return additional search information rather than just ordered list of matching IDs\n" , maxReturn ); } static struct optionSpec options[] = { {"maxReturn", OPTION_INT}, {"full", OPTION_BOOLEAN}, {NULL, 0}, }; -void dumpTsList(struct trixSearchResult *tsList) +void dumpTsList(struct trixSearchResult *tsList, int showCount, int matchCount) /* Dump out contents of tsList to stdout. */ { struct trixSearchResult *ts; -int matchCount = slCount(tsList); -int showCount = min(matchCount, maxReturn); -int ix=0; if (full) { printf("#showing %d of %d matches\n", showCount, matchCount); - printf("#identifier\tspan\tordered\tpos\n"); + printf("#identifier\tunordered_span\tordered_span\tpos\tsnippet\n"); } -for (ts = tsList, ix=0; ts != NULL && ixnext, ++ix) +for (ts = tsList; ts != NULL; ts = ts->next) { if (full) { printf("%s\t%d\t", ts->itemId, ts->unorderedSpan); if (ts->orderedSpan == BIGNUM) printf("n/a"); else printf("%d", ts->orderedSpan); - printf("\t%d\n", ts->wordPos); + int i = 0; + printf("\t"); + for (i = 0; i < ts->wordPosSize; i++) + { + printf("%d", ts->wordPos[i]); + if (i + 1 < ts->wordPosSize) + printf(","); + } + printf("\t%s\n",ts->snippet); } else printf("%s\n", ts->itemId); } } void trixSearchCommand(char *inFile, int wordCount, char *words[]) /* trixSearchCommand - search trix free text index from command line. */ { struct trix *trix; char ixFile[PATH_LEN]; struct trixSearchResult *tsList; int i; safef(ixFile, sizeof(ixFile), "%s.ix", inFile); for (i=0; inext = NULL; +addSnippetsToSearchResults(tsList, trix); +dumpTsList(tsList, showCount, matchCount); trixSearchResultFreeList(&tsList); trixClose(&trix); } int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); if (argc < 3) usage(); maxReturn = optionInt("maxReturn", maxReturn); full = optionExists("full"); trixSearchCommand(argv[1], argc-2, argv+2); return 0; }