This repository has been archived by the owner on Dec 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eaf727d
commit 633ce75
Showing
14 changed files
with
241 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Pucene\Component\ZendSearch\Compiler; | ||
|
||
use Pucene\Component\QueryBuilder\Query\QueryInterface; | ||
use Pucene\Component\Symfony\Pool\PoolInterface; | ||
|
||
class Compiler | ||
{ | ||
/** | ||
* @var PoolInterface | ||
*/ | ||
private $visitors; | ||
|
||
/** | ||
* @param PoolInterface $visitors | ||
*/ | ||
public function __construct(PoolInterface $visitors) | ||
{ | ||
$this->visitors = $visitors; | ||
} | ||
|
||
public function compile(QueryInterface $query) | ||
{ | ||
return $this->getVisitor($query)->visit($query); | ||
} | ||
|
||
/** | ||
* @param QueryInterface $query | ||
* | ||
* @return VisitorInterface | ||
*/ | ||
private function getVisitor(QueryInterface $query) | ||
{ | ||
return $this->visitors->get(get_class($query)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Component/ZendSearch/Compiler/Visitor/Compound/BoolVisitor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Pucene\Component\ZendSearch\Compiler\Visitor\Compound; | ||
|
||
use Pucene\Component\ZendSearch\Compiler\VisitorInterface; | ||
use Pucene\Component\QueryBuilder\Query\Compound\BoolQuery; | ||
use Pucene\Component\QueryBuilder\Query\QueryInterface; | ||
use Pucene\Component\Symfony\Pool\PoolInterface; | ||
|
||
class BoolVisitor implements VisitorInterface | ||
{ | ||
/** | ||
* @var PoolInterface | ||
*/ | ||
private $interpreterPool; | ||
|
||
/** | ||
* @param PoolInterface $interpreterPool | ||
*/ | ||
public function __construct(PoolInterface $interpreterPool) | ||
{ | ||
$this->interpreterPool = $interpreterPool; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param BoolQuery $query | ||
*/ | ||
public function visit(QueryInterface $query) | ||
{ | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Component/ZendSearch/Compiler/Visitor/FullText/MatchVisitor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Pucene\Component\ZendSearch\Compiler\Visitor\FullText; | ||
|
||
use Pucene\Component\Analysis\StandardAnalyzer; | ||
use Pucene\Component\QueryBuilder\Query\FullText\MatchQuery; | ||
use Pucene\Component\QueryBuilder\Query\QueryInterface; | ||
use Pucene\Component\ZendSearch\Compiler\VisitorInterface; | ||
use ZendSearch\Lucene\Index; | ||
use ZendSearch\Lucene\Search\Query\MultiTerm; | ||
|
||
class MatchVisitor implements VisitorInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param MatchQuery $query | ||
*/ | ||
public function visit(QueryInterface $query) | ||
{ | ||
$analyzer = new StandardAnalyzer(); | ||
|
||
$multiTerm = new MultiTerm(); | ||
foreach ($analyzer->analyze($query->getQuery()) as $token) { | ||
$multiTerm->addTerm(new Index\Term($token->getTerm(), $query->getField()), null); | ||
} | ||
|
||
return $multiTerm; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Component/ZendSearch/Compiler/Visitor/MatchAllVisitor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Pucene\Component\ZendSearch\Compiler\Visitor; | ||
|
||
use Pucene\Component\ZendSearch\Compiler\VisitorInterface; | ||
use Pucene\Component\QueryBuilder\Query\MatchAllQuery; | ||
use Pucene\Component\QueryBuilder\Query\QueryInterface; | ||
|
||
class MatchAllVisitor implements VisitorInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param MatchAllQuery $query | ||
*/ | ||
public function visit(QueryInterface $query) | ||
{ | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Component/ZendSearch/Compiler/Visitor/Specialized/MoreLikeThisVisitor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Pucene\Component\ZendSearch\Compiler\Visitor\Specialized; | ||
|
||
use Pucene\Component\QueryBuilder\Query\QueryInterface; | ||
use Pucene\Component\QueryBuilder\Query\Specialized\MoreLikeThis\MoreLikeThisQuery; | ||
use Pucene\Component\ZendSearch\Compiler\VisitorInterface; | ||
|
||
class MoreLikeThisVisitor implements VisitorInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param MoreLikeThisQuery $query | ||
*/ | ||
public function visit(QueryInterface $query) | ||
{ | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Component/ZendSearch/Compiler/Visitor/TermLevel/IdsVisitor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Pucene\Component\ZendSearch\Compiler\Visitor\TermLevel; | ||
|
||
use Pucene\Component\ZendSearch\Compiler\VisitorInterface; | ||
use Pucene\Component\QueryBuilder\Query\QueryInterface; | ||
use Pucene\Component\QueryBuilder\Query\TermLevel\IdsQuery; | ||
|
||
class IdsVisitor implements VisitorInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param IdsQuery $query | ||
*/ | ||
public function visit(QueryInterface $query) | ||
{ | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Component/ZendSearch/Compiler/Visitor/TermLevel/TermVisitor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Pucene\Component\ZendSearch\Compiler\Visitor\TermLevel; | ||
|
||
use Pucene\Component\QueryBuilder\Query\QueryInterface; | ||
use Pucene\Component\QueryBuilder\Query\TermLevel\TermQuery; | ||
use Pucene\Component\ZendSearch\Compiler\VisitorInterface; | ||
use ZendSearch\Lucene\Search\Query\Term; | ||
use ZendSearch\Lucene\Index; | ||
|
||
class TermVisitor implements VisitorInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param TermQuery $query | ||
*/ | ||
public function visit(QueryInterface $query) | ||
{ | ||
return new Term(new Index\Term($query->getTerm(), $query->getField())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Pucene\Component\ZendSearch\Compiler\Visitor; | ||
|
||
use Pucene\Component\QueryBuilder\Query\FullText\MatchQuery; | ||
use Pucene\Component\QueryBuilder\Query\MatchAllQuery; | ||
use Pucene\Component\QueryBuilder\Query\TermLevel\TermQuery; | ||
use Pucene\Component\Symfony\Pool\PoolInterface; | ||
use Pucene\Component\ZendSearch\Compiler\Visitor\FullText\MatchVisitor; | ||
use Pucene\Component\ZendSearch\Compiler\Visitor\TermLevel\TermVisitor; | ||
|
||
class VisitorPool implements PoolInterface | ||
{ | ||
private $visitors = []; | ||
|
||
public function __construct() | ||
{ | ||
$this->visitors = [ | ||
TermQuery::class => new TermVisitor(), | ||
MatchAllQuery::class => new MatchAllVisitor(), | ||
MatchQuery::class => new MatchVisitor(), | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get($alias) | ||
{ | ||
return $this->visitors[$alias]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Pucene\Component\ZendSearch\Compiler; | ||
|
||
use Pucene\Component\QueryBuilder\Query\QueryInterface; | ||
use ZendSearch\Lucene\Search\Query\AbstractQuery; | ||
|
||
interface VisitorInterface | ||
{ | ||
/** | ||
* @param QueryInterface $query | ||
* | ||
* @return AbstractQuery | ||
*/ | ||
public function visit(QueryInterface $query); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters