r21465 - in /branches/upstream/libswish-api-common-perl: ./ current/ current/eg/ current/eg/canned/ current/eg/canned/data1/ current/eg/canned/data2/ current/lib/ current/lib/SWISH/ current/lib/SWISH/API/ current/t/

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Sun Jun 15 15:19:40 UTC 2008


Author: gregoa
Date: Sun Jun 15 15:19:40 2008
New Revision: 21465

URL: http://svn.debian.org/wsvn/?sc=1&rev=21465
Log:
[svn-inject] Installing original source of libswish-api-common-perl

Added:
    branches/upstream/libswish-api-common-perl/
    branches/upstream/libswish-api-common-perl/current/
    branches/upstream/libswish-api-common-perl/current/Changes
    branches/upstream/libswish-api-common-perl/current/MANIFEST
    branches/upstream/libswish-api-common-perl/current/MANIFEST.SKIP
    branches/upstream/libswish-api-common-perl/current/META.yml
    branches/upstream/libswish-api-common-perl/current/Makefile.PL
    branches/upstream/libswish-api-common-perl/current/README
    branches/upstream/libswish-api-common-perl/current/eg/
    branches/upstream/libswish-api-common-perl/current/eg/canned/
    branches/upstream/libswish-api-common-perl/current/eg/canned/data1/
    branches/upstream/libswish-api-common-perl/current/eg/canned/data1/abc
    branches/upstream/libswish-api-common-perl/current/eg/canned/data1/def
    branches/upstream/libswish-api-common-perl/current/eg/canned/data2/
    branches/upstream/libswish-api-common-perl/current/eg/canned/data2/ghi
    branches/upstream/libswish-api-common-perl/current/eg/idx_and_search.pl   (with props)
    branches/upstream/libswish-api-common-perl/current/lib/
    branches/upstream/libswish-api-common-perl/current/lib/SWISH/
    branches/upstream/libswish-api-common-perl/current/lib/SWISH/API/
    branches/upstream/libswish-api-common-perl/current/lib/SWISH/API/Common.pm
    branches/upstream/libswish-api-common-perl/current/t/
    branches/upstream/libswish-api-common-perl/current/t/001Basic.t
    branches/upstream/libswish-api-common-perl/current/t/002Merge.t
    branches/upstream/libswish-api-common-perl/current/t/003Atime.t

Added: branches/upstream/libswish-api-common-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/Changes?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/Changes (added)
+++ branches/upstream/libswish-api-common-perl/current/Changes Sun Jun 15 15:19:40 2008
@@ -1,0 +1,13 @@
+######################################################################
+Revision history for Perl extension SWISH::API::Common
+######################################################################
+
+0.03  2005/07/01
+    (ms) Search swish-e in /usr/local/bin and other PATHs.
+
+0.02  2005/07/01
+    (ms) index() now accepts one or more directories
+    (ms) If $^X is relative, the absolute path with be determined
+
+0.01  2005/06/28
+    (ms) Where it all began.

Added: branches/upstream/libswish-api-common-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/MANIFEST?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/MANIFEST (added)
+++ branches/upstream/libswish-api-common-perl/current/MANIFEST Sun Jun 15 15:19:40 2008
@@ -1,0 +1,14 @@
+Changes
+eg/canned/data1/abc
+eg/canned/data1/def
+eg/canned/data2/ghi
+eg/idx_and_search.pl
+lib/SWISH/API/Common.pm
+Makefile.PL
+MANIFEST			This list of files
+MANIFEST.SKIP
+META.yml			Module meta-data (added by MakeMaker)
+README
+t/001Basic.t
+t/002Merge.t
+t/003Atime.t

Added: branches/upstream/libswish-api-common-perl/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/MANIFEST.SKIP?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/MANIFEST.SKIP (added)
+++ branches/upstream/libswish-api-common-perl/current/MANIFEST.SKIP Sun Jun 15 15:19:40 2008
@@ -1,0 +1,8 @@
+blib
+^Makefile$
+^Makefile.old$
+CVS
+.cvsignore
+docs
+MANIFEST.bak
+adm/release

Added: branches/upstream/libswish-api-common-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/META.yml?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/META.yml (added)
+++ branches/upstream/libswish-api-common-perl/current/META.yml Sun Jun 15 15:19:40 2008
@@ -1,0 +1,19 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         SWISH-API-Common
+version:      0.03
+version_from: lib/SWISH/API/Common.pm
+installdirs:  site
+requires:
+    File::Basename:                0
+    File::Copy:                    0
+    File::Find:                    0
+    File::Path:                    0
+    File::Temp:                    0
+    Log::Log4perl:                 0
+    LWP::Simple:                   0
+    SWISH::API:                    0
+    Sysadm::Install:               0
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17

Added: branches/upstream/libswish-api-common-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/Makefile.PL?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/Makefile.PL (added)
+++ branches/upstream/libswish-api-common-perl/current/Makefile.PL Sun Jun 15 15:19:40 2008
@@ -1,0 +1,77 @@
+######################################################################
+# Makefile.PL for SWISH::API::Common
+# 2005, Mike Schilli <cpan at perlmeister.com>
+######################################################################
+use ExtUtils::MakeMaker;
+WriteMakefile(
+    'NAME'         => 'SWISH::API::Common',
+    'VERSION_FROM' => 'lib/SWISH/API/Common.pm', # finds $VERSION
+    'PREREQ_PM'    => {
+                        Sysadm::Install => 0,
+                        Log::Log4perl   => 0,
+                        SWISH::API      => 0,
+                        File::Path      => 0,
+                        File::Find      => 0,
+                        File::Basename  => 0,
+                        File::Temp      => 0,
+                        File::Copy      => 0,
+                        LWP::Simple     => 0,
+                      }, # e.g., Module::Name => 1.1
+    ($] >= 5.005 ?    ## Add these new keywords supported since 5.005
+      (ABSTRACT_FROM => 'lib/SWISH/API/Common.pm',
+       AUTHOR     => 'Mike Schilli <cpan at perlmeister.com>') : ()),
+);
+
+my $version = `swish-e -V`;
+
+if($version !~ /SWISH/) {
+        print <<EOT;
+
+     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+     This module requires SWISH-E, available from 
+         http://swish-e.org/download/index.html
+     Please download and install it prior to installing this module.
+     Steps:
+         tar zxfv swish-e-2.4.x.tar.gz
+         cd swish-e-2.4.x
+         ./configure
+         make
+         make install
+         cd perl
+         export LD_RUN_PATH=/usr/local/lib
+         perl Makefile.PL
+         make install
+     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+EOT
+     my $build = ExtUtils::MakeMaker::prompt(
+         "Do you want me to download/build it for you ([y]/n)?", "y");
+     if($build =~ /y/) {
+         if($< != 0) {
+             print "You need to be root to do that.\n";
+             exit 0;
+         }
+         require File::Temp;
+         require File::Copy;
+         require LWP::Simple;
+         my $dir = File::Temp::tempdir(CLEANUP => 1);
+         #print "*** Temporary directory: $dir\n";
+         chdir $dir or die "Cannot chdir to $dir";
+         my $distro = "swish-e-2.4.3.tar.gz";
+         (my $distrodir = $distro) =~ s/\.tar.\gz$//g;
+         print "Downloading $distro ...\n";
+#File::Copy::copy("/tmp/$distro", "$dir/$distro");
+         LWP::Simple::getstore(
+                 "http://swish-e.org/distribution/$distro", $distro);
+         print "Done. Unpacking ...\n";
+         system("tar zxf $distro");
+         print "Done. Building ...\n";
+         system("cd $distrodir; ./configure; make; LD_LIBRARY_PATH=/usr/local/lib make install;");
+         system("cd $distrodir; cd perl; " .
+                "LD_LIBRARY_PATH=/usr/local/lib LD_RUN_PATH=/usr/local/lib perl Makefile.PL; make install");
+         print "Done.\n";
+             # Step out of 
+         chdir "/";
+    }
+
+    exit 0;
+}

Added: branches/upstream/libswish-api-common-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/README?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/README (added)
+++ branches/upstream/libswish-api-common-perl/current/README Sun Jun 15 15:19:40 2008
@@ -1,0 +1,112 @@
+######################################################################
+    SWISH::API::Common 0.03
+######################################################################
+
+NAME
+    SWISH::API::Common - SWISH Document Indexing Made Easy
+
+SYNOPSIS
+        use SWISH::API::Common;
+
+        my $swish = SWISH::API::Common->new();
+
+            # Index all files in a directory and its subdirectories
+        $swish->index("/usr/local/share/doc");
+
+            # After indexing once (it's persistent), fire up as many
+            # queries as you like:
+
+            # Search documents containing both "swish" and "install"
+        for my $hit ($swish->search("swish AND install")) {
+            print $hit->path(), "\n";
+        }
+
+DESCRIPTION
+    "SWISH::API::Common" offers an easy interface to the Swish index engine.
+    While SWISH::API offers a complete API, "SWISH::API::Common" focusses on
+    ease of use.
+
+    THIS MODULE IS CURRENTLY UNDER DEVELOPMENT. THE API MIGHT CHANGE AT ANY
+    TIME.
+
+    Currently, "SWISH::API::Common" just allows for indexing documents in a
+    single directory and any of its subdirectories. Also, don't run index()
+    and search() in parallel yet.
+
+INSTALLATION
+    "SWISH::API::Common" requires "SWISH::API" and the swish engine to be
+    installed. Please download the latest release from
+
+        http://swish-e.org/distribution/swish-e-2.4.3.tar.gz
+
+    and untar it, type
+
+        ./configure
+        make
+        make install
+
+    and then install SWISH::API which is contained in the distribution:
+
+        cd perl
+        perl Makefile.PL
+        make 
+        make install
+
+  METHODS
+    $sw = SWISH::API::Common->new()
+        Constructor. Takes many options, but the defaults are usually fine.
+
+        Available options and their defaults:
+
+                # Where SWISH::API::Common stores index files etc.
+            swish_adm_dir   "$ENV{HOME}/.swish-common"
+
+                # The path to swish-e, relative is OK
+            swish_exe       "swish-e"
+
+                # Swish index file
+            swish_idx_file  "$self->{swish_adm_dir}/default.idx"
+
+                # Swish configuration file
+            swish_cnf_file  "$self->{swish_adm_dir}/default.cnf"
+
+                # SWISH Stemming
+            swish_fuzzy_indexing_mode => "Stemming_en"
+
+                # Maximum amount of data (in bytes) extracted
+                # from a single file
+            file_len_max 100_000
+
+                # Preserve every indexed file's atime
+            atime_preserve
+        
+    $sw->index($dir, ...)
+        Generate a new index of all text documents under directory $dir. One
+        or more directories can be specified.
+
+    $sw->search("foo AND bar");
+        Searches the index, using the given search expression. Returns a
+        list hits, which can be asked for their path:
+
+                # Search documents containing 
+                # both "foo" and "bar"
+            for my $hit ($swish->search("foo AND bar")) {
+                print $hit->path(), "\n";
+            }
+
+    index_remove
+        Permanently delete the current index.
+
+TODO List
+        * More than one index directory
+        * Remove documents from index
+        * Iterator for search hits
+
+LEGALESE
+    Copyright 2005 by Mike Schilli, all rights reserved. This program is
+    free software, you can redistribute it and/or modify it under the same
+    terms as Perl itself.
+
+AUTHOR
+    2005, Mike Schilli <cpan at perlmeister.com>
+

Added: branches/upstream/libswish-api-common-perl/current/eg/canned/data1/abc
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/eg/canned/data1/abc?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/eg/canned/data1/abc (added)
+++ branches/upstream/libswish-api-common-perl/current/eg/canned/data1/abc Sun Jun 15 15:19:40 2008
@@ -1,0 +1,1 @@
+mike

Added: branches/upstream/libswish-api-common-perl/current/eg/canned/data1/def
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/eg/canned/data1/def?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/eg/canned/data1/def (added)
+++ branches/upstream/libswish-api-common-perl/current/eg/canned/data1/def Sun Jun 15 15:19:40 2008
@@ -1,0 +1,1 @@
+someone else

Added: branches/upstream/libswish-api-common-perl/current/eg/canned/data2/ghi
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/eg/canned/data2/ghi?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/eg/canned/data2/ghi (added)
+++ branches/upstream/libswish-api-common-perl/current/eg/canned/data2/ghi Sun Jun 15 15:19:40 2008
@@ -1,0 +1,1 @@
+different

Added: branches/upstream/libswish-api-common-perl/current/eg/idx_and_search.pl
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/eg/idx_and_search.pl?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/eg/idx_and_search.pl (added)
+++ branches/upstream/libswish-api-common-perl/current/eg/idx_and_search.pl Sun Jun 15 15:19:40 2008
@@ -1,0 +1,27 @@
+#!/usr/bin/perl -w
+####################################################
+# idx_and_search.pl - SWISH::API::Common test script
+# Mike Schilli, 2005 (m at perlmeister.com)
+####################################################
+use strict;
+use Log::Log4perl qw(:easy);
+
+Log::Log4perl->easy_init($ERROR);
+
+use SWISH::API::Common;
+
+    # Generate index
+my $sw = SWISH::API::Common->new();
+$sw->index("/tmp");
+
+    # Search for "michael"
+my @results = $sw->search("michael");
+
+    # Print results
+if(@results) {
+    for my $hit (@results) {
+        print $hit->path(), "\n";
+    }
+} else {
+    print "No results\n";
+}

Propchange: branches/upstream/libswish-api-common-perl/current/eg/idx_and_search.pl
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libswish-api-common-perl/current/lib/SWISH/API/Common.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/lib/SWISH/API/Common.pm?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/lib/SWISH/API/Common.pm (added)
+++ branches/upstream/libswish-api-common-perl/current/lib/SWISH/API/Common.pm Sun Jun 15 15:19:40 2008
@@ -1,0 +1,459 @@
+###########################################
+# SWISH::API::Common
+###########################################
+
+###########################################
+package SWISH::API::Common;
+###########################################
+
+use strict;
+use warnings;
+
+our $VERSION         = "0.03";
+our $SWISH_EXE       = "swish-e";
+our @SWISH_EXE_PATHS = qw(/usr/local/bin);
+
+use SWISH::API;
+use File::Path;
+use File::Find;
+use File::Spec;
+use File::Basename;
+use Log::Log4perl qw(:easy);
+use Sysadm::Install qw(:all);
+use File::Temp qw(tempfile);
+
+###########################################
+sub new {
+###########################################
+    my($class, %options) = @_;
+
+    my $self = {
+        swish_adm_dir             => "$ENV{HOME}/.swish-common",
+        swish_exe                 => swish_find(),
+        swish_fuzzy_indexing_mode => "Stemming_en",
+        %options,
+    };
+
+    my $defaults = {
+        swish_idx_file   => "$self->{swish_adm_dir}/default.idx",
+        swish_cnf_file   => "$self->{swish_adm_dir}/default.cnf",
+        dirs_file        => "$self->{swish_adm_dir}/default.dirs",
+        streamer         => "$self->{swish_adm_dir}/default.streamer",
+        file_len_max     => 100_000,
+        atime_preserve   => 0,
+    };
+
+    for my $name (keys %$defaults) {
+        if(! exists $self->{$name}) {
+            $self->{$name} = $defaults->{$name};
+        }
+    }
+
+    LOGDIE "swish-e executable not found" unless -x $self->{swish_exe};
+
+    bless $self, $class;
+}
+
+###########################################
+sub index_remove {
+###########################################
+    my($self) = @_;
+
+    unlink $self->{swish_idx_file};
+}
+
+###########################################
+sub search {
+###########################################
+    my($self, $term) = @_;
+
+    if(! -f $self->{swish_idx_file}) {
+        ERROR "Index file $self->{swish_idx_file} not found";
+        return undef;
+    }
+
+    my $swish = SWISH::API->new($self->{swish_idx_file});
+
+    $swish->AbortLastError 
+        if $swish->Error;
+
+    my $results = $swish->Query($term);
+
+    $swish->AbortLastError 
+        if $swish->Error;
+
+       # We might change this in the future to return an iterator
+       # in scalar context
+    my @results = ();
+
+    while (my $r = $results->NextResult) {
+        my $hit = SWISH::API::Common::Hit->new(
+                      path => $r->Property("swishdocpath")
+                  );
+        push @results, $hit;
+    }
+
+    return @results;
+}
+
+###########################################
+sub files_stream {
+###########################################
+    my($self) = @_;
+
+    my @dirs = split /,/, slurp $self->{dirs_file};
+
+    my @files = grep { -f } @dirs;
+       @dirs  = grep { ! -f } @dirs;
+
+    for(@files) {
+        $self->file_stream($_);
+    }
+
+    return unless @dirs;
+
+    find(sub {
+        return unless -f;
+        return unless -T;
+
+        my $full = $File::Find::name;
+
+        DEBUG "Indexing $full";
+        $self->file_stream(File::Spec->rel2abs($_));
+
+    }, @dirs);
+}
+
+############################################
+sub file_stream {
+############################################
+    my($self, $file) = @_;
+
+    my @saved;
+
+    if($self->{atime_preserve}) {
+        @saved = (stat($file))[8,9];
+    }
+
+    if(! open FILE, "<$file") {
+        WARN "Cannot open $file ($!)";
+        return;
+    }
+
+    my $rc = sysread FILE, my $data, $self->{file_len_max};
+
+    unless(defined $rc) {
+        WARN "Can't read $file $!";
+        return;
+    }
+    close FILE;
+
+    if($self->{atime_preserve}) {
+        utime(@saved, $file);
+    }
+
+    my $size = length $data;
+
+    print "Path-Name: $file\n",
+          "Document-Type: TXT*\n",
+          "Content-Length: $size\n\n";
+    print $data;
+}
+
+############################################
+sub dir_prep {
+############################################
+    my($file) = @_;
+
+    my $dir = dirname($file);
+
+    if(! -d $dir) {
+        mkd($dir) unless -d $dir;
+    }
+}
+
+############################################
+sub index_add {
+############################################
+    my($self, $dir) = @_;
+
+        # Index new doc in tmp idx file
+    my $old_idx_name = $self->{swish_idx_file};
+    (my $dummy, my $old_idx) = tempfile(CLEANUP => 1);
+    mv $old_idx_name, $old_idx;
+    mv "$old_idx_name.prop", "$old_idx.prop";
+
+    ($dummy, $self->{swish_idx_file}) = tempfile(CLEANUP => 1);
+    $self->index($dir);
+
+        # Merge two indices
+    my($stdout, $stderr, $rc) = tap($self->{swish_exe}, "-M",
+                                    $old_idx,
+                                    $self->{swish_idx_file},
+                                    $old_idx_name);
+
+    if($rc != 0) {
+        ERROR "Merging failed: $stdout $stderr";
+        return undef;
+    }
+
+    $self->{swish_idx_file} = $old_idx_name;
+}
+
+############################################
+sub index {
+############################################
+    my($self, @dirs) = @_;
+
+        # Make a new dirs file
+    dir_prep($self->{dirs_file});
+    blurt join(',', @dirs), $self->{dirs_file};
+
+        # Make a new swish conf file
+    dir_prep($self->{swish_cnf_file});
+    blurt <<EOT, $self->{swish_cnf_file};
+IndexDir  $self->{streamer}
+IndexFile $self->{swish_idx_file}
+FuzzyIndexingMode $self->{swish_fuzzy_indexing_mode}
+EOT
+
+        # Make a new streamer
+    dir_prep($self->{streamer});
+    my $perl = perl_find();
+    blurt <<EOT, $self->{streamer};
+#!$perl
+use SWISH::API::Common;
+SWISH::API::Common->new(
+        dirs_file    => '$self->{dirs_file}',
+        file_len_max => '$self->{file_len_max}',
+)->files_stream();
+EOT
+
+    chmod 0755, $self->{streamer} or 
+        LOGDIE "chmod of $self->{streamer} failed ($!)";
+
+    my($stdout, $stderr, $rc) = tap($self->{swish_exe}, "-c",
+                                    $self->{swish_cnf_file},
+                                    "-e", "-S", "prog");
+
+    unless($stdout =~ /Indexing done!/) {
+        ERROR "Indexing failed: $stdout $stderr";
+        return undef;
+    }
+
+    DEBUG "$stdout";
+
+    1;
+}
+
+###########################################
+sub perl_find {
+###########################################
+
+    if($^X =~ m#/#) {
+        return $^X;
+    }
+
+    return exe_find($^X);
+}
+
+###########################################
+sub swish_find {
+###########################################
+
+    for my $path (@SWISH_EXE_PATHS) {
+        if(-f File::Spec->catfile($path, $SWISH_EXE)) {
+                return File::Spec->catfile($path, $SWISH_EXE);
+        }
+    }
+
+    return exe_find($SWISH_EXE);
+}
+
+###########################################
+sub exe_find {
+###########################################
+    my($exe) = @_;
+
+    for my $path (split /:/, $ENV{PATH}) {
+        if(-f File::Spec->catfile($path, $exe)) {
+                return File::Spec->catfile($path, $exe);
+        }
+    }
+
+    return undef;
+}
+
+###########################################
+package SWISH::API::Common::Hit;
+###########################################
+
+make_accessor(__PACKAGE__, "path");
+
+###########################################
+sub new {
+###########################################
+    my($class, %options) = @_;
+
+    my $self = {
+        %options,
+    };
+
+    bless $self, $class;
+}
+
+##################################################
+# Poor man's Class::Struct
+##################################################
+sub make_accessor {
+##################################################
+    my($package, $name) = @_;
+
+    no strict qw(refs);
+
+    my $code = <<EOT;
+        *{"$package\\::$name"} = sub {
+            my(\$self, \$value) = \@_;
+    
+            if(defined \$value) {
+                \$self->{$name} = \$value;
+            }
+            if(exists \$self->{$name}) {
+                return (\$self->{$name});
+            } else {
+                return "";
+            }
+        }
+EOT
+    if(! defined *{"$package\::$name"}) {
+        eval $code or die "$@";
+    }
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+SWISH::API::Common - SWISH Document Indexing Made Easy
+
+=head1 SYNOPSIS
+
+    use SWISH::API::Common;
+
+    my $swish = SWISH::API::Common->new();
+
+        # Index all files in a directory and its subdirectories
+    $swish->index("/usr/local/share/doc");
+
+        # After indexing once (it's persistent), fire up as many
+        # queries as you like:
+
+        # Search documents containing both "swish" and "install"
+    for my $hit ($swish->search("swish AND install")) {
+        print $hit->path(), "\n";
+    }
+
+=head1 DESCRIPTION
+
+C<SWISH::API::Common> offers an easy interface to the Swish index engine.
+While SWISH::API offers a complete API, C<SWISH::API::Common> focusses
+on ease of use. 
+
+THIS MODULE IS CURRENTLY UNDER DEVELOPMENT. THE API MIGHT CHANGE AT ANY
+TIME.
+
+Currently, C<SWISH::API::Common> just allows for indexing documents
+in a single directory and any of its subdirectories. Also, don't run
+index() and search() in parallel yet.
+
+=head1 INSTALLATION
+
+C<SWISH::API::Common> requires C<SWISH::API> and the swish engine to
+be installed. Please download the latest release from 
+
+    http://swish-e.org/distribution/swish-e-2.4.3.tar.gz
+
+and untar it, type
+
+    ./configure
+    make
+    make install
+
+and then install SWISH::API which is contained in the distribution:
+
+    cd perl
+    perl Makefile.PL
+    make 
+    make install
+
+=head2 METHODS
+
+=over 4
+
+=item $sw = SWISH::API::Common-E<gt>new()
+
+Constructor. Takes many options, but the defaults are usually fine.
+
+Available options and their defaults:
+
+        # Where SWISH::API::Common stores index files etc.
+    swish_adm_dir   "$ENV{HOME}/.swish-common"
+
+        # The path to swish-e, relative is OK
+    swish_exe       "swish-e"
+
+        # Swish index file
+    swish_idx_file  "$self->{swish_adm_dir}/default.idx"
+
+        # Swish configuration file
+    swish_cnf_file  "$self->{swish_adm_dir}/default.cnf"
+
+        # SWISH Stemming
+    swish_fuzzy_indexing_mode => "Stemming_en"
+
+        # Maximum amount of data (in bytes) extracted
+        # from a single file
+    file_len_max 100_000
+
+        # Preserve every indexed file's atime
+    atime_preserve
+        
+=item $sw-E<gt>index($dir, ...)
+
+Generate a new index of all text documents under directory C<$dir>. One
+ or more directories can be specified.
+
+=item $sw-E<gt>search("foo AND bar");
+
+Searches the index, using the given search expression. Returns a list
+hits, which can be asked for their path:
+
+        # Search documents containing 
+        # both "foo" and "bar"
+    for my $hit ($swish->search("foo AND bar")) {
+        print $hit->path(), "\n";
+    }
+
+=item index_remove
+
+Permanently delete the current index.
+
+=back 
+
+=head1 TODO List
+
+    * More than one index directory
+    * Remove documents from index
+    * Iterator for search hits
+
+=head1 LEGALESE
+
+Copyright 2005 by Mike Schilli, all rights reserved.
+This program is free software, you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=head1 AUTHOR
+
+2005, Mike Schilli <cpan at perlmeister.com>

Added: branches/upstream/libswish-api-common-perl/current/t/001Basic.t
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/t/001Basic.t?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/t/001Basic.t (added)
+++ branches/upstream/libswish-api-common-perl/current/t/001Basic.t Sun Jun 15 15:19:40 2008
@@ -1,0 +1,61 @@
+######################################################################
+# Test suite for SWISH::API::Common
+# by Mike Schilli <cpan at perlmeister.com>
+######################################################################
+
+use warnings;
+use strict;
+
+use Test::More qw(no_plan);
+use Sysadm::Install qw(:all);
+use Log::Log4perl qw(:easy);
+#Log::Log4perl->easy_init($DEBUG);
+
+BEGIN { use_ok('SWISH::API::Common') };
+
+my $CANNED = "eg/canned";
+$CANNED = "../eg/canned" unless -d $CANNED;
+
+use SWISH::API::Common;
+
+my $sw = SWISH::API::Common->new(
+  swish_adm_dir             => "$CANNED/adm",
+  swish_fuzzy_indexing_mode => "NONE",
+);
+$sw->index("$CANNED/data1");
+
+my @found = $sw->search("mike");
+my $found = join " ", map { $_->path } @found;
+like($found, qr(canned/data1/abc), "simple query");
+
+ at found = $sw->search("someone AND else");
+$found = join " ", map { $_->path } @found;
+like($found, qr(canned/data1/def), "boolean query");
+
+ at found = $sw->search("someone AND else OR mike");
+$found = join " ", map { $_->path } @found;
+like($found, qr(canned/data1/def), "and-or query");
+like($found, qr(canned/data1/abc), "and-or query");
+
+    # Two directories
+$sw->index_remove();
+
+$sw = SWISH::API::Common->new(
+  swish_adm_dir             => "$CANNED/adm",
+  swish_fuzzy_indexing_mode => "NONE",
+);
+$sw->index("$CANNED/data1", "$CANNED/data2");
+
+ at found = $sw->search("mike");
+$found = join " ", map { $_->path } @found;
+like($found, qr(canned/data1/abc), "simple query (two dirs)");
+
+ at found = $sw->search("different");
+$found = join " ", map { $_->path } @found;
+like($found, qr(canned/data2/ghi), "simple query (two dirs)");
+
+ at found = $sw->search("nowhere");
+$found = join " ", map { $_->path } @found;
+is($found, "", "nothing found");
+
+END { rmf "$CANNED/adm"; }

Added: branches/upstream/libswish-api-common-perl/current/t/002Merge.t
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/t/002Merge.t?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/t/002Merge.t (added)
+++ branches/upstream/libswish-api-common-perl/current/t/002Merge.t Sun Jun 15 15:19:40 2008
@@ -1,0 +1,46 @@
+######################################################################
+# Test suite for SWISH::API::Common
+# by Mike Schilli <cpan at perlmeister.com>
+######################################################################
+
+use warnings;
+use strict;
+
+use Test::More qw(no_plan);
+use Sysadm::Install qw(:all);
+use Log::Log4perl qw(:easy);
+#Log::Log4perl->easy_init($DEBUG);
+
+BEGIN { use_ok('SWISH::API::Common') };
+
+my $CANNED = "eg/canned";
+$CANNED = "../eg/canned" unless -d $CANNED;
+
+use SWISH::API::Common;
+my $sw = SWISH::API::Common->new(swish_adm_dir => "$CANNED/adm");
+$sw->index("$CANNED/data1/abc");
+
+    # One
+my @found = $sw->search("mike");
+my $found = join " ", map { $_->path } @found;
+like($found, qr(canned/data1/abc), "simple query");
+
+    # and not the other
+ at found = $sw->search("someone AND else");
+$found = join " ", map { $_->path } @found;
+unlike($found, qr(canned/data1/def), "boolean query");
+
+    # Now add 2nd file to index
+$sw->index_add("$CANNED/data1/def");
+
+    # Match one ...
+ at found = $sw->search("someone AND else");
+$found = join " ", map { $_->path } @found;
+like($found, qr(canned/data1/def), "boolean query");
+
+    # ... AND the other
+ at found = $sw->search("mike");
+$found = join " ", map { $_->path } @found;
+like($found, qr(canned/data1/abc), "simple query");
+
+END { rmf "$CANNED/adm"; }

Added: branches/upstream/libswish-api-common-perl/current/t/003Atime.t
URL: http://svn.debian.org/wsvn/branches/upstream/libswish-api-common-perl/current/t/003Atime.t?rev=21465&op=file
==============================================================================
--- branches/upstream/libswish-api-common-perl/current/t/003Atime.t (added)
+++ branches/upstream/libswish-api-common-perl/current/t/003Atime.t Sun Jun 15 15:19:40 2008
@@ -1,0 +1,36 @@
+######################################################################
+# Test suite for SWISH::API::Common
+# by Mike Schilli <cpan at perlmeister.com>
+######################################################################
+
+use warnings;
+use strict;
+
+use Test::More qw(no_plan);
+use Sysadm::Install qw(:all);
+use Log::Log4perl qw(:easy);
+#Log::Log4perl->easy_init($DEBUG);
+
+BEGIN { use_ok('SWISH::API::Common') };
+
+my $CANNED = "eg/canned";
+$CANNED = "../eg/canned" unless -d $CANNED;
+
+use SWISH::API::Common;
+
+    # Preserving atime
+my $sw = SWISH::API::Common->new(swish_adm_dir  => "$CANNED/adm",
+                              atime_preserve => 1);
+
+my ($atime, $mtime) = (stat("$CANNED/data1/abc"))[8,9];
+die "Cannot get atime" unless $atime;
+
+sleep(1);
+$sw->index("$CANNED/data1/abc");
+
+my ($atime2, $mtime2) = (stat("$CANNED/data1/abc"))[8,9];
+
+ok($atime <= $atime2, "atime unmodified by index");
+ok($mtime <= $mtime2, "mtime unmodified by index");
+
+END { rmf "$CANNED/adm"; }




More information about the Pkg-perl-cvs-commits mailing list