From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by bl2.djc.id.au (Postfix, from userid 1000) id EF5ED29C46E; Sun, 18 Oct 2026 12:52:22 +1100 (AEDT) Date: Sun, 18 Oct 2026 12:52:23 +1100 To: sup-commits@supmua.dev Subject: [sup.git] 01/06: prepend type:mail to every search before parsing MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Reply-To: Dan Callaghan In-Reply-To: <179228834279.389402.1183876010618010579@bl2.djc.id.au> References: <179228834279.389402.1183876010618010579@bl2.djc.id.au> Thread-Index: AQAAEjRWNCbjvxiESNeReEpYhFO1Gg== X-Git-Host: bl2.djc.id.au X-Git-Repo: sup.git X-Git-Refname: refs/heads/develop X-Git-Reftype: branch X-Git-Rev: bcf87a864c5543ee5daf459fd9466b5d92b57da4 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.7.dev Auto-Submitted: auto-generated Message-Id: <20261018015222.EF5ED29C46E@bl2.djc.id.au> From: Dan Callaghan List-Id: New commit on branch develop: https://supmua.dev/git/sup/commit/bcf87a864c5543ee5daf459fd9466b5d92b57da4.html commit bcf87a864c5543ee5daf459fd9466b5d92b57da4 Author: Dan Callaghan AuthorDate: Sun Oct 11 16:25:12 2026 +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. --- lib/sup/index.rb | 4 ++++ test/unit/test_index.rb | 30 +++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/sup/index.rb b/lib/sup/index.rb index 70afc8d7..82f28657 100644 --- 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 index 3f2bc213..08221aa2 100644 --- 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