public inbox for [email protected]  
help / color / mirror / Atom feed
From: Petr Jelinek <[email protected]>
To: PostgreSQL www <[email protected]>
Subject: Docbot search fix
Date: Fri, 16 Nov 2007 12:30:18 +0100
Message-ID: <[email protected]> (raw)

Hello,

there is one problem in current implementation of docbot search on pg 
website (the "Based on your search term, we recommend the following 
links" part). It only works for single words which is not how docbot is 
meant to work.
Attached patch handles multi-word search queries the way docbot does.

-- 
Regards
Petr Jelinek (PJMODOS)


Index: system/page/search.php
===================================================================
--- system/page/search.php	(revision 1813)
+++ system/page/search.php	(working copy)
@@ -105,7 +105,15 @@
 
     function search_docbot() {
         if ($this->pagenum > 1) return; // only show docbot urls on first page 
-        $qry = "SELECT url FROM docbot_keylist WHERE \"key\" = '". pg_escape_string($this->query) ."'ORDER BY url ~ 'postgresql.org' desc, url LIMIT ". $this->maxdocbots;
+        // split query to separate words
+        $keys = preg_split('/\s+/', str_replace('"', '', $this->query));
+
+        // build the keyword search sql query
+        $part = "SELECT kurl FROM docbot_key WHERE \"key\" = lower('";
+        $qry = "SELECT url FROM docbot_url WHERE id IN (\n";
+        $qry .= join("\n\tINTERSECT\n", array_map(create_function('$e', 'global $part; return $part.pg_escape_string($e)."\')";'), $keys));
+        $qry .= ")\nORDER BY url ~ 'postgresql.org' desc, url LIMIT ".$this->maxdocbots;
+
         $rs = $this->pg_query($qry,'search');
         for ($i = 0; $i < pg_num_rows($rs); $i++) {
             $r = pg_fetch_array($rs, $i, PGSQL_ASSOC);


Attachments:

  [text/plain] search.diff (1.2K, 2-search.diff)
  download | inline diff:
Index: system/page/search.php
===================================================================
--- system/page/search.php	(revision 1813)
+++ system/page/search.php	(working copy)
@@ -105,7 +105,15 @@
 
     function search_docbot() {
         if ($this->pagenum > 1) return; // only show docbot urls on first page 
-        $qry = "SELECT url FROM docbot_keylist WHERE \"key\" = '". pg_escape_string($this->query) ."'ORDER BY url ~ 'postgresql.org' desc, url LIMIT ". $this->maxdocbots;
+        // split query to separate words
+        $keys = preg_split('/\s+/', str_replace('"', '', $this->query));
+
+        // build the keyword search sql query
+        $part = "SELECT kurl FROM docbot_key WHERE \"key\" = lower('";
+        $qry = "SELECT url FROM docbot_url WHERE id IN (\n";
+        $qry .= join("\n\tINTERSECT\n", array_map(create_function('$e', 'global $part; return $part.pg_escape_string($e)."\')";'), $keys));
+        $qry .= ")\nORDER BY url ~ 'postgresql.org' desc, url LIMIT ".$this->maxdocbots;
+
         $rs = $this->pg_query($qry,'search');
         for ($i = 0; $i < pg_num_rows($rs); $i++) {
             $r = pg_fetch_array($rs, $i, PGSQL_ASSOC);


view thread (5+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Docbot search fix
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox