Skip to content
This repository was archived by the owner on Dec 25, 2022. It is now read-only.

Commit 633ce75

Browse files
tmp
1 parent eaf727d commit 633ce75

14 files changed

Lines changed: 241 additions & 14 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ install:
3232
- ./tests/bin/console doctrine:database:create -e prod
3333
- ./tests/bin/console pucene:indices:create -e prod
3434
- ./tests/bin/console test:import:json my_index ./tests/app/data.json --adapter pucene -e prod
35+
- ./tests/bin/console zend_search:indices:create -e prod
36+
- ./tests/bin/console test:import:json my_index ./tests/app/data.json --adapter zend_search -e prod
3537

3638
script:
3739
- ./vendor/bin/phpunit $CODE_COVERAGE

src/Component/Elasticsearch/Compiler/ElementInterface.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Component/Elasticsearch/Compiler/VisitorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface VisitorInterface
99
/**
1010
* @param QueryInterface $query
1111
*
12-
* @return ElementInterface
12+
* @return array
1313
*/
1414
public function visit(QueryInterface $query);
1515
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Pucene\Component\ZendSearch\Compiler;
4+
5+
use Pucene\Component\QueryBuilder\Query\QueryInterface;
6+
use Pucene\Component\Symfony\Pool\PoolInterface;
7+
8+
class Compiler
9+
{
10+
/**
11+
* @var PoolInterface
12+
*/
13+
private $visitors;
14+
15+
/**
16+
* @param PoolInterface $visitors
17+
*/
18+
public function __construct(PoolInterface $visitors)
19+
{
20+
$this->visitors = $visitors;
21+
}
22+
23+
public function compile(QueryInterface $query)
24+
{
25+
return $this->getVisitor($query)->visit($query);
26+
}
27+
28+
/**
29+
* @param QueryInterface $query
30+
*
31+
* @return VisitorInterface
32+
*/
33+
private function getVisitor(QueryInterface $query)
34+
{
35+
return $this->visitors->get(get_class($query));
36+
}
37+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Pucene\Component\ZendSearch\Compiler\Visitor\Compound;
4+
5+
use Pucene\Component\ZendSearch\Compiler\VisitorInterface;
6+
use Pucene\Component\QueryBuilder\Query\Compound\BoolQuery;
7+
use Pucene\Component\QueryBuilder\Query\QueryInterface;
8+
use Pucene\Component\Symfony\Pool\PoolInterface;
9+
10+
class BoolVisitor implements VisitorInterface
11+
{
12+
/**
13+
* @var PoolInterface
14+
*/
15+
private $interpreterPool;
16+
17+
/**
18+
* @param PoolInterface $interpreterPool
19+
*/
20+
public function __construct(PoolInterface $interpreterPool)
21+
{
22+
$this->interpreterPool = $interpreterPool;
23+
}
24+
25+
/**
26+
* {@inheritdoc}
27+
*
28+
* @param BoolQuery $query
29+
*/
30+
public function visit(QueryInterface $query)
31+
{
32+
}
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Pucene\Component\ZendSearch\Compiler\Visitor\FullText;
4+
5+
use Pucene\Component\Analysis\StandardAnalyzer;
6+
use Pucene\Component\QueryBuilder\Query\FullText\MatchQuery;
7+
use Pucene\Component\QueryBuilder\Query\QueryInterface;
8+
use Pucene\Component\ZendSearch\Compiler\VisitorInterface;
9+
use ZendSearch\Lucene\Index;
10+
use ZendSearch\Lucene\Search\Query\MultiTerm;
11+
12+
class MatchVisitor implements VisitorInterface
13+
{
14+
/**
15+
* {@inheritdoc}
16+
*
17+
* @param MatchQuery $query
18+
*/
19+
public function visit(QueryInterface $query)
20+
{
21+
$analyzer = new StandardAnalyzer();
22+
23+
$multiTerm = new MultiTerm();
24+
foreach ($analyzer->analyze($query->getQuery()) as $token) {
25+
$multiTerm->addTerm(new Index\Term($token->getTerm(), $query->getField()), null);
26+
}
27+
28+
return $multiTerm;
29+
}
30+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Pucene\Component\ZendSearch\Compiler\Visitor;
4+
5+
use Pucene\Component\ZendSearch\Compiler\VisitorInterface;
6+
use Pucene\Component\QueryBuilder\Query\MatchAllQuery;
7+
use Pucene\Component\QueryBuilder\Query\QueryInterface;
8+
9+
class MatchAllVisitor implements VisitorInterface
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*
14+
* @param MatchAllQuery $query
15+
*/
16+
public function visit(QueryInterface $query)
17+
{
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Pucene\Component\ZendSearch\Compiler\Visitor\Specialized;
4+
5+
use Pucene\Component\QueryBuilder\Query\QueryInterface;
6+
use Pucene\Component\QueryBuilder\Query\Specialized\MoreLikeThis\MoreLikeThisQuery;
7+
use Pucene\Component\ZendSearch\Compiler\VisitorInterface;
8+
9+
class MoreLikeThisVisitor implements VisitorInterface
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*
14+
* @param MoreLikeThisQuery $query
15+
*/
16+
public function visit(QueryInterface $query)
17+
{
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Pucene\Component\ZendSearch\Compiler\Visitor\TermLevel;
4+
5+
use Pucene\Component\ZendSearch\Compiler\VisitorInterface;
6+
use Pucene\Component\QueryBuilder\Query\QueryInterface;
7+
use Pucene\Component\QueryBuilder\Query\TermLevel\IdsQuery;
8+
9+
class IdsVisitor implements VisitorInterface
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*
14+
* @param IdsQuery $query
15+
*/
16+
public function visit(QueryInterface $query)
17+
{
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Pucene\Component\ZendSearch\Compiler\Visitor\TermLevel;
4+
5+
use Pucene\Component\QueryBuilder\Query\QueryInterface;
6+
use Pucene\Component\QueryBuilder\Query\TermLevel\TermQuery;
7+
use Pucene\Component\ZendSearch\Compiler\VisitorInterface;
8+
use ZendSearch\Lucene\Search\Query\Term;
9+
use ZendSearch\Lucene\Index;
10+
11+
class TermVisitor implements VisitorInterface
12+
{
13+
/**
14+
* {@inheritdoc}
15+
*
16+
* @param TermQuery $query
17+
*/
18+
public function visit(QueryInterface $query)
19+
{
20+
return new Term(new Index\Term($query->getTerm(), $query->getField()));
21+
}
22+
}

0 commit comments

Comments
 (0)