From fcb84165e4e2c01b7819a26eedea0dbc13f90c4a Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Fri, 19 Oct 2007 14:26:05 +0000 Subject: [PATCH] (NewSearchFreeTextTitleAndBody): Call SearchFreeTextUnique for both result sets. (SearchFreeTextUnique): New, uniquify the list. --- modules/search-freetext.pl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/search-freetext.pl b/modules/search-freetext.pl index 3b41ac0b..cd52318c 100644 --- a/modules/search-freetext.pl +++ b/modules/search-freetext.pl @@ -56,7 +56,7 @@ sub process { package OddMuse; -$ModulesDescription .= '

$Id: search-freetext.pl,v 1.61 2007/10/11 11:09:36 as Exp $

'; +$ModulesDescription .= '

$Id: search-freetext.pl,v 1.62 2007/10/19 14:26:05 as Exp $

'; =head2 User Interface @@ -314,13 +314,16 @@ sub NewSearchFreeTextTitleAndBody { my @words = map { SearchFreeTextGet(SearchFreeTextDB($_), 0, @wanted_words); } ("$DataDir/word-update.db", "$DataDir/word.db"); + @words = SearchFreeTextUnique(@words); # both dictionaries might have returned a result my @tags = map { SearchFreeTextGet(SearchFreeTextDB($_), 1, @wanted_tags); } ("$DataDir/tags-update.db", "$DataDir/tags.db"); + @tags = SearchFreeTextUnique(@tags); # both dictionaries might have returned a result my @excluded_tags = map { SearchFreeTextGet(SearchFreeTextDB($_), 1, @unwanted_tags); } ("$DataDir/tags-update.db", "$DataDir/tags.db"); my @result = (); + # some set operations... if (not @wanted_words and not @wanted_tags and not @excluded_tags) { # do nothing } elsif (not @wanted_words and not @wanted_tags and @excluded_tags) { @@ -392,6 +395,19 @@ sub NewSearchFreeTextTitleAndBody { return @items; } +sub SearchFreeTextUnique { + # remove duplicate pages without disturbing the order of @result! + my %seen; + my @copy; + foreach my $id (@_) { + if (not $seen{$id}) { + unshift(@copy,$id); + $seen{$id} = 1; + } + } + return @copy; +} + sub SearchFreeTextGet { my ($db, $tags, @wanted) = @_; # Shortcut if there are no search terms.