r36489 - in /branches/upstream/libsearch-xapian-perl/current: ./ Xapian/ examples/ t/

ryan52-guest at users.alioth.debian.org ryan52-guest at users.alioth.debian.org
Wed May 27 04:23:46 UTC 2009


Author: ryan52-guest
Date: Wed May 27 04:23:38 2009
New Revision: 36489

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=36489
Log:
[svn-upgrade] Integrating new upstream version, libsearch-xapian-perl (1.0.13.1)

Added:
    branches/upstream/libsearch-xapian-perl/current/examples/full-indexer.pl   (with props)
    branches/upstream/libsearch-xapian-perl/current/examples/full-searcher.pl   (with props)
    branches/upstream/libsearch-xapian-perl/current/examples/simpleexpand.pl   (with props)
    branches/upstream/libsearch-xapian-perl/current/examples/simpleindex.pl   (with props)
    branches/upstream/libsearch-xapian-perl/current/examples/simplematchdecider.pl   (with props)
Modified:
    branches/upstream/libsearch-xapian-perl/current/Changes
    branches/upstream/libsearch-xapian-perl/current/MANIFEST
    branches/upstream/libsearch-xapian-perl/current/META.yml
    branches/upstream/libsearch-xapian-perl/current/README
    branches/upstream/libsearch-xapian-perl/current/Xapian.pm
    branches/upstream/libsearch-xapian-perl/current/Xapian/MSet.pm
    branches/upstream/libsearch-xapian-perl/current/examples/simplesearch.pl
    branches/upstream/libsearch-xapian-perl/current/t/tied.t

Modified: branches/upstream/libsearch-xapian-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/Changes?rev=36489&op=diff
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/Changes (original)
+++ branches/upstream/libsearch-xapian-perl/current/Changes Wed May 27 04:23:38 2009
@@ -1,7 +1,23 @@
 Revision history for Perl extension Search::Xapian.
 
+1.0.13.1  Tue May 26 13:51:18 GMT 2009
+	[Changes contributed by Olly Betts]
+	- Deprecate Search::Xapian::MSet::matches() and make it issue a
+	  warning.  Please use Search::Xapian::MSet::items() instead.
+	- Add another translated example: simplematchdecider.pl
+
+1.0.13.0  Sat May 23 15:10:39 GMT 2009
+	[Changes contributed by Olly Betts]
+	- Add Search::Xapian::MSet::matches() method which returns an array
+	  tied to the MSet (much like Search::Xapian::Enquire::matches(), but
+	  you get access to the MSet object itself).
+	- Add new translated version of the simple examples from the Python
+	  bindings.
+	- Add more fully featured examples: full-indexer.pl and
+	  full-searcher.pl.
+
 1.0.12.0  Sun Apr 19 11:18:04 GMT 2009
-	[Changes contributed by Olly Betts] 
+	[Changes contributed by Olly Betts]
 	- Add handling of exceptions from Database::get_metadata() and methods
 	  of Enquire which might throw DatabaseModifiedError to address
 	  situation reported in ticket#284.

Modified: branches/upstream/libsearch-xapian-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/MANIFEST?rev=36489&op=diff
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/MANIFEST (original)
+++ branches/upstream/libsearch-xapian-perl/current/MANIFEST Wed May 27 04:23:38 2009
@@ -84,5 +84,10 @@
 t/valuerange.t
 t/writabledatabase.t
 
+examples/full-indexer.pl
+examples/full-searcher.pl
+examples/simpleexpand.pl
+examples/simpleindex.pl
+examples/simplematchdecider.pl
 examples/simplesearch.pl
 META.yml                                 Module meta-data (added by MakeMaker)

Modified: branches/upstream/libsearch-xapian-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/META.yml?rev=36489&op=diff
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/META.yml (original)
+++ branches/upstream/libsearch-xapian-perl/current/META.yml Wed May 27 04:23:38 2009
@@ -1,10 +1,13 @@
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
-name:         Search-Xapian
-version:      1.0.12.0
-version_from: Xapian.pm
-installdirs:  site
-requires:
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.30_01
+--- #YAML:1.0
+name:                Search-Xapian
+version:             1.0.13.1
+abstract:            Perl XS frontend to the Xapian C++ search library.
+license:             ~
+author:              
+    - Alex Bowley <xapian-discuss at lists.xapian.org>
+generated_by:        ExtUtils::MakeMaker version 6.42
+distribution_type:   module
+requires:     
+meta-spec:
+    url:     http://module-build.sourceforge.net/META-spec-v1.3.html
+    version: 1.3

Modified: branches/upstream/libsearch-xapian-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/README?rev=36489&op=diff
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/README (original)
+++ branches/upstream/libsearch-xapian-perl/current/README Wed May 27 04:23:38 2009
@@ -1,4 +1,4 @@
-Search::Xapian version 1.0.12.0
+Search::Xapian version 1.0.13.1
 ===============================
 
 This is Search::Xapian, a Perl XS frontend to the Xapian C++ search library.

Modified: branches/upstream/libsearch-xapian-perl/current/Xapian.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/Xapian.pm?rev=36489&op=diff
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/Xapian.pm (original)
+++ branches/upstream/libsearch-xapian-perl/current/Xapian.pm Wed May 27 04:23:38 2009
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-our $VERSION = '1.0.12.0';
+our $VERSION = '1.0.13.1';
 
 use Exporter 'import';
 

Modified: branches/upstream/libsearch-xapian-perl/current/Xapian/MSet.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/Xapian/MSet.pm?rev=36489&op=diff
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/Xapian/MSet.pm (original)
+++ branches/upstream/libsearch-xapian-perl/current/Xapian/MSet.pm Wed May 27 04:23:38 2009
@@ -84,4 +84,16 @@
   }
 }
 
+sub items {
+  my $self = shift;
+  my @array;
+  tie( @array, 'Search::Xapian::MSet::Tied', $self );
+  return @array;
+}
+
+sub matches {
+    warn "Search::Xapian::MSet::matches() is deprecated - use Search::Xapian::MSet::items() method instead.\n";
+    return items(@_);
+}
+
 1;

Added: branches/upstream/libsearch-xapian-perl/current/examples/full-indexer.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/examples/full-indexer.pl?rev=36489&op=file
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/examples/full-indexer.pl (added)
+++ branches/upstream/libsearch-xapian-perl/current/examples/full-indexer.pl Wed May 27 04:23:38 2009
@@ -1,0 +1,142 @@
+#!/usr/bin/perl
+#
+# A sample indexer which demonstrates many of Xapian's commonly used features.
+#
+# Copyright (C) 2009 Olly Betts
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+use strict;
+use Search::Xapian (':all');
+use POSIX;
+
+# Constants denoting what we're using the number value slots for.
+my $SLOT_DATE = 0;
+my $SLOT_DOCNUM = 1;
+my $SLOT_TYPE = 2;
+my $SLOT_AUTHOR = 3;
+my $SLOT_TITLE = 4;
+
+# We want exactly one command line argument.
+if (scalar @ARGV != 1) {
+    print STDERR "Usage: $0 PATH_TO_DATABASE\n";
+    exit 1;
+}
+
+my ($database, $indexer);
+
+eval {
+    # Open the database for writing.  If it doesn't exist, create it.
+    $database = Search::Xapian::WritableDatabase->new(
+	    $ARGV[0],
+	    DB_CREATE_OR_OPEN);
+
+    # Set up a TermGenerator to index text stemmed with the "english" stemmer.
+    $indexer = Search::Xapian::TermGenerator->new();
+    my $stemmer = Search::Xapian::Stem->new("english");
+    $indexer->set_stemmer($stemmer);
+};
+if ($@) {
+    # Report the exception which we've caught.
+    print STDERR "Exception: $@\n";
+    exit 1;
+}
+
+# Add some documents to the index (in a real indexer, this data would come from
+# some external source like a file or a database).
+index_document(
+    "The Old Man and the Sea",
+    "Ernest Hemingway",
+    "Santiago goes fishing, without much success.",
+    "978-0-684-80122-3",
+    "1952-09-01",
+    "book"
+);
+index_document(
+    "Star Wars",
+    "George Lucas",
+    "Luke goes to meet his destiny in the stars.",
+    "tt0076759",
+    "1977-05-25",
+    "film"
+);
+index_document(
+    "Accidental Death of an Anarchist",
+    "Dario Fo",
+    "An anarchist dies, accidentally!",
+    "12345",
+    "1970-12-10",
+    "play"
+);
+
+sub index_document {
+    my ($doc_name, $author, $keywords, $doc_number, $date, $type) = @_;
+
+    eval {
+	my $doc = Search::Xapian::Document->new();
+	$indexer->set_document($doc);
+
+	# Set the document data to the doc_name so we can show it for matches.
+	$doc->set_data($doc_name);
+
+	# Index the author to allow fielded free-text searching.
+	$indexer->index_text($author, 1, "A");
+
+	# Index the title to allow fielded free-text searching.
+	$indexer->index_text($doc_name, 1, "S");
+
+	# Index the title without a prefix too.
+	$indexer->index_text($doc_name);
+
+	# Increase the term position so that phrases can't straddle the
+	# doc_name and keywords.
+	$indexer->increase_termpos();
+
+	# Index the keywords as free-text.
+	$indexer->index_text($keywords);
+
+	# Unique ID.
+	$doc->add_term("Q" . $doc_number);
+
+	# To allow boolean filtering by type.
+	$doc->add_term("XTYPE" . lc $type);
+
+	# To allow date range searching and sorting by date.
+	if ($date =~ /^(\d{4})-(\d\d)-(\d\d)$/) {
+	    # DateValueRangeProcessor wants values in the form "YYYYMMDD".
+	    $doc->add_value($SLOT_DATE, "$1$2$3");
+	}
+
+	# To allow sorting by document number.
+	$doc->add_value($SLOT_DOCNUM, $doc_number);
+
+	# To allow sorting by document type.
+	$doc->add_value($SLOT_TYPE, lc $type);
+
+	# To allow sorting by author.
+	$doc->add_value($SLOT_AUTHOR, $author);
+
+	# To allow sorting by title..
+	$doc->add_value($SLOT_TITLE, $doc_name);
+
+	# Add the document to the database.
+	$database->add_document($doc);
+    };
+    if ($@) {
+	# Report the exception which we've caught.
+	print STDERR "Exception: $@\n";
+	exit 1;
+    }
+}

Propchange: branches/upstream/libsearch-xapian-perl/current/examples/full-indexer.pl
------------------------------------------------------------------------------
    svn:executable = *

Added: branches/upstream/libsearch-xapian-perl/current/examples/full-searcher.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/examples/full-searcher.pl?rev=36489&op=file
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/examples/full-searcher.pl (added)
+++ branches/upstream/libsearch-xapian-perl/current/examples/full-searcher.pl Wed May 27 04:23:38 2009
@@ -1,0 +1,153 @@
+#!/usr/bin/perl
+#
+# A sample search program which demonstrates many of Xapian's commonly used
+# features.
+#
+# Copyright (C) 2009 Olly Betts
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+use strict;
+use Search::Xapian (':all');
+
+# Constants denoting what we're using the number value slots for.
+my $SLOT_DATE = 0;
+my $SLOT_DOCNUM = 1;
+my $SLOT_TYPE = 2;
+my $SLOT_AUTHOR = 3;
+my $SLOT_TITLE = 4;
+
+# We need at least three command line arguments.
+if (scalar @ARGV < 3) {
+    print STDERR "Usage: $0 PATH_TO_DATABASE[...] -- [-sSORTBY] QUERY[...]\n";
+    print STDERR "where SORTBY can be date, id, type, author, or title.\n";
+    print STDERR "\n";
+    print STDERR "Search syntax supported:\n";
+    print STDERR "  Boolean filters: type:book id:tt0076759\n";
+    print STDERR "  Date ranges: 25/12/1970..31/12/1979\n";
+    print STDERR "  Boolean operators: AND OR NOT\n";
+    print STDERR "  Free text fields: author:John title:\"star wars\"\n";
+    print STDERR "  Phrases: \"accidental death\"\n";
+    exit 1;
+}
+
+eval {
+    # Open the database(s) for searching.
+    my $database = Search::Xapian::Database->new(shift @ARGV);
+    while (scalar @ARGV && $ARGV[0] ne '--') {
+	# Xapian can transparently search several databases together.
+	my $extra_db = Search::Xapian::Database->new(shift @ARGV);
+	$database->add_database($extra_db);
+    }
+    shift @ARGV;
+
+    # Default is sort by relevance.
+    my $sort_by;
+    if (scalar @ARGV && $ARGV[0] =~ /^-s(\w+)$/) {
+	if ($1 eq 'date') {
+	    $sort_by = 0;
+	} elsif ($1 eq 'id') {
+	    $sort_by = 1;
+	} elsif ($1 eq 'type') {
+	    $sort_by = 2;
+	} elsif ($1 eq 'author') {
+	    $sort_by = 3;
+	} elsif ($1 eq 'title') {
+	    $sort_by = 4;
+	} else {
+	    print STDERR "Bad option '-s$1'.\n";
+	    exit 1;
+	}
+	shift @ARGV;
+    }
+
+    # Start an enquire session.
+    my $enquire = Search::Xapian::Enquire->new($database);
+
+    # Combine the remaining command line arguments with a space between each.
+    # This means that simple queries without shell metacharacters in don't
+    # have to be quoted just to appear as a single argument to the shell.
+    my $query_string = join ' ', @ARGV;
+
+    # Set up the QueryParser how we want.
+    my $qp = Search::Xapian::QueryParser->new();
+    $qp->set_database($database);
+    $qp->set_stemmer(Search::Xapian::Stem->new("english"));
+    $qp->set_stemming_strategy(STEM_SOME);
+
+    # Prefixes for free-text fields.
+    $qp->add_prefix('title', 'S');
+    $qp->add_prefix('author', 'A');
+
+    # Prefixes for boolean filters.
+    $qp->add_boolean_prefix('type', 'XTYPE');
+    $qp->add_boolean_prefix('id', 'Q');
+
+    # Second argument of 1 means "prefer mm/dd/yyyy".
+    # Third argument means that two digit years < 20 are 20xx; >= 29 are 19xx.
+    my $vrpdate = new Search::Xapian::DateValueRangeProcessor($SLOT_DATE, 1,
+							      1920);
+    $qp->add_valuerangeprocessor($vrpdate);
+
+    # Parse the query string and return a Xapian::Query object.
+    my $query = $qp->parse_query(
+	    $query_string,
+	    FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE|FLAG_WILDCARD
+	    );
+
+    print "Internal view of parsed query is:\n$query\n\n";
+
+    $enquire->set_query($query);
+    if (defined $sort_by) {
+	$enquire->set_sort_by_value($sort_by, 0);
+    }
+
+    # Return the top 10 results for the query.
+    my $mset = $enquire->get_mset(0, 10);
+
+    my $msize = $mset->size();
+    if ($msize == 0) {
+	print "No matching documents found.\n";
+	exit 0;
+    }
+
+    # Display the results.
+    if ($mset->get_matches_lower_bound() != $mset->get_matches_upper_bound()) {
+	print "About ";
+    }
+    printf "%u matching documents were found.\n",
+	   $mset->get_matches_estimated();
+    print "Results 1-$msize:\n";
+
+    foreach my $m (tie_mset($mset)) {
+        printf "#%u: Score %u%%: %s\n",
+	      $m->get_rank() + 1,
+	      $m->get_percent(),
+	      $m->get_document()->get_data();
+    }
+};
+if ($@) {
+    # Report the exception which we've caught.
+    print STDERR "Exception: $@\n";
+    exit 1;
+}
+
+# Helper function which allows a Search::Xapian::MSet to be accessed as if it
+# were a Perl array.
+sub tie_mset {
+    my @a;
+    tie( @a, 'Search::Xapian::MSet::Tied', shift );
+    return @a;
+}

Propchange: branches/upstream/libsearch-xapian-perl/current/examples/full-searcher.pl
------------------------------------------------------------------------------
    svn:executable = *

Added: branches/upstream/libsearch-xapian-perl/current/examples/simpleexpand.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/examples/simpleexpand.pl?rev=36489&op=file
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/examples/simpleexpand.pl (added)
+++ branches/upstream/libsearch-xapian-perl/current/examples/simpleexpand.pl Wed May 27 04:23:38 2009
@@ -1,0 +1,112 @@
+#!/usr/bin/perl
+#
+# Simple example script demonstrating query expansion.
+#
+# Copyright (C) 2003 James Aylett
+# Copyright (C) 2004,2006,2007,2009 Olly Betts
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+
+use strict;
+use Search::Xapian (':all');
+
+# We require at least two command line arguments.
+if (scalar @ARGV < 2) {
+    print STDERR "Usage: $0 PATH_TO_DATABASE QUERY [-- [DOCID...]]\n";
+    exit(1);
+}
+
+eval {
+    # Open the database for searching.
+    my $database = Search::Xapian::Database->new(shift @ARGV);
+
+    # Start an enquire session.
+    my $enquire = Search::Xapian::Enquire->new($database);
+
+    # Combine command line arguments up to "--" with spaces between
+    # them, so that simple queries don't have to be quoted at the shell
+    # level.
+    my $sep_index = 0;
+    while (exists $ARGV[$sep_index] && $ARGV[$sep_index] ne '--') {
+	$sep_index++;
+    }
+
+    my $query_string = join ' ', @ARGV[0 .. $sep_index - 1];
+
+    # Create an RSet with the listed docids in.
+    my $reldocs = Search::Xapian::RSet->new();
+    foreach my $did (@ARGV[$sep_index + 1 .. $#ARGV]) {
+        $reldocs->add_document($did);
+	print "rel: $did\n";
+    }
+
+    # Parse the query string to produce a Xapian::Query object.
+    my $qp = Search::Xapian::QueryParser->new();
+    my $stemmer = Search::Xapian::Stem->new("english");
+    $qp->set_stemmer($stemmer);
+    $qp->set_database($database);
+    $qp->set_stemming_strategy(STEM_SOME);
+    my $query = $qp->parse_query($query_string);
+
+    my $mset;
+    if (!$query->empty()) {
+	print "Parsed query is: $query\n";
+
+        # Find the top 10 results for the query.
+	$enquire->set_query($query);
+	$mset = $enquire->get_mset(0, 10, $reldocs);
+
+        # Display the results.
+	printf "%i results found.\n", $mset->get_matches_estimated();
+	printf "Results 1-%i:\n", $mset->size();
+
+	# In 1.0.13.0 and newer you'll be able to replace this with:
+	# foreach my $m ($mset->matches()) {
+	foreach my $m (tie_mset($mset)) {
+	    printf "%i: %i%% docid=%i [%s]\n", $m->get_rank() + 1, $m->get_percent(), $m->get_docid(), $m->get_document()->get_data();
+	}
+    }
+
+    # Put the top 5 (at most) docs into the rset if rset is empty
+    if ($reldocs->empty() && defined $mset) {
+	my $last = $mset->size() - 1;
+	if ($last > 4) {
+	   $last = 4;
+	} 
+	foreach my $m ((tie_mset($mset))[0..$last]) {
+            $reldocs->add_document($m->get_docid());
+	}
+    }
+
+    # Get the suggested expand terms
+    my $eset = $enquire->get_eset(10, $reldocs);
+    printf "%i suggested additional terms\n", $eset->size();
+    my $k = $eset->begin();
+    while ($k != $eset->end()) {
+        printf "%s: %f\n", $k->get_termname(), $k->get_weight();
+        ++$k;
+    }
+};
+if ($@) {
+    print STDERR "Exception: $@\n";
+    exit(1);
+}
+
+sub tie_mset {
+    my @a;
+    tie( @a, 'Search::Xapian::MSet::Tied', shift );
+    return @a;
+}

Propchange: branches/upstream/libsearch-xapian-perl/current/examples/simpleexpand.pl
------------------------------------------------------------------------------
    svn:executable = *

Added: branches/upstream/libsearch-xapian-perl/current/examples/simpleindex.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/examples/simpleindex.pl?rev=36489&op=file
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/examples/simpleindex.pl (added)
+++ branches/upstream/libsearch-xapian-perl/current/examples/simpleindex.pl Wed May 27 04:23:38 2009
@@ -1,0 +1,67 @@
+#!/usr/bin/perl
+#
+# Index each paragraph of a text file as a Xapian document.
+#
+# Copyright (C) 2003 James Aylett
+# Copyright (C) 2004,2007,2009 Olly Betts
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+
+use strict;
+use Search::Xapian (':all');
+
+if (scalar @ARGV != 1) {
+    print STDERR "Usage: $0 PATH_TO_DATABASE\n";
+    exit(1);
+}
+
+eval {
+    # Open the database for update, creating a new database if necessary.
+    my $database = Search::Xapian::WritableDatabase->new($ARGV[0], DB_CREATE_OR_OPEN);
+
+    my $indexer = Search::Xapian::TermGenerator->new();
+    my $stemmer = Search::Xapian::Stem->new("english");
+    $indexer->set_stemmer($stemmer);
+
+    my $para = '';
+    foreach my $line (<STDIN>) {
+	$line =~ s/\s+$//;
+	$line =~ s/^\s+//;
+	if ($line eq '') {
+	    if ($para ne '') {
+		# We've reached the end of a paragraph, so index it.
+		my $doc = Search::Xapian::Document->new();
+		$doc->set_data($para);
+
+		$indexer->set_document($doc);
+		$indexer->index_text($para);
+
+		# Add the document to the database.
+		$database->add_document($doc);
+		$para = '';
+	    }
+	} else {
+	    if ($para ne '') {
+		$para .= ' ';
+	    }
+	    $para .= $line;
+	}
+    }
+};
+if ($@) {
+    print STDERR "Exception: $@\n";
+    exit(1);
+}

Propchange: branches/upstream/libsearch-xapian-perl/current/examples/simpleindex.pl
------------------------------------------------------------------------------
    svn:executable = *

Added: branches/upstream/libsearch-xapian-perl/current/examples/simplematchdecider.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/examples/simplematchdecider.pl?rev=36489&op=file
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/examples/simplematchdecider.pl (added)
+++ branches/upstream/libsearch-xapian-perl/current/examples/simplematchdecider.pl Wed May 27 04:23:38 2009
@@ -1,0 +1,88 @@
+#!/usr/bin/perl
+#
+# Simple command-line match decider example
+#
+# Copyright (C) 2003 James Aylett
+# Copyright (C) 2004,2007,2009 Olly Betts
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+
+use strict;
+use Search::Xapian (':all');
+
+# This example runs a query like simplesearch does, but uses a MatchDecider
+# (mymatchdecider) to discard any document for which value 0 is equal to
+# the string passed as the second command line argument.
+
+# We require at least three command line arguments.
+if (scalar @ARGV < 3) {
+    print STDERR "Usage: $0 PATH_TO_DATABASE AVOID_VALUE QUERY\n";
+    exit(1);
+}
+
+my $avoid_value;
+
+sub mymatchdecider {
+    return $_[0]->get_value(0) ne $avoid_value;
+}
+
+eval {
+    # Open the database for searching.
+    my $database = Search::Xapian::Database->new(shift @ARGV);
+
+    # Start an enquire session.
+    my $enquire = Search::Xapian::Enquire->new($database);
+
+    $avoid_value = shift @ARGV;
+
+    # Combine the rest of the command line arguments with spaces between
+    # them, so that simple queries don't have to be quoted at the shell
+    # level.
+    my $query_string = join ' ', @ARGV;
+
+    # Parse the query string to produce a Xapian::Query object.
+    my $qp = Search::Xapian::QueryParser->new();
+    my $stemmer = Search::Xapian::Stem->new("english");
+    $qp->set_stemmer($stemmer);
+    $qp->set_database($database);
+    $qp->set_stemming_strategy(STEM_SOME);
+    my $query = $qp->parse_query($query_string);
+    print "Parsed query is: $query\n";
+
+    # Find the top 10 results for the query.
+    $enquire->set_query($query);
+    my $mset = $enquire->get_mset(0, 10, \&mymatchdecider);
+
+    # Display the results.
+    printf "%i results found.\n", $mset->get_matches_estimated();
+    printf "Results 1-%i:\n", $mset->size();
+
+    # In 1.0.13.0 and newer you'll be able to replace this with:
+    # foreach my $m ($mset->matches()) {
+    foreach my $m (tie_mset($mset)) {
+        printf "%i: %i%% docid=%i [%s]\n", $m->get_rank() + 1, $m->get_percent(), $m->get_docid(), $m->get_document()->get_data();
+    }
+};
+if ($@) {
+    print STDERR "Exception: $@\n";
+    exit(1);
+}
+
+sub tie_mset {
+    my @a;
+    tie( @a, 'Search::Xapian::MSet::Tied', shift );
+    return @a;
+}

Propchange: branches/upstream/libsearch-xapian-perl/current/examples/simplematchdecider.pl
------------------------------------------------------------------------------
    svn:executable = *

Modified: branches/upstream/libsearch-xapian-perl/current/examples/simplesearch.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/examples/simplesearch.pl?rev=36489&op=diff
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/examples/simplesearch.pl (original)
+++ branches/upstream/libsearch-xapian-perl/current/examples/simplesearch.pl Wed May 27 04:23:38 2009
@@ -1,48 +1,76 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl
+#
+# Simple command-line search script.
+#
+# Copyright (C) 2003 James Aylett
+# Copyright (C) 2004,2007,2009 Olly Betts
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
 
 use strict;
+use Search::Xapian (':all');
 
-use ExtUtils::testlib;
-use Getopt::Std;
-use Search::Xapian qw(:ops);
-
-use vars qw( %opts );
-getopts('d:t:nh', \%opts);
-
-if( exists $opts{h} ) {
-  print <<EOF;
-Synopsis: Searches a Xapian database for a particular term.
-Usage: $0 -d testdb -t help
-Options:
-        -d : database directory
-        -t : search terms
-        -h : displays this help screen
-        -q : quiet; does not display document data
-EOF
-  exit 0;
+# We require at least two command line arguments.
+if (scalar @ARGV < 2) {
+    print STDERR "Usage: $0 PATH_TO_DATABASE QUERY\n";
+    exit(1);
 }
 
-if( !$opts{d} or !$opts{t} ) {
-  print "Usage: $0 -d [database dir] -t [search terms]\n";
-  print "Try $0 -h for further information\n";
-  exit 0;
+eval {
+    # Open the database for searching.
+    my $database = Search::Xapian::Database->new(shift @ARGV);
+
+    # Start an enquire session.
+    my $enquire = Search::Xapian::Enquire->new($database);
+
+    # Combine the rest of the command line arguments with spaces between
+    # them, so that simple queries don't have to be quoted at the shell
+    # level.
+    my $query_string = join ' ', @ARGV;
+
+    # Parse the query string to produce a Xapian::Query object.
+    my $qp = Search::Xapian::QueryParser->new();
+    my $stemmer = Search::Xapian::Stem->new("english");
+    $qp->set_stemmer($stemmer);
+    $qp->set_database($database);
+    $qp->set_stemming_strategy(STEM_SOME);
+    my $query = $qp->parse_query($query_string);
+    print "Parsed query is: $query\n";
+
+    # Find the top 10 results for the query.
+    $enquire->set_query($query);
+    my $mset = $enquire->get_mset(0, 10);
+
+    # Display the results.
+    printf "%i results found.\n", $mset->get_matches_estimated();
+    printf "Results 1-%i:\n", $mset->size();
+
+    # In 1.0.13.0 and newer you'll be able to replace this with:
+    # foreach my $m ($mset->matches()) {
+    foreach my $m (tie_mset($mset)) {
+        printf "%i: %i%% docid=%i [%s]\n", $m->get_rank() + 1, $m->get_percent(), $m->get_docid(), $m->get_document()->get_data();
+    }
+};
+if ($@) {
+    print STDERR "Exception: $@\n";
+    exit(1);
 }
 
-my $db = Search::Xapian::Database->new( $opts{d} );
-my @terms = split ',', $opts{t};
-my $enq = $db->enquire( OP_OR, @terms );
-
-printf "Parsing query '%s'\n", $enq->get_query()->get_description();
-
-my @matches = $enq->matches(0, 10);
-
-print scalar(@matches) . " results found\n";
-
-foreach my $match ( @matches ) {
-  printf "ID %d %d%%", $match->get_docid(), $match->get_percent();
-  if( !defined( $opts{n} ) ) {
-    my $doc = $match->get_document();
-    printf " [ %s ]", $doc->get_data();
-  }
-  print "\n";
+sub tie_mset {
+    my @a;
+    tie( @a, 'Search::Xapian::MSet::Tied', shift );
+    return @a;
 }

Modified: branches/upstream/libsearch-xapian-perl/current/t/tied.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsearch-xapian-perl/current/t/tied.t?rev=36489&op=diff
==============================================================================
--- branches/upstream/libsearch-xapian-perl/current/t/tied.t (original)
+++ branches/upstream/libsearch-xapian-perl/current/t/tied.t Wed May 27 04:23:38 2009
@@ -7,7 +7,7 @@
 
 use Test;
 use Devel::Peek;
-BEGIN { plan tests => 6 };
+BEGIN { plan tests => 19 };
 use Search::Xapian qw(:ops);
 
 #########################
@@ -24,8 +24,10 @@
 
 $enq->set_query( $query );
 
+my $mset;
+ok( $mset = $enq->get_mset(0, 10) );
 my @matches;
-ok( @matches = $enq->matches(0, 10) );
+ok( @matches = $mset->items() );
 my $match;
 ok( $match = $matches[0] );
 ok( $match->get_docid() );
@@ -33,8 +35,31 @@
 
 $matches[0] = 34;
 
+# Check that MSet::matches() gives a warning - it's deprecated in favour of
+# MSet::items() - but still works like items() does.
+my $warned = 0;
+my $old_sig_warn = $SIG{'__WARN__'};
+$SIG{'__WARN__'} = sub { ++$warned; };
+ok( @matches = $mset->matches() );
+ok( $warned == 1 );
+$SIG{'__WARN__'} = $old_sig_warn;
+ok( $match = $matches[0] );
+ok( $match->get_docid() );
+ok( $match->get_percent() );
+
 my $doc;
 ok( $doc = $match->get_document() );
 ok( $doc->get_data() );
 
-1;
+ok( exists $matches[1] );
+ok( !exists $matches[10] );
+ok( exists $matches[-1] );
+
+my @ematches;
+ok( @ematches = $enq->matches(0, 2) );
+
+ok( $match = $ematches[0] );
+ok( $match->get_docid() );
+ok( $match->get_percent() );
+
+1;




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