Add column-scoped search predicates (Fixes #776)#934
Draft
DannyStoll1 wants to merge 1 commit into
Draft
Conversation
Introduce column predicates as a general way to filter by a single field, addressing the "filter processes of a user" request without a special-purpose flag: `procs user==root` shows only root's processes, `procs command~=dockerd` matches a substring of the command. A search keyword now parses into either a plain keyword (matched against every searchable column, as before) or a `<column><op><value>` predicate: == exact, full-string match ~= substring match The column name resolves case-insensitively against the existing column kinds, and a predicate matches its target column regardless of that column's numeric_search/nonnumeric_search flags (so `pid==1` works). Predicates are ordinary terms, so they compose with plain keywords and the existing `--and`/`--or`/`--nand`/`--nor` logic: procs --and user==root command~=dockerd Internally, `View::filter` is refactored from combining numeric/nonnumeric keyword groups to a per-term fold. Each term compiles to the set of columns it searches plus the operator, then the active logic folds per-term results. This is equivalent to the previous behavior for plain keywords and generalizes cleanly to predicates. Unknown column names and columns absent from the active layout are reported as errors before output. Predicate parsing is disabled in --regex mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds column-scoped search predicates, giving a general way to filter by a single field. This resolves #776 ("filter processes of a user") without a special-purpose flag:
Behavior
A search keyword now parses into either a plain keyword (matched against every searchable column, as before) or a
<column><op><value>predicate:==: exact, full-string match~=: substring matchDetails:
The column name resolves case-insensitively against the existing column kinds (a substring is enough, e.g.
user,command,pid).A predicate matches its target column regardless of that column's
numeric_search/nonnumeric_searchflags, sopid==1works even when Pid is not otherwise searchable.Only the value after the operator may contain further
=characters; the leftmost operator splits the token.Predicates are ordinary search terms, so they compose with plain keywords and with
--and/--or/--nand/--nor:procs --and user==root command~=dockerdUnknown column names, and columns absent from the active layout, are reported as errors before any output.
Predicate parsing is disabled in
--regexmode, where the pattern is taken verbatim.Implementation
View::filter's matching is extracted into aSearchtype that compiles the keywords once (regex, or a set of per-column terms) and exposesmatches(pid). Plain-keyword matching folds per-term results with the active logic; this is equivalent to the previous numeric/nonnumeric group combine, verified for all four logic modes.View::filtershrinks from ~200 lines to ~70.Tests
=, unknown/empty column).run_defaultmirroring the existing search tests, plus error cases.Docs updated: README (new subsection + feature bullet), man page, and CHANGELOG.