1 | <?php |
||
2 | |||
3 | namespace SilverStripe\FullTextSearch\Solr\Writers; |
||
4 | |||
5 | use SilverStripe\FullTextSearch\Search\Criteria\SearchCriterion; |
||
6 | use SilverStripe\FullTextSearch\Search\Queries\AbstractSearchQueryWriter; |
||
7 | |||
8 | /** |
||
9 | * Class SolrSearchQueryWriter_Basic |
||
10 | * @package SilverStripe\FullTextSearch\Solr\Writers |
||
11 | */ |
||
12 | class SolrSearchQueryWriterBasic extends AbstractSearchQueryWriter |
||
13 | { |
||
14 | /** |
||
15 | * @var SearchCriterion $searchCriterion |
||
16 | * @return string |
||
17 | */ |
||
18 | public function generateQueryString(SearchCriterion $searchCriterion) |
||
19 | { |
||
20 | return sprintf( |
||
21 | '%s(%s%s%s)', |
||
22 | $this->getComparisonPolarity($searchCriterion->getComparison()), |
||
23 | addslashes($searchCriterion->getTarget()), |
||
24 | $this->getComparisonConjunction(), |
||
25 | $searchCriterion->getQuoteValue($searchCriterion->getValue()) |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
26 | ); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Is this a positive (+) or negative (-) Solr comparison. |
||
31 | * |
||
32 | * @param string $comparison |
||
33 | * @return string |
||
34 | */ |
||
35 | protected function getComparisonPolarity($comparison) |
||
36 | { |
||
37 | switch ($comparison) { |
||
38 | case SearchCriterion::NOT_EQUAL: |
||
39 | return '-'; |
||
40 | default: |
||
41 | return '+'; |
||
42 | } |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Decide how we are comparing our left and right values. |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | protected function getComparisonConjunction() |
||
51 | { |
||
52 | return ':'; |
||
53 | } |
||
54 | } |
||
55 |