This script manages the HTTP requests for free-text search.
filename_matches ($filetext, $advanced, $casesensitive, $file)
Function filename_matches
tells if search results for $file should be kept for display.
$filetext
a string containing the desired name fragment or pattern
$advanced
an integer equal to 1 if $filetext
is a pattern, 0 otherwise
$casesensitive
an integer equal to 1 if comparison is case-sensitive, 0 otherwise
$file
a string containing the filename to check
Result is 1 if fragment $filetext
is present (either as a substring or a matching pattern) inside filename $file
.
glimpsesearch ($searchtext, $filetext, $advanced, $casesensitive)
Function glimpsesearch
searches the tree with glimpse.
$searchtext
a string containing the text to look for
$filetext
a string containing the desired name fragment or pattern
$advanced
an integer equal to 1 if $filetext
is a pattern, 0 otherwise
$casesensitive
an integer equal to 1 if comparison is case-sensitive, 0 otherwise
Glimpse is launched to search the source-tree for the string given. Results are then filtered on the optional filename. The remaining hits are returned in an array.
swishsearch ($searchtext, $filetext, $advanced, $casesensitive)
Function swishsearch
searches the tree with Swish-e.
$searchtext
a string containing the text to look for
$filetext
a string containing the desired name fragment or pattern
$advanced
an integer equal to 1 if $filetext
is a pattern, 0 otherwise
$casesensitive
an integer equal to 1 if comparison is case-sensitive, 0 otherwise
Swish-e is launched to search the source-tree for the string given. Results are then filtered on the optional filename. The remaining hits are returned in an array.
checkvalidref ($file)
Function checkvalidref
is a "$variable" substitution function. It returns CSS class name searchinvalid
if the file timestamp is incorrect, meaning the file has been modified after genxref indexing. Otherwise, it returns an empty string.
$file
a string containing the filename to check
Since the search engines return OS-relative path, the filename must be prefixed with a / to observe LXR file designation rule.
printresults ($templ, $searchtext, @results)
Function printresults
is a "$function" substitution function. It returns an HTML string which is the concatenation of its expanded argument applied to every search result.
$templ
a string containing the template (i.e. argument)
$searchtext
a string containing the looked-for text
@results
an array containing the search results
Because of the different nature of the results, processing is split depending on the search engines. With Glimpse, line for the hit was grabbed, while with Swish-e, only a relevance score is available.
Note:
Both search engines start by looking into their private "index" files before accessing the source-tree files. A first consequence is any file added after genxref indexing cannot be seen and searched; there may exist unreported hits in these files. Since it looks like words are looked up in some "index" or "cache", a second consequence is new words are likely not to be reported in modified files.
For these reasons, background is highlighted for modified files.
search ()
Sub search
is the main driver for free-text search.
It dispatches search to the correct search engine, then calls the result editor.
Note:
Filename search may give inaccurate results if source-tree has been modified since last genxref indexation because search is done against an internal list captured at indexing time.
Builds the header and footer and launches search
for the real job.