SearchTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <?php
  2. /**
  3. * @category Zend
  4. * @package Zend_Search_Lucene
  5. * @subpackage UnitTests
  6. */
  7. /**
  8. * Zend_Search_Lucene
  9. */
  10. require_once 'Zend/Search/Lucene.php';
  11. /**
  12. * PHPUnit test case
  13. */
  14. require_once 'PHPUnit/Framework/TestCase.php';
  15. /**
  16. * @category Zend
  17. * @package Zend_Search_Lucene
  18. * @subpackage UnitTests
  19. */
  20. class Zend_Search_Lucene_SearchTest extends PHPUnit_Framework_TestCase
  21. {
  22. public function testQueryParser()
  23. {
  24. $wildcardMinPrefix = Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength();
  25. Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0);
  26. $defaultPrefixLength = Zend_Search_Lucene_Search_Query_Fuzzy::getDefaultPrefixLength();
  27. Zend_Search_Lucene_Search_Query_Fuzzy::setDefaultPrefixLength(0);
  28. $queries = array('title:"The Right Way" AND text:go',
  29. 'title:"Do it right" AND right',
  30. 'title:Do it right',
  31. 'te?t',
  32. 'test*',
  33. 'te*t',
  34. '?Ma*',
  35. // 'te?t~20^0.8',
  36. 'test~',
  37. 'test~0.4',
  38. '"jakarta apache"~10',
  39. 'contents:[business TO by]',
  40. '{wish TO zzz}',
  41. 'jakarta apache',
  42. 'jakarta^4 apache',
  43. '"jakarta apache"^4 "Apache Lucene"',
  44. '"jakarta apache" jakarta',
  45. '"jakarta apache" OR jakarta',
  46. '"jakarta apache" || jakarta',
  47. '"jakarta apache" AND "Apache Lucene"',
  48. '"jakarta apache" && "Apache Lucene"',
  49. '+jakarta apache',
  50. '"jakarta apache" AND NOT "Apache Lucene"',
  51. '"jakarta apache" && !"Apache Lucene"',
  52. '\\ ',
  53. 'NOT "jakarta apache"',
  54. '!"jakarta apache"',
  55. '"jakarta apache" -"Apache Lucene"',
  56. '(jakarta OR apache) AND website',
  57. '(jakarta || apache) && website',
  58. 'title:(+return +"pink panther")',
  59. 'title:(+re\\turn\\ value +"pink panther\\"" +body:cool)',
  60. '+contents:apache +type:1 +id:5',
  61. 'contents:apache AND type:1 AND id:5',
  62. 'f1:word1 f1:word2 and f1:word3',
  63. 'f1:word1 not f1:word2 and f1:word3'
  64. );
  65. $rewrittenQueries = array('+(title:"the right way") +(text:go)',
  66. '+(title:"do it right") +(path:right modified:right contents:right)',
  67. '(title:do) (path:it modified:it contents:it) (path:right modified:right contents:right)',
  68. '(contents:test contents:text)',
  69. '(contents:test contents:tested)',
  70. '(contents:test contents:text)',
  71. '(contents:amazon contents:email)',
  72. // ....
  73. '((contents:test) (contents:text^0.5))',
  74. '((contents:test) (contents:text^0.5833) (contents:latest^0.1667) (contents:left^0.1667) (contents:list^0.1667) (contents:meet^0.1667) (contents:must^0.1667) (contents:next^0.1667) (contents:post^0.1667) (contents:sect^0.1667) (contents:task^0.1667) (contents:tested^0.1667) (contents:that^0.1667) (contents:tort^0.1667))',
  75. '((path:"jakarta apache"~10) (modified:"jakarta apache"~10) (contents:"jakarta apache"~10))',
  76. '(contents:business contents:but contents:buy contents:buying contents:by)',
  77. '(path:wishlist contents:wishlist contents:wishlists contents:with contents:without contents:won contents:work contents:would contents:write contents:writing contents:written contents:www contents:xml contents:xmlrpc contents:you contents:your)',
  78. '(path:jakarta modified:jakarta contents:jakarta) (path:apache modified:apache contents:apache)',
  79. '((path:jakarta modified:jakarta contents:jakarta)^4) (path:apache modified:apache contents:apache)',
  80. '(((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache"))^4) ((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))',
  81. '((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) (path:jakarta modified:jakarta contents:jakarta)',
  82. '((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) (path:jakarta modified:jakarta contents:jakarta)',
  83. '((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) (path:jakarta modified:jakarta contents:jakarta)',
  84. '+((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) +((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))',
  85. '+((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) +((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))',
  86. '+(path:jakarta modified:jakarta contents:jakarta) (path:apache modified:apache contents:apache)',
  87. '+((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) -((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))',
  88. '+((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) -((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))',
  89. '(<InsignificantQuery>)',
  90. '<InsignificantQuery>',
  91. '<InsignificantQuery>',
  92. '((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) -((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))',
  93. '+((path:jakarta modified:jakarta contents:jakarta) (path:apache modified:apache contents:apache)) +(path:website modified:website contents:website)',
  94. '+((path:jakarta modified:jakarta contents:jakarta) (path:apache modified:apache contents:apache)) +(path:website modified:website contents:website)',
  95. '(+(title:return) +(title:"pink panther"))',
  96. '(+(+title:return +title:value) +(title:"pink panther") +(body:cool))',
  97. '+(contents:apache) +(<InsignificantQuery>) +(<InsignificantQuery>)',
  98. '+(contents:apache) +(<InsignificantQuery>) +(<InsignificantQuery>)',
  99. '(f1:word) (+(f1:word) +(f1:word))',
  100. '(f1:word) (-(f1:word) +(f1:word))');
  101. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  102. foreach ($queries as $id => $queryString) {
  103. $query = Zend_Search_Lucene_Search_QueryParser::parse($queryString);
  104. $this->assertTrue($query instanceof Zend_Search_Lucene_Search_Query);
  105. $this->assertEquals($query->rewrite($index)->__toString(), $rewrittenQueries[$id]);
  106. }
  107. Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength($wildcardMinPrefix);
  108. Zend_Search_Lucene_Search_Query_Fuzzy::setDefaultPrefixLength($defaultPrefixLength);
  109. }
  110. public function testQueryParserExceptionsHandling()
  111. {
  112. $this->assertTrue(Zend_Search_Lucene_Search_QueryParser::queryParsingExceptionsSuppressed());
  113. try {
  114. $query = Zend_Search_Lucene_Search_QueryParser::parse('contents:[business TO by}');
  115. } catch (Zend_Search_Lucene_Exception $e) {
  116. $this->fail('exception raised while parsing a query');
  117. }
  118. $this->assertEquals('contents business to by', $query->__toString());
  119. Zend_Search_Lucene_Search_QueryParser::dontSuppressQueryParsingExceptions();
  120. $this->assertFalse(Zend_Search_Lucene_Search_QueryParser::queryParsingExceptionsSuppressed());
  121. try {
  122. $query = Zend_Search_Lucene_Search_QueryParser::parse('contents:[business TO by}');
  123. $this->fail('exception wasn\'t raised while parsing a query');
  124. } catch (Zend_Search_Lucene_Exception $e) {
  125. $this->assertEquals('Syntax error at char position 25.', $e->getMessage());
  126. }
  127. Zend_Search_Lucene_Search_QueryParser::suppressQueryParsingExceptions();
  128. $this->assertTrue(Zend_Search_Lucene_Search_QueryParser::queryParsingExceptionsSuppressed());
  129. }
  130. public function testEmptyQuery()
  131. {
  132. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  133. $hits = $index->find('');
  134. $this->assertEquals(count($hits), 0);
  135. }
  136. public function testTermQuery()
  137. {
  138. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  139. $hits = $index->find('submitting');
  140. $this->assertEquals(count($hits), 3);
  141. $expectedResultset = array(array(2, 0.114555, 'IndexSource/contributing.patches.html'),
  142. array(7, 0.112241, 'IndexSource/contributing.bugs.html'),
  143. array(8, 0.112241, 'IndexSource/contributing.html'));
  144. foreach ($hits as $resId => $hit) {
  145. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  146. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  147. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  148. }
  149. }
  150. public function testMultiTermQuery()
  151. {
  152. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  153. $hits = $index->find('submitting AND wishlists');
  154. $this->assertEquals(count($hits), 1);
  155. $this->assertEquals($hits[0]->id, 8);
  156. $this->assertTrue( abs($hits[0]->score - 0.141633) < 0.000001 );
  157. $this->assertEquals($hits[0]->path, 'IndexSource/contributing.html');
  158. }
  159. public function testPraseQuery()
  160. {
  161. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  162. $hits = $index->find('"reporting bugs"');
  163. $this->assertEquals(count($hits), 4);
  164. $expectedResultset = array(array(0, 0.247795, 'IndexSource/contributing.documentation.html'),
  165. array(7, 0.212395, 'IndexSource/contributing.bugs.html'),
  166. array(8, 0.212395, 'IndexSource/contributing.html'),
  167. array(2, 0.176996, 'IndexSource/contributing.patches.html'));
  168. foreach ($hits as $resId => $hit) {
  169. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  170. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  171. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  172. }
  173. }
  174. public function testBooleanQuery()
  175. {
  176. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  177. $hits = $index->find('submitting AND (wishlists OR requirements)');
  178. $this->assertEquals(count($hits), 2);
  179. $expectedResultset = array(array(7, 0.095697, 'IndexSource/contributing.bugs.html'),
  180. array(8, 0.075573, 'IndexSource/contributing.html'));
  181. foreach ($hits as $resId => $hit) {
  182. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  183. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  184. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  185. }
  186. }
  187. public function testBooleanQueryWithPhraseSubquery()
  188. {
  189. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  190. $hits = $index->find('"PEAR developers" AND Home');
  191. $this->assertEquals(count($hits), 1);
  192. $expectedResultset = array(array(1, 0.168270, 'IndexSource/contributing.wishlist.html'));
  193. foreach ($hits as $resId => $hit) {
  194. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  195. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  196. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  197. }
  198. }
  199. public function testBooleanQueryWithNonExistingPhraseSubquery()
  200. {
  201. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  202. $query = Zend_Search_Lucene_Search_QueryParser::parse('"Non-existing phrase" AND Home');
  203. $this->assertEquals($query->__toString(), '+("Non-existing phrase") +(Home)');
  204. $this->assertEquals($query->rewrite($index)->__toString(),
  205. '+((path:"non existing phrase") (modified:"non existing phrase") (contents:"non existing phrase")) +(path:home modified:home contents:home)');
  206. $this->assertEquals($query->rewrite($index)->optimize($index)->__toString(), '<EmptyQuery>');
  207. }
  208. public function testFilteredTokensQueryParserProcessing()
  209. {
  210. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  211. $this->assertEquals(count(Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize('123456787654321')), 0);
  212. $hits = $index->find('"PEAR developers" AND Home AND 123456787654321');
  213. $this->assertEquals(count($hits), 1);
  214. $expectedResultset = array(array(1, 0.168270, 'IndexSource/contributing.wishlist.html'));
  215. foreach ($hits as $resId => $hit) {
  216. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  217. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  218. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  219. }
  220. }
  221. public function testWildcardQuery()
  222. {
  223. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  224. $wildcardMinPrefix = Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength();
  225. Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0);
  226. $hits = $index->find('*cont*');
  227. $this->assertEquals(count($hits), 9);
  228. $expectedResultset = array(array(8, 0.125253, 'IndexSource/contributing.html'),
  229. array(4, 0.112122, 'IndexSource/copyright.html'),
  230. array(2, 0.108491, 'IndexSource/contributing.patches.html'),
  231. array(7, 0.077716, 'IndexSource/contributing.bugs.html'),
  232. array(0, 0.050760, 'IndexSource/contributing.documentation.html'),
  233. array(1, 0.049163, 'IndexSource/contributing.wishlist.html'),
  234. array(3, 0.036159, 'IndexSource/about-pear.html'),
  235. array(5, 0.021500, 'IndexSource/authors.html'),
  236. array(9, 0.007422, 'IndexSource/core.html'));
  237. foreach ($hits as $resId => $hit) {
  238. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  239. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  240. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  241. }
  242. Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength($wildcardMinPrefix);
  243. }
  244. public function testFuzzyQuery()
  245. {
  246. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  247. $defaultPrefixLength = Zend_Search_Lucene_Search_Query_Fuzzy::getDefaultPrefixLength();
  248. Zend_Search_Lucene_Search_Query_Fuzzy::setDefaultPrefixLength(0);
  249. $hits = $index->find('tesd~0.4');
  250. $this->assertEquals(count($hits), 9);
  251. $expectedResultset = array(array(2, 0.037139, 'IndexSource/contributing.patches.html'),
  252. array(0, 0.008735, 'IndexSource/contributing.documentation.html'),
  253. array(7, 0.002449, 'IndexSource/contributing.bugs.html'),
  254. array(1, 0.000483, 'IndexSource/contributing.wishlist.html'),
  255. array(3, 0.000483, 'IndexSource/about-pear.html'),
  256. array(9, 0.000483, 'IndexSource/core.html'),
  257. array(5, 0.000414, 'IndexSource/authors.html'),
  258. array(8, 0.000414, 'IndexSource/contributing.html'),
  259. array(4, 0.000345, 'IndexSource/copyright.html'));
  260. foreach ($hits as $resId => $hit) {
  261. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  262. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  263. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  264. }
  265. Zend_Search_Lucene_Search_Query_Fuzzy::setDefaultPrefixLength($defaultPrefixLength);
  266. }
  267. public function testInclusiveRangeQuery()
  268. {
  269. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  270. $hits = $index->find('[xml TO zzzzz]');
  271. $this->assertEquals(count($hits), 5);
  272. $expectedResultset = array(array(4, 0.156366, 'IndexSource/copyright.html'),
  273. array(2, 0.080458, 'IndexSource/contributing.patches.html'),
  274. array(7, 0.060214, 'IndexSource/contributing.bugs.html'),
  275. array(1, 0.009687, 'IndexSource/contributing.wishlist.html'),
  276. array(5, 0.005871, 'IndexSource/authors.html'));
  277. foreach ($hits as $resId => $hit) {
  278. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  279. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  280. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  281. }
  282. }
  283. public function testNonInclusiveRangeQuery()
  284. {
  285. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  286. $hits = $index->find('{xml TO zzzzz}');
  287. $this->assertEquals(count($hits), 5);
  288. $expectedResultset = array(array(2, 0.1308671, 'IndexSource/contributing.patches.html'),
  289. array(7, 0.0979391, 'IndexSource/contributing.bugs.html'),
  290. array(4, 0.0633930, 'IndexSource/copyright.html'),
  291. array(1, 0.0157556, 'IndexSource/contributing.wishlist.html'),
  292. array(5, 0.0095493, 'IndexSource/authors.html'));
  293. foreach ($hits as $resId => $hit) {
  294. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  295. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  296. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  297. }
  298. }
  299. public function testDefaultSearchField()
  300. {
  301. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  302. $storedDefaultSearchField = Zend_Search_Lucene::getDefaultSearchField();
  303. Zend_Search_Lucene::setDefaultSearchField('path');
  304. $hits = $index->find('contributing');
  305. $this->assertEquals(count($hits), 5);
  306. $expectedResultset = array(array(8, 0.847922, 'IndexSource/contributing.html'),
  307. array(0, 0.678337, 'IndexSource/contributing.documentation.html'),
  308. array(1, 0.678337, 'IndexSource/contributing.wishlist.html'),
  309. array(2, 0.678337, 'IndexSource/contributing.patches.html'),
  310. array(7, 0.678337, 'IndexSource/contributing.bugs.html'));
  311. foreach ($hits as $resId => $hit) {
  312. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  313. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  314. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  315. }
  316. Zend_Search_Lucene::setDefaultSearchField($storedDefaultSearchField);
  317. }
  318. public function testQueryHit()
  319. {
  320. // Restore default search field if it wasn't done by previous test because of failure
  321. Zend_Search_Lucene::setDefaultSearchField(null);
  322. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  323. $hits = $index->find('submitting AND wishlists');
  324. $hit = $hits[0];
  325. $this->assertTrue($hit instanceof Zend_Search_Lucene_Search_QueryHit);
  326. $this->assertTrue($hit->getIndex() instanceof Zend_Search_Lucene_Interface);
  327. $doc = $hit->getDocument();
  328. $this->assertTrue($doc instanceof Zend_Search_Lucene_Document);
  329. $this->assertEquals($doc->path, 'IndexSource/contributing.html');
  330. }
  331. public function testDelayedResourceCleanUp()
  332. {
  333. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  334. $hits = $index->find('submitting AND wishlists');
  335. unset($index);
  336. $hit = $hits[0];
  337. $this->assertTrue($hit instanceof Zend_Search_Lucene_Search_QueryHit);
  338. $this->assertTrue($hit->getIndex() instanceof Zend_Search_Lucene_Interface);
  339. $doc = $hit->getDocument();
  340. $this->assertTrue($doc instanceof Zend_Search_Lucene_Document);
  341. $this->assertTrue($hit->getIndex() instanceof Zend_Search_Lucene_Interface);
  342. $this->assertEquals($doc->path, 'IndexSource/contributing.html');
  343. }
  344. public function testSortingResult()
  345. {
  346. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  347. $hits = $index->find('"reporting bugs"', 'path');
  348. $this->assertEquals(count($hits), 4);
  349. $expectedResultset = array(array(7, 0.212395, 'IndexSource/contributing.bugs.html'),
  350. array(0, 0.247795, 'IndexSource/contributing.documentation.html'),
  351. array(8, 0.212395, 'IndexSource/contributing.html'),
  352. array(2, 0.176996, 'IndexSource/contributing.patches.html'));
  353. foreach ($hits as $resId => $hit) {
  354. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  355. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  356. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  357. }
  358. }
  359. public function testLimitingResult()
  360. {
  361. $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_indexSample/_files');
  362. $storedResultSetLimit = Zend_Search_Lucene::getResultSetLimit();
  363. Zend_Search_Lucene::setResultSetLimit(3);
  364. $hits = $index->find('"reporting bugs"', 'path');
  365. $this->assertEquals(count($hits), 3);
  366. $expectedResultset = array(array(7, 0.212395, 'IndexSource/contributing.bugs.html'),
  367. array(0, 0.247795, 'IndexSource/contributing.documentation.html'),
  368. array(2, 0.176996, 'IndexSource/contributing.patches.html'));
  369. foreach ($hits as $resId => $hit) {
  370. $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
  371. $this->assertTrue( abs($hit->score - $expectedResultset[$resId][1]) < 0.000001 );
  372. $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
  373. }
  374. Zend_Search_Lucene::setResultSetLimit($storedResultSetLimit);
  375. }
  376. }