コード例 #1
0
ファイル: MoreLikeThisTest.php プロジェクト: rjsmelo/tiki
 function testDocumentTooDifferent()
 {
     $query = new Search_Query();
     $query->filterSimilar('wiki page', 'X');
     $results = $query->search($this->index);
     $this->assertCount(0, $results);
 }
コード例 #2
0
ファイル: IndexerTest.php プロジェクト: rjsmelo/tiki
 function testPartialUpdate()
 {
     $initialSource = new Search_ContentSource_Static(array('HomePage' => array('data' => 'initial'), 'SomePage' => array('data' => 'initial'), 'Untouchable' => array('data' => 'initial')), array('data' => 'sortable'));
     $finalSource = new Search_ContentSource_Static(array('SomePage' => array('data' => 'final'), 'OtherPage' => array('data' => 'final'), 'Untouchable' => array('data' => 'final')), array('data' => 'sortable'));
     $dir = dirname(__FILE__) . '/test_index';
     $edir = escapeshellarg($dir);
     `rm -Rf {$edir}`;
     $index = new Search_Lucene_Index($dir);
     $indexer = new Search_Indexer($index);
     $indexer->addContentSource('wiki page', $initialSource);
     $indexer->rebuild();
     $indexer = new Search_Indexer($index);
     $indexer->addContentSource('wiki page', $finalSource);
     $indexer->update(array(array('object_type' => 'wiki page', 'object_id' => 'HomePage'), array('object_type' => 'wiki page', 'object_id' => 'SomePage'), array('object_type' => 'wiki page', 'object_id' => 'OtherPage')));
     $query = new Search_Query();
     $query->filterType('wiki page');
     $result = $query->search($index);
     $this->assertEquals(3, count($result));
     $doc0 = $result[0];
     $doc1 = $result[1];
     $doc2 = $result[2];
     $this->assertEquals('Untouchable', $doc0['object_id']);
     $this->assertEquals('initial', $doc0['data']);
     $this->assertEquals('final', $doc1['data']);
     $this->assertEquals('final', $doc2['data']);
     `rm -Rf {$edir}`;
 }
コード例 #3
0
 function testWeightImpact()
 {
     $query = new Search_Query();
     $query->setWeightCalculator(new Search_Query_WeightCalculator_Field(array('text_field' => 100, 'other_field' => 0.0001)));
     $query->filterContent('foobar', array('text_field', 'other_field'));
     $results = $query->search($this->index);
     $this->assertOrderIs('BA', $results);
 }
コード例 #4
0
ファイル: IndexTest.php プロジェクト: hurcane/tiki-azure
 function testIndexProvidesHighlightHelper()
 {
     $query = new Search_Query('foobar or hello');
     $resultSet = $query->search($this->index);
     $plugin = new Search_Formatter_Plugin_WikiTemplate('{display name=highlight}');
     $formatter = new Search_Formatter($plugin);
     $output = $formatter->format($resultSet);
     $this->assertContains('<em>Hello</em>', $output);
     $this->assertNotContains('<body>', $output);
 }
コード例 #5
0
ファイル: CamelCaseTest.php プロジェクト: rjsmelo/tiki
 function testCamelCaseNotEnabled()
 {
     $index = new Search_Elastic_Index($this->connection, 'test_index');
     $index->destroy();
     $typeFactory = $index->getTypeFactory();
     $index->addDocument(['object_type' => $typeFactory->identifier('wiki page'), 'object_id' => $typeFactory->identifier('CamelCase Words'), 'title' => $typeFactory->plaintext('CamelCase Words')]);
     $query = new Search_Query();
     $query->filterContent('Camel AND Word', 'title');
     $this->assertEquals(0, count($query->search($index)));
 }
コード例 #6
0
ファイル: FacetTest.php プロジェクト: rjsmelo/tiki
 function testRequireFacet()
 {
     $facet = new Search_Query_Facet_Term('categories');
     $query = new Search_Query();
     $query->filterType('wiki page');
     $query->requestFacet($facet);
     $result = $query->search($this->index);
     $values = $result->getFacet($facet);
     $this->assertEquals(new Search_ResultSet_FacetFilter($facet, array(array('value' => 1, 'count' => 3), array('value' => 2, 'count' => 2), array('value' => 'orphan', 'count' => 1), array('value' => 3, 'count' => 1))), $values);
 }
コード例 #7
0
 function testTransformsApplyPerIndex()
 {
     $query = new Search_Query('Hello');
     $query->applyTransform(new Search\Federated\UrlPrefixTransform('http://foo.example.com'));
     $sub = new Search_Query('Hello');
     $sub->applyTransform(new Search\Federated\UrlPrefixTransform('http://bar.example.com/'));
     $query->includeForeign('test_index_c', $sub);
     $result = $query->search($this->indexA);
     $urls = [$result[0]['url'], $result[1]['url']];
     $this->assertContains('http://foo.example.com/PageA', $urls);
     $this->assertContains('http://bar.example.com/PageC', $urls);
 }
コード例 #8
0
ファイル: LargeDatasetTest.php プロジェクト: rjsmelo/tiki
 /**
  * @expectedException Search_MySql_LimitReachedException
  */
 function testManyIndexes()
 {
     $typeFactory = $this->index->getTypeFactory();
     $document = array('object_type' => $typeFactory->identifier('test'), 'object_id' => $typeFactory->identifier('test'));
     $query = new Search_Query();
     for ($i = 0; 1000 > $i; ++$i) {
         $document['field_' . $i] = $typeFactory->sortable('test');
         $query->filterInitial('test', 'field_' . $i);
     }
     $this->index->addDocument($document);
     $query->search($this->index);
 }
コード例 #9
0
 private function assertResultCorrect($count, $from, $perPage, $first, $last)
 {
     $this->addDocuments($count);
     $query = new Search_Query();
     $query->filterType('article');
     $query->setRange($from, $perPage);
     $result = $query->search($this->index);
     $this->assertEquals($count, count($result), 'total count');
     $real = array();
     foreach ($result as $hit) {
         $real[] = $hit;
     }
     $this->assertEquals($first, $real[0]['object_id'], 'first entry');
     $this->assertEquals($last, $real[count($real) - 1]['object_id'], 'last entry');
 }
コード例 #10
0
function smarty_block_ifsearchnotexists($params, $content, $smarty, &$repeat)
{
    if (empty($params['type']) || empty($params['id'])) {
        return '';
    }
    TikiLib::lib('access')->check_feature('feature_search');
    $query = new Search_Query();
    $query->addObject($params['type'], $params['id']);
    $index = TikiLib::lib('unifiedsearch')->getIndex();
    $result = $query->search($index);
    if ($result->count() > 0) {
        return '';
    } else {
        return $content;
    }
}
コード例 #11
0
 private function processObjects($function, $categId, $objects)
 {
     $unifiedsearchlib = TikiLib::lib('unifiedsearch');
     foreach ($objects as $object) {
         $type = $object['type'];
         $id = $object['id'];
         $this->{$function}($categId, $type, $id);
         $unifiedsearchlib->invalidateObject($type, $id);
     }
     $unifiedsearchlib->processUpdateQueue(count($objects) * 2);
     $query = new Search_Query();
     $query->filterCategory((string) $categId);
     $query->filterPermissions(Perms::get()->getGroups());
     $query->setRange(0, 1);
     $result = $query->search($unifiedsearchlib->getIndex());
     return array('categId' => $categId, 'count' => count($result), 'objects' => $objects, 'confirm' => 1);
 }
コード例 #12
0
ファイル: NumericTest.php プロジェクト: rjsmelo/tiki
 private function assertResultCount($count, $argument)
 {
     $query = new Search_Query();
     $query->filterContent($argument);
     $this->assertEquals($count, count($query->search($this->index)));
 }
コード例 #13
0
ファイル: StemmingTest.php プロジェクト: jkimdon/cohomeals
 function testHebrewString()
 {
     $query = new Search_Query();
     $query->filterContent('מחשב', 'hebrew');
     $this->assertEquals(1, count($query->search($this->index)));
 }
コード例 #14
0
ファイル: QueryTest.php プロジェクト: railfuture/tiki-website
 function testApplyWeight()
 {
     $index = new Search_Index_Memory();
     $query = new Search_Query();
     $query->setWeightCalculator(new Search_Query_WeightCalculator_Field(array('title' => 5.5, 'allowed_groups' => 0.0001)));
     $query->filterContent('hello', array('contents', 'title'));
     $query->filterPermissions(array('Anonymous'));
     $query->search($index);
     $expr = new Search_Expr_And(array(new Search_Expr_Or(array(new Search_Expr_Token('hello', 'plaintext', 'contents', 1.0), new Search_Expr_Token('hello', 'plaintext', 'title', 5.5))), new Search_Expr_Or(array(new Search_Expr_Token('Anonymous', 'multivalue', 'allowed_groups', 0.0001)))));
     $this->assertEquals($expr, $index->getLastQuery());
 }
コード例 #15
0
 private function assertResultFound($word, $index, $count = 1)
 {
     $query = new Search_Query($word);
     $result = $query->search($index);
     $this->assertEquals($count, count($result));
 }
コード例 #16
0
ファイル: LuceneTest.php プロジェクト: hurcane/tiki-azure
 private function assertResultCount($count, $filterMethod, $argument)
 {
     $arguments = func_get_args();
     $arguments = array_slice($arguments, 2);
     $query = new Search_Query();
     call_user_func_array(array($query, $filterMethod), $arguments);
     $this->assertEquals($count, count($query->search($this->index)));
 }
コード例 #17
0
ファイル: QueryTest.php プロジェクト: linuxwhy/tiki-1
 function testSubQueryCreatesOrStatement()
 {
     $index = new Search_Index_Memory();
     $query = new Search_Query();
     $query->getSubQuery('abc')->filterContent('hello');
     $query->getSubQuery('abc')->filterCategory('1 and 2');
     $query->filterPermissions(array('Registered'));
     $query->search($index);
     $expr = new Search_Expr_And(array(new Search_Expr_Or(array(new Search_Expr_Token('hello', 'plaintext', 'contents'), new Search_Expr_And(array(new Search_Expr_Token('1', 'multivalue', 'categories'), new Search_Expr_Token('2', 'multivalue', 'categories'))))), new Search_Expr_Or(array(new Search_Expr_Token('Registered', 'multivalue', 'allowed_groups')))));
     $this->assertEquals($expr, $index->getLastQuery());
     $this->assertEquals(array('hello'), $query->getTerms());
 }
コード例 #18
0
 function testStopWords()
 {
     $query = new Search_Query('a for the');
     $this->assertEquals(0, count($query->search($this->index)));
 }