Date: Monday February 3, 2003 @ 13:55
Author: matt
Update of /home/cvs/AxKit-XSP-Wiki/lib/AxKit/XSP
In directory ted.sergeant.org:/tmp/cvs-serv15107/lib/AxKit/XSP
Modified Files:
Wiki.pm
Log Message:
Log: Search now works
Submitted by:
Reviewed by:
PR:
Index: Wiki.pm
===================================================================
RCS file: /home/cvs/AxKit-XSP-Wiki/lib/AxKit/XSP/Wiki.pm,v
retrieving revision 1.17
retrieving revision 1.18
diff -b -u -r1.17 -r1.18
--- Wiki.pm 2003/02/03 08:51:01 1.17
+++ Wiki.pm 2003/02/03 13:55:58 1.18
@@ -173,6 +173,16 @@
return $text;
}
+sub get_default_formatter {
+ my ($db) = @_;
+ my $sth = $db->prepare("SELECT id FROM Formatter WHERE name LIKE ?");
+ $sth->execute("pod%");
+ while (my $row = $sth->fetch) {
+ return $row->[0];
+ }
+ die "No rows from Formatter table!";
+}
+
sub edit_page {
my ($db, $page) = @_;
my $sth = $db->prepare(<<'EOT');
@@ -183,7 +193,7 @@
$sth->execute($page);
my $output = '<edit><text>';
- my $formatter = 1;
+ my $formatter = get_default_formatter($db);
while ( my $row = $sth->fetch ) {
# create the parser
$output .= xml_escape($row->[0]);
@@ -214,13 +224,18 @@
my ($dbpath, $dbname, $query) = @_;
my $db = _mkdb($dbpath, $dbname);
my %search = parse_search($query);
+ use Data::Dumper; warn(Dumper(\%search));
my $results = search_message_index( db => $db,
required => $search{required},
normal => $search{normal},
phrase => $search{phrase},
+ excluded => $search{excluded},
);
my $output = '<search-results>';
- while (my $row = $results->fetch) {
+ if (!@{$results}) {
+ $output .= '<no-results/>';
+ }
+ foreach my $row (sort { $b->[1] <=> $a->[1] } @{$results}) {
$output .= "<result><page>" . xml_escape($row->[0]) . "</page>";
$output .= "<rank>" . xml_escape($row->[1]) . "</rank></result>";
}
@@ -233,53 +248,42 @@
my $db = $p{db};
- my $sql = "
-SELECT Page.name, SUM(ContentIndex.value) AS value
-FROM ContentIndex, Page";
-
- my @fromlist;
-
- my $clause = '';
-
- my $word_from_id = 1;
- my $andor = 'AND';
-
- if ( @{$p{required}} ) {
- foreach my $word ( @{ $p{required} } ) {
- push @fromlist, "Word AS word$word_from_id";
- $clause .= "AND ContentIndex.word_id = word$word_from_id\.id\n";
- $clause .= "AND word$word_from_id\.word = " . $db->quote($word) . "\n";
- $word_from_id++;
- }
- }
-
- if (@{$p{normal}}) {
- push @fromlist, "Word AS word$word_from_id";
- $clause .= "AND ContentIndex.word_id = word$word_from_id.id\n";
- $clause .= "AND word$word_from_id.word in (" . join(',', map { $db->quote($_)
} @{$p{normal}}) . ")\n";
- $word_from_id++;
- }
-
- if (@{$p{phrase}}) {
- $clause .= "AND (";
- $clause .= join(" OR ", map { "AND Page.content LIKE " . $db->quote("%$_%") }
@{$p{phrase}});
- $clause .= ")\n";
+ # Excluded words are excluded from all pages
+ my $exclude = '';
+ if ( @{$p{excluded}} ) {
+ $exclude .= " AND Page.name NOT IN (
+ SELECT DISTINCT Page.name
+ FROM Page, ContentIndex, Word
+ WHERE ContentIndex.page_id = Page.id
+ AND ContentIndex.word_id = Word.id
+ AND Word.word IN (" .
+ join(',', map { $db->quote($_) } @{$p{excluded}}) .
+ ")
+ )\n";
}
- if (@fromlist) {
- $sql .= ", " . join(', ', @fromlist);
- }
-
- $sql .= "\nWHERE ContentIndex.page_id = Page.id
-$clause
+ my $sql = "
+SELECT Page.name, SUM(ContentIndex.value) AS value
+FROM ContentIndex, Page, Word
+WHERE ContentIndex.page_id = Page.id
+ AND ContentIndex.word_id = Word.id
+ AND (" .
+ join(" OR ", (
+ (map { "Word.word = " . $db->quote($_) } @{$p{required}}),
+ (map { "Page.content LIKE " . $db->quote("\%$_\%") } @{$p{phrase}}),
+ )) .
+ ")
+$exclude
GROUP BY ContentIndex.page_id
-ORDER BY SUM(ContentIndex.value) DESC";
-
- warn("About to execute:\n$sql\n");
-
+";
+ warn("Getting required with:\n$sql\n");
my $sth = $db->prepare($sql);
$sth->execute();
- return $sth;
+ my $results = [];
+ while (my $row = $sth->fetch) {
+ push @$results, $row;
+ }
+ return $results;
}
@@ -298,6 +302,10 @@
$search{required}{$term}++;
warn "Search required: $term\n";
}
+ elsif ($term =~ s/^\-//) {
+ $search{excluded}{$term}++;
+ warn "Search excluded: $term\n";
+ }
elsif ($term =~ /^(["'])/) {
my $quote = $1;
$term =~ s/^$quote//;
@@ -310,13 +318,13 @@
}
}
else {
- $search{normal}{$term}++;
+ $search{required}{$term}++;
warn "Search normal: $term\n";
}
}
# turn into arrayrefs
- foreach ( qw( normal required phrase ) )
+ foreach ( qw( normal required excluded phrase ) )
{
if ( $search{$_} )
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]