/[Grep]/bin/reindex.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /bin/reindex.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 64 by dpavlin, Wed Feb 21 20:22:07 2007 UTC revision 129 by dpavlin, Sun Apr 29 11:37:28 2007 UTC
# Line 7  use strict; Line 7  use strict;
7  use lib 'lib';  use lib 'lib';
8    
9  use Jifty;  use Jifty;
 use Lucene;  
10  use Grep::Search;  use Grep::Search;
11  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
12    use Text::DeDuper;
13    use Encode;
14    
15    my $remove_duplicates = 1;
16    
17    $|=1;
18    
19  BEGIN { Jifty->new; };  BEGIN { Jifty->new; };
20    
21  my $coll = Grep::Model::ItemCollection->new( results_are_readable => 1 );  my $system_user = Grep::CurrentUser->superuser;
22    my $coll = Grep::Model::ItemCollection->new( results_are_readable => 1, current_user => $system_user );
23  $coll->unlimit;  $coll->unlimit;
24    
25  print "indexing ", $coll->count, " items ";  print "indexing ", $coll->count, " items ";
26    
27    my $search = Grep::Search->new();
28    my $deduper = Text::DeDuper->new();
29    
30    my ( $total, $duplicates ) = ( 0, 0 );
31    
32  while ( my $i = $coll->next ) {  while ( my $i = $coll->next ) {
33    
34          Grep::Search->add( $i, $i->in_feed->owner->id );          print $i->id;
35    
36            if ( $remove_duplicates ) {
37    
38                    my $c = encode('utf-8', $i->content);
39    
40          print $i->id, ' ';                  my @s = sort $deduper->find_similar( $c );
41                    if ( @s ) {
42                            #warn " similar = ",dump( @s );
43    
44                            foreach my $id ( @s ) {
45                                    next if $id == $i->id;  # keep current
46                                    my $si = Grep::Model::Item->new();
47                                    $si->load( $id ) or die "can't find similar item $id";
48                                    print " -$id-";
49                                    $si->delete;
50                                    $duplicates++;
51                            }
52                    }
53    
54                    $deduper->add_doc( $i->id, $c );
55            }
56    
57            $search->add( $i, $i->in_feed->owner->id );
58            print ' ';
59            $total++;
60  }  }
61    
62  print "\n";  print "$total records indexed", $remove_duplicates ? " ($duplicates duplicates)" : "", "\n";
63    
64  Grep::Search->finish;  $search->finish;

Legend:
Removed from v.64  
changed lines
  Added in v.129

  ViewVC Help
Powered by ViewVC 1.1.26