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",