Brad Whitaker (whitaker) wrote in changelog,
Brad Whitaker
whitaker
changelog

[livejournal] r11762: -- 2 simple APIs for querying interests ...

Committer: whitaker
-- 2 simple APIs for querying interests and intids

-- new hook to allow interests to be ignored in search
situations


U   trunk/cgi-bin/ljlib.pl
U   trunk/htdocs/directory.bml
U   trunk/htdocs/directory7.bml
U   trunk/htdocs/interests.bml
U   trunk/htdocs/tools/endpoints/directorysearch.bml
Modified: trunk/cgi-bin/ljlib.pl
===================================================================
--- trunk/cgi-bin/ljlib.pl	2007-06-22 05:30:32 UTC (rev 11761)
+++ trunk/cgi-bin/ljlib.pl	2007-06-22 22:16:59 UTC (rev 11762)
@@ -2155,6 +2155,34 @@
     return $kwid;
 }
 
+sub get_interest {
+    my $intid = shift
+        or return undef;
+
+    # FIXME: caching!
+
+    my $dbr = LJ::get_db_reader();
+    my ($int, $intcount) = $dbr->selectrow_array
+        ("SELECT interest, intcount FROM interests WHERE intid=?",
+         undef, $intid);
+
+    return wantarray() ? ($int, $intcount) : $int;
+}
+
+sub get_interest_id {
+    my $int = shift
+        or return undef;
+
+    # FIXME: caching!
+
+    my $dbr = LJ::get_db_reader();
+    my ($intid, $intcount) = $dbr->selectrow_array
+        ("SELECT intid, intcount FROM interests WHERE interest=?",
+         undef, $int);
+
+    return wantarray() ? ($intid, $intcount) : $intid;
+}
+
 # <LJFUNC>
 # name: LJ::can_use_journal
 # class:

Modified: trunk/htdocs/directory.bml
===================================================================
--- trunk/htdocs/directory.bml	2007-06-22 05:30:32 UTC (rev 11761)
+++ trunk/htdocs/directory.bml	2007-06-22 22:16:59 UTC (rev 11762)
@@ -166,8 +166,10 @@
     }
 }
 
+ if (LJ::run_hook("interest_search_ignore", query => $GET{int_like} || $FORM{int_like})) {
+     return $ad . "Sorry, we're unable to help you find users matching the interests you've provided.";
+ }
 
-
  unless (LJ::Dir::do_search($dbr, $dbdir, \%FORM, \@matches, \%info)) {
      return $ad . "<?h1 $ML{'Error'} h1?><?p $ML{'Error'}: $info{'errmsg'} p?>";
  }
@@ -227,6 +229,7 @@
  if ($count_preds == 1 && $GET{'int_like'}) {
      my $intid = $dbr->selectrow_array("SELECT intid FROM interests WHERE interest=?",
                                        undef, $GET{'int_like'});
+
      my $hide_ad = 0;
      LJ::run_hooks("interests_bml", {
          'intid' => $intid,

Modified: trunk/htdocs/directory7.bml
===================================================================
--- trunk/htdocs/directory7.bml	2007-06-22 05:30:32 UTC (rev 11761)
+++ trunk/htdocs/directory7.bml	2007-06-22 22:16:59 UTC (rev 11762)
@@ -188,6 +188,11 @@
         <?h1 Search Results h1?>
     };
 
+    if (LJ::run_hook("interest_search_ignore", query => $GET{int_like})) {
+        $ret .= "Sorry, we're unable to help you find users matching the interests you've provided.";
+        return $ret;
+    }
+
     my $page = delete $GET{page} || 1;
     my $page_size = $GET{opt_pagesize};
 

Modified: trunk/htdocs/interests.bml
===================================================================
--- trunk/htdocs/interests.bml	2007-06-22 05:30:32 UTC (rev 11761)
+++ trunk/htdocs/interests.bml	2007-06-22 22:16:59 UTC (rev 11762)
@@ -379,6 +379,10 @@
                 FROM interests WHERE interest=?", undef, $GET{'int'});
         }
 
+        if (LJ::run_hook("interest_search_ignore", query => $interest, intid => $intid)) {
+            return $ad . "<?h1 $ML{'Error'} h1?><?p Sorry, we're unable to help you find users matching the interests you've provided. p?>";
+        }
+
         $ad = LJ::ads( type => 'app', orient => 'BML-App-Search-Leaderboard' );
         return $ad . "<?h1 $ML{'Error'} h1?><?p $ML{'.error.findsim_do.intnotfound'} p?>" unless $interest;
         $intid += 0;

Modified: trunk/htdocs/tools/endpoints/directorysearch.bml
===================================================================
--- trunk/htdocs/tools/endpoints/directorysearch.bml	2007-06-22 05:30:32 UTC (rev 11761)
+++ trunk/htdocs/tools/endpoints/directorysearch.bml	2007-06-22 22:16:59 UTC (rev 11762)
@@ -85,6 +85,13 @@
 
             push @constraints, LJ::Directory::Constraint->constraints_from_formargs(\%constraint_args);
         }
+        foreach my $constraint (@constraints) {
+            next unless $constraint->isa('LJ::Directory::Constraint::Interest');
+            
+            if (LJ::run_hook("interest_search_ignore", intid => $constraint->intid)) {
+                return $err->("Sorry, we're unable to help you find users matching the interests you've provided.");
+            }
+        }
         return $err->("No search constraints were specified") unless @constraints;
 
         my $dir = LJ::Directory::Search->new(page_size => $LJ::MAX_DIR_SEARCH_RESULTS, constraints => \@constraints);

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