extern RuntimeData gData;
extern Settings gSettings;
+void ZyppSearchOptions::resolveConflicts() {
+ if (matchExact()) {
+ // --match-all does not make sense here
+ setMatchAny();
+ // the same goes for search in descriptions
+ setSearchDescriptions(false);
+ }
+
+ // ??? should we notify user about conflict resolutions?
+}
+
ZyppSearch::ZyppSearch (const ZyppSearchOptions & options, const vector<string> & qstrings) :
_options(options), _qstrings(qstrings) {
init();
void ZyppSearch::doSearch(Table & table) {
ResPool pool = getZYpp()->pool();
- setupRegexp();
-
// search for specific resolvable type only
if (_options.kind() != Resolvable::Kind()) {
+ setupRegexp();
for (ResPool::byKind_iterator it = pool.byKindBegin(_options.kind());
it != pool.byKindEnd(_options.kind()); ++it) {
if (match(*it)) table << createRow(*it);
}
}
- // search for all resolvables
+ // search for exact package using byName_iterator
+ // usable only if there is only one query string and if this string
+ // doesn't contain wildcards
+ if (_options.matchExact() && _qstrings.size() == 1 &&
+ _qstrings[0].find('*') == string::npos &&
+ _qstrings[0].find('?') == string::npos) {
+ for (ResPool::byName_iterator it = pool.byNameBegin(_qstrings[0]);
+ it != pool.byNameEnd(_qstrings[0]); ++it) {
+ table << createRow(*it);
+ }
+ }
+ // search among all resolvables
else {
+ setupRegexp();
for (ResPool::const_iterator it = pool.begin(); it != pool.end(); ++it) {
if (match(*it)) table << createRow(*it);
}
string regstr;
if (_qstrings.size() == 0) regstr = ".*";
- else if (_qstrings.size() == 1)
- regstr = ".*" + WB + wildcards2regex(_qstrings[0]) + WB + ".*";
+ else if (_qstrings.size() == 1) {
+ if (_options.matchExact())
+ regstr = wildcards2regex(_qstrings[0]);
+ else
+ regstr = ".*" + WB + wildcards2regex(_qstrings[0]) + WB + ".*";
+ }
else {
vector<string>::const_iterator it = _qstrings.begin();
if (_options.matchAll())
regstr = "(?=.*" + WB + wildcards2regex(*it) + WB + ")";
- else
- regstr = ".*" + WB + "(" + wildcards2regex(*it);
+ else {
+ if (!_options.matchExact()) regstr = ".*";
+ regstr += WB + "(" + wildcards2regex(*it);
+ }
++it;
if (_options.matchAll())
regstr += ".*";
- else
- regstr += ")" + WB + ".*";
+ else {
+ regstr += ")" + WB;
+ if (!_options.matchExact()) regstr += ".*";
+ }
}
cerr_vv << "using regex: " << regstr << endl;
_match_words(false), _kind(zypp::Resolvable::Kind())
{}
+ void resolveConflicts();
+
bool installedOnly() const { return _installed_only; }
bool uninstalledOnly() const { return _uninstalled_only; }
bool matchAll() const { return _match_all; }
bool matchAny() const { return !_match_all; }
bool matchWords() const { return _match_words; }
+ bool matchExact() const { return _match_exact; }
bool searchDescriptions() const { return _search_descriptions; }
bool caseSensitive() const { return _case_sensitive; }
zypp::Resolvable::Kind kind() const { return _kind; }
void setMatchAll(const bool match_all = true) { _match_all = match_all; }
void setMatchAny(const bool match_any = true) { _match_all = !match_any; }
void setMatchWords(const bool match_words = true) { _match_words = match_words; }
+ void setMatchExact(const bool match_exact = true) { _match_exact = match_exact; }
void setSearchDescriptions(const bool search_descriptions = true) { _search_descriptions = search_descriptions; }
void setCaseSensitive(const bool case_sensitive = true) { _case_sensitive = case_sensitive; }
void setKind(const zypp::Resolvable::Kind & kind) { _kind = kind; }
bool _uninstalled_only;
bool _match_all;
bool _match_words;
+ bool _match_exact;
bool _search_descriptions;
bool _case_sensitive;
zypp::Resolvable::Kind _kind;
{"match-any", no_argument, 0, 0},
{"match-substrings", no_argument, 0, 0},
{"match-words", no_argument, 0, 0},
+ {"match-exact", no_argument, 0, 0},
{"search-descriptions", no_argument, 0, 'd'},
{"case-sensitive", no_argument, 0, 'c'},
{"type", required_argument, 0, 't'},
" --match-any Search for a match to any of the search strings\n"
" --match-substrings Matches for search strings may be partial words (default)\n"
" --match-words Matches for search strings may only be whole words\n"
+ " --match-exact Searches for an exact package name\n"
"-d, --search-descriptions Search also in package summaries and descriptions.\n"
"-c, --case-sensitive Perform case-sensitive search.\n"
"-i, --installed-only Show only packages that are already installed.\n"
"-t, --type Search only for packages of specified type.\n"
" --sort-by-name Sort packages by name (default).\n"
" --sort-by-catalog Sort packages by catalog.\n" // ??? catalog/source?
+ "\n"
+ "* and ? wildcards can also be used within search strings.\n"
;
}
else {
if (copts.count("installed-only")) options.setInstalledOnly();
if (copts.count("match-any")) options.setMatchAny();
if (copts.count("match-words")) options.setMatchWords();
+ if (copts.count("match-exact")) options.setMatchExact();
if (copts.count("search-descriptions")) options.setSearchDescriptions();
if (copts.count("case-sensitive")) options.setCaseSensitive();
}
options.setKind(kind);
}
+
+ options.resolveConflicts();
Table t;
t.style(Ascii);