Thread: Docbot search fix

Docbot search fix

From
Petr Jelinek
Date:
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);

Re: Docbot search fix

From
Bruce Momjian
Date:
Uh, did this get addressed?  If so, I didn't see it.

---------------------------------------------------------------------------

Petr Jelinek wrote:
> 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);

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faq

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://postgres.enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: Docbot search fix

From
Petr Jelinek
Date:
Bruce Momjian wrote:
> Uh, did this get addressed?  If so, I didn't see it.
>
> ---------------------------------------------------------------------------
>
> Petr Jelinek wrote:
>   
>> 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.
Umm nobody applied patch nor did any other changes to the search afaics, 
so no it wasn't addressed.

-- 
Regards
Petr Jelinek (PJMODOS)



Re: Docbot search fix

From
Bruce Momjian
Date:
Has no one addressed this either?

---------------------------------------------------------------------------

Petr Jelinek wrote:
> 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);

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faq

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://postgres.enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: Docbot search fix

From
Bruce Momjian
Date:
Based on my testing, this has still not been addressed.

---------------------------------------------------------------------------

Bruce Momjian wrote:
> 
> Has no one addressed this either?
> 
> ---------------------------------------------------------------------------
> 
> Petr Jelinek wrote:
> > 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);
> 
> > 
> > ---------------------------(end of broadcast)---------------------------
> > TIP 3: Have you checked our extensive FAQ?
> > 
> >                http://www.postgresql.org/docs/faq
> 
> -- 
>   Bruce Momjian  <bruce@momjian.us>        http://momjian.us
>   EnterpriseDB                             http://postgres.enterprisedb.com
> 
>   + If your life is a hard drive, Christ can be your backup. +
> 
> --
> Sent via pgsql-www mailing list (pgsql-www@postgresql.org)
> To make changes to your subscription:
> http://mail.postgresql.org/mj/mj_wwwusr?domain=postgresql.org&extra=pgsql-www

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +