1 | <?php |
||
9 | class FlickrPhotoTOElasticaSearchHelper implements ElasticaSearchHelperInterface,TestOnly { |
||
|
|||
10 | |||
11 | 7 | public function __construct() { |
|
19 | |||
20 | private static $titleFieldMapping = array( |
||
21 | 'ShutterSpeed' => 'Shutter Speed', |
||
22 | 'FocalLength35mm' => 'Focal Length' |
||
23 | ); |
||
24 | |||
25 | |||
26 | /** |
||
27 | * Add a number of facets to the FlickrPhotoTO query |
||
28 | * @param \Elastica\Query &$query the existing query object to be augmented. |
||
29 | */ |
||
30 | 7 | public function augmentQuery(&$query) { |
|
79 | |||
80 | |||
81 | /** |
||
82 | * Update filters, perhaps remaps them, prior to performing a search. |
||
83 | * This allows for aggregation values to be updated prior to rendering. |
||
84 | * @param array &$filters array of key/value pairs for query filtering |
||
85 | */ |
||
86 | 7 | public function updateFilters(&$filters) { |
|
87 | |||
88 | // shutter speed is stored as decimal to 6 decimal places, then a |
||
89 | // vertical bar followed by the displayed speed as a fraction or a |
||
90 | // whole number. This puts the decimal back for matching purposes |
||
91 | 7 | if (isset($filters['ShutterSpeed'])) { |
|
92 | |||
93 | $sortable = $filters['ShutterSpeed']; |
||
94 | |||
95 | $sortable = explode('/', $sortable); |
||
96 | if (sizeof($sortable) == 1) { |
||
97 | $sortable = trim($sortable[0]); |
||
98 | |||
99 | if ($sortable === '1') { |
||
100 | $sortable = '1.000000|1'; |
||
101 | } |
||
102 | |||
103 | } else if (sizeof($sortable) == 2) { |
||
104 | if ($sortable[0] === '' || $sortable[1] === '') { |
||
105 | $sortable = ''; |
||
106 | |||
107 | } else { |
||
108 | $sortable = floatval($sortable[0])/intval($sortable[1]); |
||
109 | $sortable = round($sortable,6); |
||
110 | $sortable = $sortable . '|' . $filters['ShutterSpeed']; |
||
111 | } |
||
112 | |||
113 | } |
||
114 | |||
115 | $filters['ShutterSpeed'] = $sortable; |
||
116 | } |
||
117 | 7 | } |
|
118 | |||
119 | |||
120 | |||
121 | /** |
||
122 | * Manipulate the results, e.g. fixing up values if issues with ordering in Elastica |
||
123 | * @param array &$aggs Aggregates from an Elastica search to be tweaked |
||
124 | */ |
||
125 | public function updateAggregation(&$aggs) { |
||
137 | |||
138 | /* |
||
139 | In the event of aggregates being used and no query provided, sort by this (<field> => <order>) |
||
140 | */ |
||
141 | 7 | public function getDefaultSort() { |
|
144 | |||
145 | |||
146 | public function getIndexFieldTitleMapping() { |
||
149 | } |
||
150 |