Module Name:    src
Committed By:   christos
Date:           Fri Mar 29 20:37:00 UTC 2013

Modified Files:
        src/usr.sbin/makemandb: apropos-utils.c apropos.1 apropos.c

Log Message:
- Fix legacy mode to use like instead of match. This loses ranking.
- default to unlimited lines
- fix formatting of legacy mode


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/makemandb/apropos-utils.c
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/makemandb/apropos.1
cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/makemandb/apropos.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/makemandb/apropos-utils.c
diff -u src/usr.sbin/makemandb/apropos-utils.c:1.12 src/usr.sbin/makemandb/apropos-utils.c:1.13
--- src/usr.sbin/makemandb/apropos-utils.c:1.12	Fri Mar 29 16:07:31 2013
+++ src/usr.sbin/makemandb/apropos-utils.c	Fri Mar 29 16:37:00 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: apropos-utils.c,v 1.12 2013/03/29 20:07:31 christos Exp $	*/
+/*	$NetBSD: apropos-utils.c,v 1.13 2013/03/29 20:37:00 christos Exp $	*/
 /*-
  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadh...@gmail.com>
  * All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos-utils.c,v 1.12 2013/03/29 20:07:31 christos Exp $");
+__RCSID("$NetBSD: apropos-utils.c,v 1.13 2013/03/29 20:37:00 christos Exp $");
 
 #include <sys/queue.h>
 #include <sys/stat.h>
@@ -550,27 +550,21 @@ run_query(sqlite3 *db, const char *snipp
 		snippet_args = default_snippet_args;
 	}
 	if (args->legacy) {
+	    char *wild;
+	    easprintf(&wild, "%%%s%%", args->search_str);
 	    query = sqlite3_mprintf("SELECT section, name, name_desc, machine,"
-		" snippet(mandb, %Q, %Q, %Q, -1, 40 ),"
-		" rank_func(matchinfo(mandb, \"pclxn\")) AS rank"
+		" snippet(mandb, %Q, %Q, %Q, -1, 40 )"
 		" FROM mandb"
-		" WHERE name MATCH %Q "
+		" WHERE name LIKE %Q OR name_desc LIKE %Q "
 		"%s"
-		" UNION SELECT section, name, name_desc, machine,"
-		" snippet(mandb, %Q, %Q, %Q, -1, 40 ),"
-		" rank_func(matchinfo(mandb, \"pclxn\")) AS rank"
-		" FROM mandb"
-		" WHERE name_desc MATCH %Q "
-		"%s"
-		" ORDER BY rank DESC"
 		"%s",
 		snippet_args[0], snippet_args[1], snippet_args[2],
-		args->search_str,
+		wild,
 		section_clause ? section_clause : "",
 		snippet_args[0], snippet_args[1], snippet_args[2],
-		args->search_str,
 		section_clause ? section_clause : "",
 		limit_clause ? limit_clause : "");
+		free(wild);
 	} else {
 	    query = sqlite3_mprintf("SELECT section, name, name_desc, machine,"
 		" snippet(mandb, %Q, %Q, %Q, -1, 40 ),"

Index: src/usr.sbin/makemandb/apropos.1
diff -u src/usr.sbin/makemandb/apropos.1:1.9 src/usr.sbin/makemandb/apropos.1:1.10
--- src/usr.sbin/makemandb/apropos.1:1.9	Fri Mar 29 16:17:19 2013
+++ src/usr.sbin/makemandb/apropos.1	Fri Mar 29 16:37:00 2013
@@ -1,4 +1,4 @@
-.\" $NetBSD: apropos.1,v 1.9 2013/03/29 20:17:19 christos Exp $
+.\" $NetBSD: apropos.1,v 1.10 2013/03/29 20:37:00 christos Exp $
 .\"
 .\" Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadh...@gmail.com>
 .\" All rights reserved.
@@ -77,21 +77,6 @@ Turn on escape code formatting.
 .It Fl l
 Legacy mode: Only searches name and name description.
 Does not print context, or escape format the text.
-Note that this still does not behave exactly like the old
-.Nm
-did because FTS can only search for words, not partial words.
-For example
-.Nm
-used to return
-.Dq xlsfonts
-when searching for
-.Dq ls ,
-but now it cannot.
-One can approximate the behavior better by searching for
-.Dq ls*
-and this works because the index is sorted, but unfortunately
-.Dq *ls*
-does not work.
 .It Fl n
 Output up to the specified number of search results.
 The default limit is infinity.

Index: src/usr.sbin/makemandb/apropos.c
diff -u src/usr.sbin/makemandb/apropos.c:1.13 src/usr.sbin/makemandb/apropos.c:1.14
--- src/usr.sbin/makemandb/apropos.c:1.13	Fri Mar 29 16:07:31 2013
+++ src/usr.sbin/makemandb/apropos.c	Fri Mar 29 16:37:00 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: apropos.c,v 1.13 2013/03/29 20:07:31 christos Exp $	*/
+/*	$NetBSD: apropos.c,v 1.14 2013/03/29 20:37:00 christos Exp $	*/
 /*-
  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadh...@gmail.com>
  * All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos.c,v 1.13 2013/03/29 20:07:31 christos Exp $");
+__RCSID("$NetBSD: apropos.c,v 1.14 2013/03/29 20:37:00 christos Exp $");
 
 #include <err.h>
 #include <search.h>
@@ -204,7 +204,7 @@ main(int argc, char *argv[])
 	args.search_str = query;
 	args.sec_nums = aflags.sec_nums;
 	args.legacy = aflags.legacy;
-	args.nrec = aflags.nresults ? aflags.nresults : 10;
+	args.nrec = aflags.nresults ? aflags.nresults : -1;
 	args.offset = 0;
 	args.machine = aflags.machine;
 	args.callback = &query_callback;
@@ -252,7 +252,7 @@ query_callback(void *data, const char *s
 	callback_data *cbdata = (callback_data *) data;
 	FILE *out = cbdata->out;
 	cbdata->count++;
-	fprintf(out, cbdata->aflags->legacy ? "%s(%s)\t- %s\n" :
+	fprintf(out, cbdata->aflags->legacy ? "%s(%s) - %s\n" :
 	    "%s (%s)\t%s\n", name, section, name_desc);
 
 	if (cbdata->aflags->no_context == 0)

Reply via email to