-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new serach criterion to allow proper replication of ezfind searches
- Loading branch information
gggeek
committed
Dec 18, 2018
1 parent
729691d
commit 42bbe26
Showing
7 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
API/Repository/Values/Content/Query/Criterion/EzFindText.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 Kaliop\EzFindSearchEngineBundle\API\Repository\Values\Content\Query\Criterion; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Query\Criterion as BaseCriterion; | ||
|
||
/** | ||
* Full-text search criterion, based on eZFind configuration. | ||
* When this criterion is used (NB: as part of a query's `query`, not `filter`), the given text will be matched against | ||
* all content fields indexed in Solr as per eZFind configuration (including field boosts etc...) | ||
* Note: when using the FullTextr criterion instead of this one, matching is done against the `ezf_df_text` Solr field | ||
*/ | ||
class EzFindText extends BaseCriterion | ||
{ | ||
public function __construct($value) | ||
{ | ||
$this->value = $value; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
Core/Persistence/eZFind/Content/Search/Common/Gateway/CriterionHandler/EzFindText.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,60 @@ | ||
<?php | ||
|
||
namespace Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway\CriterionHandler; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; | ||
use Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway\CriteriaConverter; | ||
use Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway\CriterionHandler; | ||
use Kaliop\EzFindSearchEngineBundle\API\Repository\Values\Content\Query\Criterion\EzFindText as EzFindTextCriterion; | ||
|
||
class EzFindText extends CriterionHandler | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function accept(Criterion $criterion) | ||
{ | ||
return $criterion instanceof EzFindTextCriterion; | ||
} | ||
|
||
/** | ||
* If the full-text search contain wildcard search, build correct wildcard query | ||
* with non-truncated words boosted. | ||
* | ||
* @inheritdoc | ||
*/ | ||
public function handle(CriteriaConverter $converter, Criterion $criterion) | ||
{ | ||
$value = trim($criterion->value); | ||
|
||
if (preg_match('/^".+"$/', $value)) { | ||
// Quoted-string query: escape everything but the outher quotes | ||
$value = '"' . $this->escapeValue(substr($value, 1, -1)) . '"'; | ||
|
||
} else if (preg_match('/(^\*|\*$)/', $value)) { | ||
// Wildcard query: make the exact match stronger than the wildcard | ||
|
||
// @bug we do not support wildcard chars in the middle of phrases | ||
|
||
$value = $this->escapeValue($value); | ||
|
||
// Escape spaces | ||
$value = str_replace(' ', '\\ ', $value); | ||
|
||
// wildcard match: un-escape wildcard char | ||
$wildcard = str_replace('\\*', '*', $value); | ||
|
||
// Non-wildcard match | ||
$value = trim($value, '*'); | ||
$value = rtrim($value, '\\'); | ||
|
||
$value = $value . '^2 OR ' . $wildcard; | ||
|
||
} else { | ||
// plain query | ||
$value = $this->escapeValue($value); | ||
} | ||
|
||
return $value; | ||
} | ||
} |
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
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
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