diff options
-rw-r--r-- | cgi.c | 1 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | mansearch.c | 8 | ||||
-rw-r--r-- | mansearch.h | 1 |
4 files changed, 14 insertions, 0 deletions
@@ -977,6 +977,7 @@ pg_search(const struct req *req) search.sec = req->q.sec; search.outkey = "Nd"; search.argmode = req->q.equal ? ARG_NAME : ARG_EXPR; + search.firstmatch = 1; paths.sz = 1; paths.paths = mandoc_malloc(sizeof(char *)); @@ -294,6 +294,10 @@ main(int argc, char *argv[]) if (argc == 0) usage(search.argmode); + if (search.argmode == ARG_NAME && + outmode == OUTMODE_ONE) + search.firstmatch = 1; + /* Access the mandoc database. */ manpath_parse(&paths, conf_file, defpaths, auxpaths); diff --git a/mansearch.c b/mansearch.c index 1d94937c..521f78de 100644 --- a/mansearch.c +++ b/mansearch.c @@ -352,6 +352,14 @@ mansearch(const struct mansearch *search, sqlite3_finalize(s2); sqlite3_close(db); ohash_delete(&htab); + + /* + * In man(1) mode, prefer matches in earlier trees + * over matches in later trees. + */ + + if (cur && search->firstmatch) + break; } qsort(*res, cur, sizeof(struct manpage), manpage_compare); rc = 1; diff --git a/mansearch.h b/mansearch.h index 7e40ef45..44b6858a 100644 --- a/mansearch.h +++ b/mansearch.h @@ -94,6 +94,7 @@ struct mansearch { const char *sec; /* mansection/NULL */ const char *outkey; /* show content of this macro */ enum argmode argmode; /* interpretation of arguments */ + int firstmatch; /* first matching database only */ }; __BEGIN_DECLS |