コード例 #1
0
    print "get_data+set_data doesn't transparently handle a zero byte\n";
    exit(1);
}
$doc->set_data("is there anybody out there?");
$doc->add_term("XYzzy");
$doc->add_posting($stem->apply("is"), 1);
$doc->add_posting($stem->apply("there"), 2);
$doc->add_posting($stem->apply("anybody"), 3);
$doc->add_posting($stem->apply("out"), 4);
$doc->add_posting($stem->apply("there"), 5);
// Check virtual function dispatch.
if (substr($db->get_description(), 0, 17) !== "WritableDatabase(") {
    print "Unexpected \$db->get_description()\n";
    exit(1);
}
$db->add_document($doc);
if ($db->get_doccount() != 1) {
    print "Unexpected \$db->get_doccount()\n";
    exit(1);
}
$terms = array("smoke", "test", "terms");
$query = new XapianQuery(XapianQuery::OP_OR, $terms);
if ($query->get_description() != "Query((smoke OR test OR terms))") {
    print "Unexpected \$query->get_description()\n";
    exit(1);
}
$query1 = new XapianQuery(XapianQuery::OP_PHRASE, array("smoke", "test", "tuple"));
if ($query1->get_description() != "Query((smoke PHRASE 3 test PHRASE 3 tuple))") {
    print "Unexpected \$query1->get_description()\n";
    exit(1);
}
コード例 #2
0
ファイル: simpleindex.php5 プロジェクト: nsmetanin/xapian
    $indexer->set_stemmer($stemmer);

    $para = '';
    $lines = file("php://stdin");
    foreach ($lines as $line) {
	$line = rtrim($line);
	if ($line == "" && $para != "") {
	    // We've reached the end of a paragraph, so index it.
	    $doc = new XapianDocument();
	    $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 != "") {
		$para .= " ";
	    }
	    $para .= $line;
	}
    }

    // Set the database handle to Null to ensure that it gets closed
    // down cleanly or uncommitted changes may be lost.
    $database = Null;
} catch (Exception $e) {
    print $e->getMessage() . "\n";
コード例 #3
0
ファイル: xapian.class.php プロジェクト: bqq1986/efront
 /**
  * Index file contents
  * 
  * @param array $lines The array of the file contents, each entry corresponds to a new line (included) 
  */
 protected function _index($lines, $file_path)
 {
     if (empty($lines)) {
         return false;
     }
     // Open the database for update, creating a new database if necessary.
     $database = new XapianWritableDatabase(self::$_database_path, Xapian::DB_CREATE_OR_OPEN);
     $indexer = new XapianTermGenerator();
     $stemmer = new XapianStem("english");
     $indexer->set_stemmer($stemmer);
     $para = '';
     //$lines = file($path);
     foreach ($lines as $line) {
         $line = rtrim($line);
         if ($line == "" && $para != "") {
             // We've reached the end of a paragraph, so index it.
             $doc = new XapianDocument();
             $doc->set_data($para);
             $doc->add_value('file', $file_path);
             //add meta-information to the entry
             $indexer->set_document($doc);
             $indexer->index_text($para);
             // Add the document to the database.
             $database->add_document($doc);
             $para = "";
         } else {
             if ($para != "") {
                 $para .= " ";
             }
             $para .= $line;
         }
     }
     // Set the database handle to Null to ensure that it gets closed
     // down cleanly or uncommitted changes may be lost.
     $database = Null;
 }