Ticket #287: xapian_standalone_test.php
| File xapian_standalone_test.php, 2.8 kB (added by flav, 5 months ago) |
|---|
| Line | |
|---|---|
| 1 | #!/usr/bin/php |
| 2 | <?php |
| 3 | /* |
| 4 | This simulates a problem I am having with Xapian/PHP/Ubuntu. Reduced |
| 5 | the problem down to this contrived example. |
| 6 | |
| 7 | PHP Error: DatabaseCorruptError: Data ran out unexpectedly when reading posting list. |
| 8 | xapian-check Error: Extra bytes after key for first chunk of posting list for term |
| 9 | |
| 10 | The use case is similar to this: |
| 11 | Many accounts with individual data to be indexed. Using a handful of |
| 12 | custom prefixes to do filtering when querying. When an account is |
| 13 | disabled, the records are purged from the XapianDatabase. |
| 14 | |
| 15 | Errors with: |
| 16 | Ubuntu Hardy 8.04.1 |
| 17 | libxapian15 1.0.5 (Ubuntu current package) |
| 18 | php5 5.2.4 (Ubuntu current package) |
| 19 | |
| 20 | -- Did an upgrade install to 1.0.7 and had same problems errors. |
| 21 | |
| 22 | Works fine under: |
| 23 | Ubuntu Gutsy 7.10 |
| 24 | libxapian15 1.0.2 (Ubuntu current package) |
| 25 | php5 5.2.3 (Ubuntu current package) |
| 26 | |
| 27 | */ |
| 28 | require '/usr/share/php5/xapian.php'; |
| 29 | |
| 30 | $db_file = '/tmp/xapiantest'; |
| 31 | |
| 32 | try { |
| 33 | |
| 34 | /* Changing keys or values will give mixed results. */ |
| 35 | $recipe_for_fail = array ( |
| 36 | 219 => 74, |
| 37 | 221 => 116, |
| 38 | 222 => 199, |
| 39 | 223 => 21, |
| 40 | 224 => 45, |
| 41 | 225 => 155, |
| 42 | 226 => 189, |
| 43 | ); |
| 44 | |
| 45 | $testdata = array (); |
| 46 | $pos = 0; |
| 47 | foreach ($recipe_for_fail as $value => $num) |
| 48 | { |
| 49 | $testdata += array_fill($pos, $num, $value); |
| 50 | $pos += $num; |
| 51 | } |
| 52 | |
| 53 | // Populate Xapian database |
| 54 | $database = new XapianWritableDatabase($db_file, Xapian::DB_CREATE_OR_OPEN); |
| 55 | foreach ($testdata as $value) |
| 56 | { |
| 57 | $doc = new XapianDocument(); |
| 58 | $doc->add_term('XC' . $value); |
| 59 | $doc->add_term('XTabc'); |
| 60 | $doc->add_term('XAdef'); |
| 61 | $doc->add_term('XRghi'); |
| 62 | // Magic quantity, if you comment this, it wont error. |
| 63 | $doc->add_term('XYabc'); |
| 64 | |
| 65 | $database->add_document($doc); |
| 66 | } |
| 67 | $database = null; |
| 68 | |
| 69 | |
| 70 | |
| 71 | // Did not normally delete /all/ entries, however, in testing, this |
| 72 | // gave more consistent results/error. |
| 73 | // Also of note, in production dont actually open the DB twice, however |
| 74 | // the error would show up on subsequent calls, doing the second open |
| 75 | // in here to reproduce multiple calls in one pass. |
| 76 | $database = new XapianWritableDatabase($db_file, Xapian::DB_CREATE_OR_OPEN); |
| 77 | foreach (array_keys ($recipe_for_fail) as $value) |
| 78 | { |
| 79 | $database->delete_document('XC' . $value); |
| 80 | } |
| 81 | $database = null; |
| 82 | |
| 83 | // Running xapian check on DB shows the errors. In normal use, the |
| 84 | // database would work somewhat unless querying for one of the deleted |
| 85 | // records. |
| 86 | system("xapian-check $db_file"); |
| 87 | |
| 88 | echo "Dont forget to remove the db file before next test. ($db_file)\n"; |
| 89 | //echo "Cleanup\n"; |
| 90 | //system("rm -Rf $db_file"); |
| 91 | |
| 92 | } catch (Exception $e) { |
| 93 | print $e->getMessage() . "\n"; |
| 94 | exit(1); |
| 95 | } |
