From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C2A881F43D for ; Tue, 21 Mar 2023 23:07:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1679440063; bh=gt4RDNFgdwTCeWumR2NzkEzUypmNEmPxU0OUR4LVjqE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oqw5yY7LTg7GpR6HGXR/3o11ghYqi9Xp/lWNSXx9Abl0h9+FPy8Hsi+3zzGSdHxkC sENuRzH5ZMuuu5A8OtVzfFGpA9Hs5eOeKDdkfYudd6I9G99ZacxHgmVIrCGMA2/DQu 2Qcx1A86JKqXQXiX+wHj0Aov5DEJbhIqAl2I4u5k= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 02/28] search: relocate all_terms from lei_search Date: Tue, 21 Mar 2023 23:07:17 +0000 Message-Id: <20230321230743.3020032-2-e@80x24.org> In-Reply-To: <20230321230743.3020032-1-e@80x24.org> References: <20230321230701.3019936-1-e@80x24.org> <20230321230743.3020032-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This will be used for code_search, too. --- lib/PublicInbox/LeiSearch.pm | 14 -------------- lib/PublicInbox/Search.pm | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/PublicInbox/LeiSearch.pm b/lib/PublicInbox/LeiSearch.pm index 936c2751..ba4c4309 100644 --- a/lib/PublicInbox/LeiSearch.pm +++ b/lib/PublicInbox/LeiSearch.pm @@ -158,20 +158,6 @@ sub kw_changed { join("\0", @$new_kw_sorted) eq $cur_kw ? 0 : 1; } -sub all_terms { - my ($self, $pfx) = @_; - my $xdb = $self->xdb; - my $cur = $xdb->allterms_begin($pfx); - my $end = $xdb->allterms_end($pfx); - my %ret; - for (; $cur != $end; $cur++) { - my $tn = $cur->get_termname; - index($tn, $pfx) == 0 and - $ret{substr($tn, length($pfx))} = undef; - } - wantarray ? (sort keys %ret) : \%ret; -} - sub qparse_new { my ($self) = @_; my $qp = $self->SUPER::qparse_new; # PublicInbox::Search diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index e858729a..7aba2445 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -553,4 +553,18 @@ sub num2docid ($$) { ($num - 1) * $nshard + $num % $nshard + 1; } +sub all_terms { + my ($self, $pfx) = @_; + my $cur = xdb($self)->allterms_begin($pfx); + my $end = $self->{xdb}->allterms_end($pfx); + my %ret; + for (; $cur != $end; $cur++) { + my $tn = $cur->get_termname; + index($tn, $pfx) == 0 and + $ret{substr($tn, length($pfx))} = undef; + } + wantarray ? (sort keys %ret) : \%ret; +} + + 1;