Re: [gentoo-portage-dev] [PATCH] emerge: add --fuzzy-search and --search-similarity (bug 65566)

2016-08-08 Thread Zac Medico
On 08/08/2016 02:22 AM, Alexander Berntsen wrote:
> LGTM. Thanks for addressing my previous concerns.

Thanks, pushed:

https://gitweb.gentoo.org/proj/portage.git/commit/?id=b7f0937a811ef4859333ccc45f8076dca109dc2f
-- 
Thanks,
Zac



Re: [gentoo-portage-dev] [PATCH] emerge: add --fuzzy-search and --search-similarity (bug 65566)

2016-08-08 Thread Alexander Berntsen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

LGTM. Thanks for addressing my previous concerns.

- -- 
Alexander
berna...@gentoo.org
https://secure.plaimi.net/~alexander
-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iQIcBAEBCgAGBQJXqE9jAAoJENQqWdRUGk8B4m8QAJyQ7AicdYPGvF8pnIsGafKf
uOXfVRh+jN87y8flu96+6a+SguwwjI1NW2mZdOTheXWW9nBzMDLdeMfUuuuwx0EW
syZpGxeQRFXJBIzuMLlyDRX01yLNMRhyzpaI+pxqz2T2yuCh4SqQ2a2qabzkhn7h
l13OAhhNHBJuoDWXAc5tdHMZvW02/KQr6ims8RhZL83Kdx4789gtfWQgkaZrEDy6
3rUt35h56UDoVSlvN0MDMIAEsozPvdbhAzz85/PtEAP0oeYRTRMRS6ppGqRtspQY
OEu/LcP5nQH9f+LiAg+F0XUiw9Bm1gVLQy+ZFQijFp5HUCNR3xYx7SpkQauiMDsf
1nJiagHJOz4vHH3yvzCRHnqLz2RnjdGEacQLNI7j36NpfsofIgUKwQefKraYIOgq
PUfEInIha1wv+cPIQx3CdzT7O8LKBdt5G3GsqkvKrSkgOWSReO33C8U14VNsYvjr
8c/9nenIyZSWTbDzZ4vq505j393bsHjOn63yCR9ILcPLXS0x0mkK3E8pQTG67p4o
JFdPGiX80SsrYN3hLbDNsnlWObfTL4Hc7iLuyZxrS+5NLbO1e9qBNFoD2DhTAuK5
gwE+li5uKduI8VAkdjGe72CnR6vPWTAHWkCjrX3FZDW6kE9YtkOUAjEpeMTMu706
IzvSyZiEBv9+nnmNjPw0
=fZcj
-END PGP SIGNATURE-



[gentoo-portage-dev] [PATCH] emerge: add --fuzzy-search and --search-similarity (bug 65566)

2016-07-24 Thread Zac Medico
Add --fuzzy-search option, and --search-similarity option to adjust
the minimum similarity for search results (defaults to 80%).

X-Gentoo-bug: 65566
X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=65566
---
 man/emerge.1   | 14 ++
 pym/_emerge/actions.py |  7 +--
 pym/_emerge/main.py| 32 +++-
 pym/_emerge/search.py  | 26 --
 4 files changed, 74 insertions(+), 5 deletions(-)

diff --git a/man/emerge.1 b/man/emerge.1
index da1d852..7442220 100644
--- a/man/emerge.1
+++ b/man/emerge.1
@@ -565,6 +565,14 @@ packages (fetch things from SRC_URI based upon USE 
setting).
 Instead of doing any package building, just perform fetches for all
 packages (fetch everything in SRC_URI regardless of USE setting).
 .TP
+.BR "\-\-fuzzy\-search [ y | n ]"
+Enable or disable fuzzy search for search actions. When fuzzy search
+is enabled, a result is returned if it is sufficiently similar to the
+search string, without requiring an exact match. This option is enabled
+by default. Fuzzy search does not support regular expressions, therefore
+it is automatically disabled for regular expression searches. Fuzzy
+search is slightly slower than non\-fuzzy search.
+.TP
 .BR "\-\-getbinpkg [ y | n ] (\-g short option)"
 Using the server and location defined in \fIPORTAGE_BINHOST\fR (see
 \fBmake.conf\fR(5)), portage will download the information from each binary
@@ -874,6 +882,12 @@ enabled by default. The search index needs to be 
regenerated by
 to \fBEMERGE_DEFAULT_OPTS\fR (see \fBmake.conf\fR(5)) and later
 overridden via the command line.
 .TP
+.BR "\-\-search\-similarity PERCENTAGE"
+Set the minimum similarity percentage (a floating-point number between
+0 and 100). Search results with similarity percentages lower than this
+are discarded (default: \'80\'). This option has no effect unless the
+\fB\-\-fuzzy\-search\fR option is enabled.
+.TP
 .BR "\-\-select [ y | n ] (\-w short option)"
 Add specified packages to the world set (inverse of
 \fB\-\-oneshot\fR). This is useful if you want to
diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
index 1dc2b0d..6704afc 100644
--- a/pym/_emerge/actions.py
+++ b/pym/_emerge/actions.py
@@ -1,4 +1,4 @@
-# Copyright 1999-2015 Gentoo Foundation
+# Copyright 1999-2016 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from __future__ import division, print_function, unicode_literals
@@ -1974,7 +1974,10 @@ def action_search(root_config, myopts, myfiles, spinner):
spinner, "--searchdesc" in myopts,
"--quiet" not in myopts, "--usepkg" in myopts,
"--usepkgonly" in myopts,
-   search_index = myopts.get("--search-index", "y") != "n")
+   search_index=myopts.get("--search-index", "y") != "n",
+   search_similarity=myopts.get("--search-similarity"),
+   fuzzy=myopts.get("--fuzzy-search") != "n",
+   )
for mysearch in myfiles:
try:
searchinstance.execute(mysearch)
diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py
index 0e672a2..eae1954 100644
--- a/pym/_emerge/main.py
+++ b/pym/_emerge/main.py
@@ -1,4 +1,4 @@
-# Copyright 1999-2015 Gentoo Foundation
+# Copyright 1999-2016 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from __future__ import print_function
@@ -141,6 +141,7 @@ def insert_optional_args(args):
'--deselect' : y_or_n,
'--binpkg-respect-use'   : y_or_n,
'--fail-clean'   : y_or_n,
+   '--fuzzy-search' : y_or_n,
'--getbinpkg': y_or_n,
'--getbinpkgonly': y_or_n,
'--jobs'   : valid_integers,
@@ -458,6 +459,11 @@ def parse_opts(tmpcmdline, silent=False):
"choices" : true_y_or_n
},
 
+   "--fuzzy-search": {
+   "help": "Enable or disable fuzzy search",
+   "choices": true_y_or_n
+   },
+
"--ignore-built-slot-operator-deps": {
"help": "Ignore the slot/sub-slot := operator parts of 
dependencies that have "
"been recorded when packages where built. This 
option is intended "
@@ -658,6 +664,12 @@ def parse_opts(tmpcmdline, silent=False):
"choices": y_or_n
},
 
+   "--search-similarity": {
+   "help": ("Set minimum similarity percentage for fuzzy 
seach "
+   "(a floating-point number between 0 and 100)"),
+   "action": "store"
+   },
+
"--select": {
"shortopt" : "-w",