3 # DW::Hooks::SiteSearch
5 # Hooks for Site Search functionality.
8 # Mark Smith <mark@dreamwidth.org>
10 # Copyright (c) 2009 by Dreamwidth Studios, LLC.
12 # This program is free software; you may redistribute it and/or modify it under
13 # the same terms as Perl itself. For a copy of the license, please reference
14 # 'perldoc perlartistic' or 'perldoc perlgpl'.
17 package DW::Hooks::SiteSearch;
23 # ensure we can talk to our system
24 return LJ::get_dbh( 'sphinx_search' )
25 or die "Unable to get sphinx_search database handle.\n";
28 LJ::Hooks::register_hook( 'setprop', sub {
30 return unless $opts{prop} eq 'opt_blockglobalsearch';
32 my $dbh = _sphinx_db() or return 0;
33 $dbh->do( 'UPDATE posts_raw SET allow_global_search = ? WHERE journal_id = ?',
34 undef, $opts{value} eq 'Y' ? 0 : 1, $opts{u}->id );
35 die $dbh->errstr if $dbh->err;
42 # set when the user's status(vis) changes
43 # the user may still undelete or be unsuspended
44 # so we don't want to remove from indexing just yet
46 my ( $u, $is_deleted ) = @_;
48 my $dbh = _sphinx_db() or return 0;
49 $dbh->do( 'UPDATE posts_raw SET is_deleted = ? where journal_id = ?',
50 undef, $is_deleted, $u->id );
51 die $dbh->errstr if $dbh->err;
56 LJ::Hooks::register_hook( 'account_delete', sub { _mark_deleted( $_[0], 1 ) } );
57 LJ::Hooks::register_hook( 'account_cancel', sub { _mark_deleted( $_[0], 1 ) } );
58 LJ::Hooks::register_hook( 'account_makevisible', sub {
59 my ( $u, %opts ) = @_;
61 my $old = $opts{old_statusvis};
62 _mark_deleted( $u, 0 ) if $old eq "D" || $old eq "S";
66 LJ::Hooks::register_hook( 'purged_user', sub {
69 my $sclient = LJ::theschwartz() or die;
71 # queue up a copier job, which will notice that the entries by this user have been deleted...
72 $sclient->insert_jobs( TheSchwartz::Job->new_from_array( 'DW::Worker::Sphinx::Copier',
73 { userid => $u->id } ) );