Class: Wurk::Web::Search
- Inherits:
-
Object
- Object
- Wurk::Web::Search
- Defined in:
- lib/wurk/web/search.rb
Overview
Pro feature parity: substring search across queues / retries / scheduled / dead. Spec: docs/target/sidekiq-pro.md §10.1 (“Search box on Retry/Scheduled/Dead pages, substring across job payload via ZSCAN”). Wurk ships it free, extended to also cover the queue LIST.
ZSET stores use ‘ZSCAN MATCH needle` (the substring is literal, wrapped in glob stars — Redis matches the raw JSON payload). The queue LIST falls back to a paged LRANGE filter since LIST has no SCAN.
Result shape mirrors ‘Wurk::Api::Serializers#sorted_entry` so the SPA renders search hits with the same component as a sorted-set row.
Constant Summary collapse
- DEFAULT_LIMIT =
100- MAX_LIMIT =
500- KINDS =
%w[queues retry scheduled dead].freeze
- QUEUE_PAGE =
50- ZSCAN_PAGE =
200
Instance Attribute Summary collapse
-
#kinds ⇒ Object
readonly
Returns the value of attribute kinds.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#substring ⇒ Object
readonly
Returns the value of attribute substring.
Instance Method Summary collapse
-
#each ⇒ Object
Streams matching hits across every selected store.
-
#initialize(substring, kinds: KINDS, limit: DEFAULT_LIMIT) ⇒ Search
constructor
A new instance of Search.
- #to_a ⇒ Object
Constructor Details
#initialize(substring, kinds: KINDS, limit: DEFAULT_LIMIT) ⇒ Search
Returns a new instance of Search.
30 31 32 33 34 35 |
# File 'lib/wurk/web/search.rb', line 30 def initialize(substring, kinds: KINDS, limit: DEFAULT_LIMIT) @substring = substring.to_s @kinds = (Array(kinds).map(&:to_s) & KINDS) @kinds = KINDS.dup if @kinds.empty? @limit = limit.to_i.clamp(1, MAX_LIMIT) end |
Instance Attribute Details
#kinds ⇒ Object (readonly)
Returns the value of attribute kinds.
28 29 30 |
# File 'lib/wurk/web/search.rb', line 28 def kinds @kinds end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
28 29 30 |
# File 'lib/wurk/web/search.rb', line 28 def limit @limit end |
#substring ⇒ Object (readonly)
Returns the value of attribute substring.
28 29 30 |
# File 'lib/wurk/web/search.rb', line 28 def substring @substring end |
Instance Method Details
#each ⇒ Object
Streams matching hits across every selected store. Stops at ‘limit`. Yields Hashes shaped like sorted_entry payloads with an extra `:kind` discriminator + `:name` (queue name or set name).
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wurk/web/search.rb', line 40 def each(&) return enum_for(:each) unless block_given? return if @substring.empty? emitted = 0 each_hit do |row| yield row emitted += 1 break if emitted >= @limit end end |
#to_a ⇒ Object
52 53 54 |
# File 'lib/wurk/web/search.rb', line 52 def to_a each.to_a end |