コード例 #1
0
function index($datapath, $dbpath)
{
    // Create or open the database we're going to be writing to.
    $db = new XapianWritableDatabase($dbpath, Xapian::DB_CREATE_OR_OPEN);
    // Set up a TermGenerator that we'll use in indexing
    $termgenerator = new XapianTermGenerator();
    $termgenerator->set_stemmer(new XapianStem('en'));
    // open the file
    $fH = open_file($datapath);
    //    Read the header row in
    $headers = get_csv_headers($fH);
    while (($row = parse_csv_row($fH, $headers)) !== false) {
        // mapping from field name to value using first row headers
        // We're just going to use id_NUMBER, TITLE and DESCRIPTION
        $description = $row['DESCRIPTION'];
        $title = $row['TITLE'];
        $identifier = $row['id_NUMBER'];
        $collection = $row['COLLECTION'];
        $maker = $row['MAKER'];
        // we make a document and tell the term generator to use this
        $doc = new XapianDocument();
        $termgenerator->set_document($doc);
        // index each field with a suitable prefix
        $termgenerator->index_text($title, 1, 'S');
        $termgenerator->index_text($description, 1, 'XD');
        // index fields without prefixes for general search
        $termgenerator->index_text($title);
        $termgenerator->increase_termpos();
        $termgenerator->index_text($description);
        ### Start of new indexing code.
        // index the MATERIALS field, splitting on semicolons
        $materials = explode(";", $row['MATERIALS']);
        foreach ($materials as $material) {
            $material = strtolower(trim($material));
            if ($material != '') {
                $doc->add_boolean_term('XM' . $material);
            }
        }
        ### End of new indexing code.
        // store all the fields for display purposes
        $doc->set_data(json_encode($row));
        // we use the identifier to ensure each object ends up
        // in the database only once no matter how many times
        // we run the indexer
        $idterm = "Q" . $identifier;
        $doc->add_term($idterm);
        $db->replace_document($idterm, $doc);
    }
}
コード例 #2
0
function index($datapath, $dbpath)
{
    // Create or open the database we're going to be writing to.
    $db = new XapianWritableDatabase($dbpath, Xapian::DB_CREATE_OR_OPEN);
    // Set up a TermGenerator that we'll use in indexing.
    $termgenerator = new XapianTermGenerator();
    $termgenerator->set_stemmer(new XapianStem('english'));
    // Open the file.
    $fH = open_file($datapath);
    // Read the header row in.
    $headers = get_csv_headers($fH);
    while (($row = parse_csv_row($fH, $headers)) !== false) {
        // '$row' maps field name to value.  The field names come from the
        // first row of the CSV file.
        //
        // We're just going to use DESCRIPTION, TITLE and id_NUMBER.
        $description = $row['DESCRIPTION'];
        $title = $row['TITLE'];
        $identifier = $row['id_NUMBER'];
        // We make a document and tell the term generator to use this.
        $doc = new XapianDocument();
        $termgenerator->set_document($doc);
        // Index each field with a suitable prefix.
        $termgenerator->index_text($title, 1, 'S');
        $termgenerator->index_text($description, 1, 'XD');
        // Index fields without prefixes for general search.
        $termgenerator->index_text($title);
        $termgenerator->increase_termpos();
        $termgenerator->index_text($description);
        // Store all the fields for display purposes.
        $doc->set_data(json_encode($row));
        // We use the identifier to ensure each object ends up in the
        // database only once no matter how many times we run the
        // indexer.
        $idterm = "Q" . $identifier;
        $doc->add_boolean_term($idterm);
        $db->replace_document($idterm, $doc);
    }
}
コード例 #3
0
ファイル: simpleindex.php5 プロジェクト: nsmetanin/xapian
    $indexer = new XapianTermGenerator();
    $stemmer = new XapianStem("english");
    $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.
コード例 #4
0
    $values[$term] = $k->get_termfreq();
}
$expected = array("ABB" => 1, "ABC" => 1, "ABC" => 1, "ABCD" => 1, "ABCÿ" => 1);
if ($values != $expected) {
    print "Unexpected matchspy values():\n";
    var_dump($values);
    var_dump($expected);
    print "\n";
    exit(1);
}
# Regression test for SWIG bug - it was generating "return $r;" in wrapper
# functions which didn't set $r.
$indexer = new XapianTermGenerator();
$doc = new XapianDocument();
$indexer->set_document($doc);
$indexer->index_text("I ask nothing in return");
$indexer->index_text_without_positions("Tea time");
$indexer->index_text("Return in time");
$s = '';
foreach ($doc->termlist_begin() as $term) {
    $s .= $term . ' ';
}
if ($s !== 'ask i in nothing return tea time ') {
    print "PHP Iterator wrapping of TermIterator doesn't work ({$s})\n";
    exit(1);
}
$s = '';
foreach ($doc->termlist_begin() as $k => $term) {
    $s .= $term . ':' . $k->get_wdf() . ' ';
}
if ($s !== 'ask:1 i:1 in:2 nothing:1 return:2 tea:1 time:2 ') {
コード例 #5
0
ファイル: smoketest.php プロジェクト: networkimprov/xapian
$query = XapianQuery::MatchNothing();
if ($query->get_description() != 'Xapian::Query()') {
    print "Unexpected \$query->get_description():\n";
    print $query->get_description() . "\n";
    exit(1);
}
$matchspy = new XapianValueCountMatchSpy(0);
$enquire->add_matchspy($matchspy);
$enquire->get_mset(0, 10);
$beg = $matchspy->values_begin();
$end = $matchspy->values_end();
$values = array();
while (!$beg->equals($end)) {
    $values[$beg->get_term()] = $beg->get_termfreq();
    $beg->next();
}
$expected = array("ABB" => 1, "ABC" => 1, "ABC" => 1, "ABCD" => 1, "ABCÿ" => 1);
if ($values != $expected) {
    print "Unexpected matchspy values():\n";
    var_dump($values);
    var_dump($expected);
    print "\n";
    exit(1);
}
# Regression test for SWIG bug - it was generating "return $r;" in wrapper
# functions which didn't set $r.
$indexer = new XapianTermGenerator();
$doc = new XapianDocument();
$indexer->set_document($doc);
$indexer->index_text("I ask nothing in return");
$indexer->index_text_without_positions("Tea time");
コード例 #6
0
ファイル: indexer.php プロジェクト: ratan203/who-said
                $text = trim($text);
                if (!$text) {
                    continue;
                }
                $noise = 0;
                if ($text != 'I' && !preg_match('#[a-z!.]#', $text) && $color == 'white') {
                    $noise = 1;
                }
                $id = "{$series}-{$epid}-{$rowcount}";
                $doc = new XapianDocument();
                $indexer->set_document($doc);
                $doc->set_data($text);
                $doc->add_term("A{$align}");
                $doc->add_term("B{$begin}");
                $doc->add_term("C{$color}");
                $doc->add_term("E{$epid}");
                $doc->add_term("I{$rowcount}");
                $doc->add_term("N{$noise}");
                $doc->add_term("Q{$id}");
                $doc->add_term("S{$series}");
                $doc->add_value(0, Xapian::sortable_serialise($beginN));
                $doc->add_value(1, sprintf("%d%02d", $series, $epid));
                $indexer->index_text($text);
                $db->add_document($doc);
                $rowcount++;
            }
            $lasttextarr = $safetextarr;
        }
    }
}
$db = null;
コード例 #7
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;
 }