wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r17838: LJSUP-7453. Search don't work

Committer: gprochaev
LJSUP-7453. Search don't work

U   trunk/cgi-bin/LJ/Browse.pm
U   trunk/cgi-bin/LJ/Vertical.pm
U   trunk/cgi-bin/LJ/Widget/Browse.pm
Modified: trunk/cgi-bin/LJ/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Browse.pm	2010-12-01 09:37:52 UTC (rev 17837)
+++ trunk/cgi-bin/LJ/Browse.pm	2010-12-01 09:43:33 UTC (rev 17838)
@@ -904,11 +904,27 @@
     my $comm_list = join ",", @$comms;
     my $dbh = LJ::get_db_reader();
     if (defined $search) {
-        my $where = $vertical ? " AND m.vert_id = " . $vertical->vert_id : "";
+        my $where = $vertical ? " AND km.vert_id = " . $vertical->vert_id . " AND " : "";
+        my @search_words = map { "SELECT '%".$_."%' AS cond" } split /\s+/, $search;
+        $search = join " UNION ALL ", @search_words;
         my $posts = $dbh->selectall_arrayref (
-            "SELECT journalid, jitemid FROM vertical_keywords w, vertical_keymap m WHERE w.kw_id = m.kw_id $where AND keyword like ?", 
-            { Slice => {} }, '%'.$search.'%'
-        );
+            "SELECT journalid, jitemid
+                FROM vertical_keymap km
+                WHERE 
+                $where
+                kw_id IN (
+                    SELECT kw_id
+                        FROM vertical_keywords kw
+                        WHERE EXISTS (
+                            SELECT 1 
+                                FROM (
+                                    $search
+                                ) c 
+                            WHERE kw.keyword LIKE cond
+                        )
+                    )",
+            { Slice => {} }
+        ) || [];
         my @found_posts = ();
         foreach my $post (@$posts) {
             my $post_ids = $dbh->selectall_arrayref (

Modified: trunk/cgi-bin/LJ/Vertical.pm
===================================================================
--- trunk/cgi-bin/LJ/Vertical.pm	2010-12-01 09:37:52 UTC (rev 17837)
+++ trunk/cgi-bin/LJ/Vertical.pm	2010-12-01 09:43:33 UTC (rev 17838)
@@ -356,16 +356,29 @@
         or die "unable to contact global db master to create vertical";
 
     my $comms_search = [];
-    if ($search) {
+    my %finded = ();
+    if (defined $search) {
+        my @search_words = map { "SELECT '%".$_."%' AS cond" } split /\s+/, $search;
+        $search = join " UNION ALL ", @search_words;
         $comms_search = $dbh->selectall_arrayref (
-            "SELECT DISTINCT journalid 
-                FROM vertical_keywords w, vertical_keymap m 
-                WHERE m.jitemid <> 0 
-                    AND m.vert_id = ? 
-                    AND w.kw_id = m.kw_id 
-                    AND keyword like ?", 
-            { Slice => {} }, $self->vert_id, '%'.$search.'%'
+            "SELECT DISTINCT journalid
+                FROM vertical_keymap km
+                WHERE km.jitemid = 0
+                AND vert_id = ?
+                AND kw_id IN (
+                    SELECT kw_id
+                        FROM vertical_keywords kw
+                        WHERE EXISTS (
+                            SELECT 1 
+                                FROM (
+                                    $search
+                                ) c 
+                            WHERE kw.keyword LIKE cond
+                        )
+                    )",
+            { Slice => {} }, $self->vert_id
         ) || [];
+        %finded = map { $_->{journalid} => 1 } @$comms_search;
     }
 
     ## Get subcategories
@@ -378,9 +391,9 @@
     if ($category) {
         $category->load_communities ( %args ) unless ($args{'is_need_child'} && $category->{_loaded_journals});
         my $comms = $category->{communities};
-    
-        $comms = @$comms_search
-                ? [ grep { my $s_comm_id = $_->{journalid}; grep { $s_comm_id == $_ } @$comms } @$comms_search ]
+
+        $comms = defined $search
+                ? [ map { { journalid => $_ } } grep { $finded{$_} } @$comms ]
                 : [ map { { journalid => $_ } } @$comms ];
 
         $cusers = LJ::load_userids(map { $_->{journalid} } @$comms);
@@ -394,8 +407,8 @@
         my $comms = $cat->{communities};
 
         ## apply a user search if need
-        $comms = @$comms_search
-                ? [ grep { my $s_comm_id = $_->{journalid}; grep { $s_comm_id == $_ } @$comms } @$comms_search ]
+        $comms = defined $search
+                ? [ map { { journalid => $_ } } grep { $finded{$_} } @$comms ]
                 : [ map { { journalid => $_ } } @$comms ];
 
         ## join with common communities hash

Modified: trunk/cgi-bin/LJ/Widget/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Browse.pm	2010-12-01 09:37:52 UTC (rev 17837)
+++ trunk/cgi-bin/LJ/Widget/Browse.pm	2010-12-01 09:43:33 UTC (rev 17838)
@@ -173,7 +173,11 @@
     }
 
     if ($vertical) {
-        @comms = $vertical->get_communities( is_need_child => 1, category => $cat, search => $search_str );
+        @comms = $vertical->get_communities(
+            is_need_child   => 1, 
+            category        => $cat, 
+            search          => $view eq 'communities' ? $search_str : undef
+        );
         $ad = LJ::get_ads({ location => 'bml.explore/vertical', vertical => $vertical->name, ljadwrapper => 1 });
     } elsif ($cat) { # we're looking at a lower-level category
 

Tags: livejournal, pm, wisest-owl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments