commit bcf87a864c5543ee5daf459fd9466b5d92b57da4
parent cf3a2e38fcc81e0515ea0557c6f837fd3cfdb269
Author: Dan Callaghan <djc@djc.id.au>
Date: Sun, 11 Oct 2026 16:25:12 +1100
prepend type:mail to every search before parsing
The type:mail term matches everything in the index. This works around
Xapian's QueryParser refusing to parse a query containing only negated
terms.
Fixes #250.
Diffstat:
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -406,11 +406,15 @@ EOS
query = {}
subs = HookManager.run("custom-search", :subs => s) || s
+
+ subs = "type:mail #{subs}"
+
begin
subs = SearchManager.expand subs
rescue SearchManager::ExpansionError => e
raise ParseError, e.message
end
+
subs = subs.gsub(/\b(to|from):(\S+)\b/) do
field, value = $1, $2
email_field, name_field = %w(email name).map { |x| "#{field}_#{x}" }
diff --git a/test/unit/test_index.rb b/test/unit/test_index.rb
@@ -32,34 +32,58 @@ class TestIndex < Minitest::Test
parsed = with_fake_time do
Redwood::Index.parse_query "after:yesterday"
end
- expected_qobj = Xapian::Query.new(
+ expected_date_qobj = Xapian::Query.new(
Xapian::Query::OP_VALUE_RANGE,
Redwood::Index::DATE_VALUENO,
Xapian.sortable_serialise(Time.utc(2000, 1, 1).to_i),
Xapian.sortable_serialise(2**32),
)
+ expected_qobj = Xapian::Query.new(
+ 0.0,
+ Xapian::Query.new(
+ Xapian::Query::OP_AND,
+ expected_date_qobj,
+ Xapian::Query.new("Kmail"),
+ ),
+ )
assert_equal expected_qobj.description, parsed[:qobj].description
parsed = with_fake_time do
Redwood::Index.parse_query "before:yesterday"
end
- expected_qobj = Xapian::Query.new(
+ expected_date_qobj = Xapian::Query.new(
Xapian::Query::OP_VALUE_RANGE,
Redwood::Index::DATE_VALUENO,
Xapian.sortable_serialise(0),
Xapian.sortable_serialise(Time.utc(2000, 1, 1).to_i),
)
+ expected_qobj = Xapian::Query.new(
+ 0.0,
+ Xapian::Query.new(
+ Xapian::Query::OP_AND,
+ expected_date_qobj,
+ Xapian::Query.new("Kmail"),
+ ),
+ )
assert_equal expected_qobj.description, parsed[:qobj].description
parsed = with_fake_time do
Redwood::Index.parse_query "during:yesterday"
end
- expected_qobj = Xapian::Query.new(
+ expected_date_qobj = Xapian::Query.new(
Xapian::Query::OP_VALUE_RANGE,
Redwood::Index::DATE_VALUENO,
Xapian.sortable_serialise(Time.utc(1999, 12, 31).to_i),
Xapian.sortable_serialise(Time.utc(2000, 1, 1).to_i),
)
+ expected_qobj = Xapian::Query.new(
+ 0.0,
+ Xapian::Query.new(
+ Xapian::Query::OP_AND,
+ expected_date_qobj,
+ Xapian::Query.new("Kmail"),
+ ),
+ )
assert_equal expected_qobj.description, parsed[:qobj].description
end
end