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/lib/trix.c src/lib/trix.c index 83d18e3..e02810e 100644 --- src/lib/trix.c +++ src/lib/trix.c @@ -1,29 +1,30 @@ /* trix - text retrieval index. Stuff for fast two level index * of text for fast word searches. */ /* 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 "hash.h" #include "linefile.h" #include "trix.h" #include "sqlNum.h" #include "udc.h" #include "net.h" #include "rangeTree.h" +#include "portable.h" /* Some local structures for the search. */ struct trixHitPos /* A hit to the index. */ { struct trixHitPos *next; /* Next in list */ char *itemId; /* Associated itemId */ int wordIx; /* Which word this is part of. */ int leftoverLetters; /* Number of letters at end of word not matched */ }; struct trixWordResult /* Results of a search on one word. */ { struct trixWordResult *next; @@ -858,31 +859,31 @@ static struct rbTree *wordPosToRangeTree(int *intList, int len) /* Convert an array of integers to a range tree with 10 context around each int */ { struct rbTree *rt = rangeTreeNew(); int i; for (i = 0; i < len; i++) { int temp = intList[i] - 10; if (temp < 0) temp = 0; rangeTreeAdd(rt, temp, intList[i]+10); } return rt; } -static void addSnippetForResult(struct trixSearchResult *tsr, struct trix *trix) +void addSnippetForResult(struct trixSearchResult *tsr, struct trix *trix) /* Find the snippet for a search result */ { struct snippetIndex *snippetIndex = trix->snippetIndex; char *ourDocId = tsr->itemId; static struct dyString *snippet = NULL; if (snippet == NULL) snippet = dyStringNew(0); else dyStringClear(snippet); off_t origFileOffset = 0, offsetFilePos = trixFindIndexStartLine(snippetIndex->ixx, snippetIndex->ixxSize, ourDocId); ourSeek(trix, snippetIndex->textIndex, offsetFilePos); char *snippetIxLine, *origTextLine; char *thisDocId; while (ourReadLine(trix, snippetIndex->textIndex, &snippetIxLine)) { @@ -929,25 +930,31 @@ else break; } else if (!didEllipse) { didEllipse = TRUE; dyStringPrintf(snippet, " ... "); } } tsr->snippet = dyStringCannibalize(&snippet); break; } } } -void addSnippetsToSearchResults(struct trixSearchResult *tsrList, struct trix *trix) -/* Add a snippet to the search result */ +void initSnippetIndex(struct trix *trix) +/* Setup what we need to obtain snippets */ { trixPrefixSize = 15; initCharTables(); openSnippetIndex(trix); +} + +void addSnippetsToSearchResults(struct trixSearchResult *tsrList, struct trix *trix) +/* Add snippets to each search result in tsrList */ +{ +initSnippetIndex(trix); struct trixSearchResult *tsr; for (tsr = tsrList; tsr != NULL; tsr = tsr->next) addSnippetForResult(tsr, trix); }