[KinoSearch] deleting syntax

Scott Beck scottbeck at gmail.com
Tue Aug 21 17:20:28 PDT 2007


Hi,

I've written code to do record updates, it deletes a record and then
adds it back and I'm not sure how to do the delete. I have this
currently and it seem to delete half my index:

    eval {
        local $SIG{__DIE__};
        $invindexer->delete_by_term(path => qq{$folder/$status/$file});
    };
    if ($@) {
        return $self->error("CORRUPT_INDEX", "WARN", "$@");
    }


In my test case $folder/$status/$file ends up being:
./new/1186611701.5283.1.vmware.nmsrv.com,S=25951

I tried: $invindexer->delete_by_term(path => qq{"$folder/$status/$file"});
but that doesn't end up deleting anything. Is there an easy way to
debug this sort of thing? Is there some way to get a count on what is
deleted?
The path field in the schema is not analyzed or vectorized.

My entire update method follow:

sub update {
    my ($self, $path, $new) = @_;

warn "Update $path";
    my $index_path = $self->get_maildir->get_config_path . "/kino";

    my ($folder, $status, $file);
    if ($path =~ m{([^/]+)/(new|cur)/([^/]+)$}) {
        $folder = $1;
        $status = $2;
        $file = $3;
    }
    else {
        croak "Invalid path specified to $self->delete_message";
    }

    my $hostname = hostname();
    die "Can't get unique hostname" unless $hostname;

    my $invindex = GT::Maildir::KinoSearch::Schema->open($index_path);
    my $lock_factory = KinoSearch::Store::LockFactory->new(
        folder    => $invindex->get_folder,
        agent_id  => $hostname,
    );
    my $invindexer = KinoSearch::InvIndexer->new(
        invindex     => $invindex,
        lock_factory => $lock_factory
    );
    my $reader = KinoSearch::Index::IndexReader->open(
        invindex     => $invindex,
        lock_factory => $lock_factory,
    );
    my $searcher = KinoSearch::Searcher->new(
        invindex => $invindex,
        reader   => $reader
    );

    $searcher = $self->searcher;
    my $hits = $searcher->search(
        query => qq{path: "$path"},
    );

warn "delete $folder/$status/$file";
    eval {
        local $SIG{__DIE__};
        $invindexer->delete_by_term(path => qq{$folder/$status/$file});
    };
    if ($@) {
        return $self->error("CORRUPT_INDEX", "WARN", "$@");
    }

    while ( my $hashref = $hits->fetch_hit_hashref ) {
        my $result = {};
        for (keys %$hashref) {
            next if $_ eq 'score' or $_ eq 'excerpts';
            my $cp = $_;
            $cp =~ s/_sort$//;
            if (exists $new->{$cp}) {
                if ($_ eq 'data') {
                    $new->{$_} = GT::Dumper->dump_structure($new->{$_});
                }
                $result->{$_} = $new->{$cp};
                if ($_ ne $cp) {
                    $result->{$cp} = $new->{$cp};
                }
            }
            else {
                $result->{$_} = $hashref->{$_};
            }
        }
        $invindexer->add_doc($result);
    }

    $invindexer->finish;
    return 1;
}

Thanks,

Scott



More information about the KinoSearch mailing list