@@ -479,6 +479,9 @@ |
||
479 | 479 | } |
480 | 480 | |
481 | 481 | |
482 | + /** |
|
483 | + * @param string $query |
|
484 | + */ |
|
482 | 485 | private function getResultsFor($query, $pageLength = 10, $fields = array('Title' => 1, 'Description' => 1)) { |
483 | 486 | $es = new ElasticSearcher(); |
484 | 487 | $es->setStart(0); |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | parent::requireDefaultRecords(); |
28 | 28 | |
29 | 29 | $similar = AutoCompleteOption::get()->filter('Name', 'Similar')->first(); |
30 | - if (!$similar) { |
|
30 | + if(!$similar) { |
|
31 | 31 | $similar = new AutoCompleteOption(); |
32 | 32 | $similar->Name = 'Similar'; |
33 | 33 | $similar->Slug = 'SIMILAR'; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | $search = AutoCompleteOption::get()->filter('Name', 'Search')->first(); |
40 | - if (!$search) { |
|
40 | + if(!$search) { |
|
41 | 41 | $search = new AutoCompleteOption(); |
42 | 42 | $search->Name = 'Search'; |
43 | 43 | $search->Description = 'Find records similar to the selected item'; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | $goto = AutoCompleteOption::get()->filter('Name', 'GoToRecord')->first(); |
50 | - if (!$goto) { |
|
50 | + if(!$goto) { |
|
51 | 51 | $goto = new AutoCompleteOption(); |
52 | 52 | $goto->Name = 'GoToRecord'; |
53 | 53 | $goto->Description = 'Go to the page of the selected item, found by the Link() method'; |
@@ -20,24 +20,24 @@ |
||
20 | 20 | // Makes most sense to only provide one field here, e.g. Title, Name |
21 | 21 | $field = $this->request->getVar('field'); |
22 | 22 | |
23 | - error_log('QUERY:'.$query); |
|
23 | + error_log('QUERY:' . $query); |
|
24 | 24 | |
25 | 25 | // start, and page length, i.e. pagination |
26 | 26 | $es->setPageLength(10); |
27 | - if ($classes) { |
|
27 | + if($classes) { |
|
28 | 28 | $es->setClasses($classes); |
29 | 29 | } |
30 | 30 | |
31 | - if ($filter) { |
|
31 | + if($filter) { |
|
32 | 32 | $es->addFilter('InSiteTree', true); |
33 | 33 | } |
34 | 34 | |
35 | - $resultList = $es->autocomplete_search($query,$field); |
|
35 | + $resultList = $es->autocomplete_search($query, $field); |
|
36 | 36 | $result = array(); |
37 | 37 | $result['Query'] = $query; |
38 | 38 | $suggestions = array(); |
39 | 39 | |
40 | - foreach ($resultList->getResults() as $singleResult) { |
|
40 | + foreach($resultList->getResults() as $singleResult) { |
|
41 | 41 | $suggestion = array('value' => $singleResult->Title); |
42 | 42 | $suggestion['data'] = array( |
43 | 43 | 'ID' => $singleResult->getParam('_id'), |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | //return false; |
23 | 23 | // |
24 | 24 | |
25 | - if ($data['ClassesToSearch'] == array()) { |
|
25 | + if($data['ClassesToSearch'] == array()) { |
|
26 | 26 | $data['ClassesToSearch'] = ''; |
27 | 27 | } |
28 | 28 | |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | echo "STDATA:$debug\n"; |
31 | 31 | |
32 | 32 | // Check if any classes to search if site tree only is not ticked |
33 | - if (!$data['SiteTreeOnly']) { |
|
34 | - if (!$data['ClassesToSearch']) { |
|
33 | + if(!$data['SiteTreeOnly']) { |
|
34 | + if(!$data['ClassesToSearch']) { |
|
35 | 35 | $valid = false; |
36 | 36 | $this->validationError("ClassesToSearch", |
37 | 37 | "Please provide at least one class to search, or select 'Site Tree Only'", |
@@ -39,15 +39,15 @@ discard block |
||
39 | 39 | ); |
40 | 40 | } else { |
41 | 41 | $toSearch = $data['ClassesToSearch']; |
42 | - foreach ($toSearch as $clazz) { |
|
42 | + foreach($toSearch as $clazz) { |
|
43 | 43 | try { |
44 | 44 | $instance = Injector::inst()->create($clazz); |
45 | - if (!$instance->hasExtension('SilverStripe\Elastica\Searchable')) { |
|
46 | - $this->validationError('ClassesToSearch', 'The class '.$clazz.' must have the Searchable extension'); |
|
45 | + if(!$instance->hasExtension('SilverStripe\Elastica\Searchable')) { |
|
46 | + $this->validationError('ClassesToSearch', 'The class ' . $clazz . ' must have the Searchable extension'); |
|
47 | 47 | } |
48 | 48 | } catch (ReflectionException $e) { |
49 | 49 | $this->validationError("ClassesToSearch", |
50 | - 'The class '.$clazz.' does not exist', |
|
50 | + 'The class ' . $clazz . ' does not exist', |
|
51 | 51 | 'error' |
52 | 52 | ); |
53 | 53 | } |
@@ -58,23 +58,23 @@ discard block |
||
58 | 58 | |
59 | 59 | // Check the identifier is unique |
60 | 60 | $mode = Versioned::get_reading_mode(); |
61 | - $suffix = ''; |
|
62 | - if ($mode == 'Stage.Live') { |
|
61 | + $suffix = ''; |
|
62 | + if($mode == 'Stage.Live') { |
|
63 | 63 | $suffix = '_Live'; |
64 | 64 | } |
65 | - $where = 'ElasticSearchPage'.$suffix.'.ID != '.$data['ID']." AND `Identifier` = '".$data['Identifier']."'"; |
|
65 | + $where = 'ElasticSearchPage' . $suffix . '.ID != ' . $data['ID'] . " AND `Identifier` = '" . $data['Identifier'] . "'"; |
|
66 | 66 | $existing = ElasticSearchPage::get()->where($where)->count(); |
67 | - if ($existing > 0) { |
|
67 | + if($existing > 0) { |
|
68 | 68 | $valid = false; |
69 | 69 | $this->validationError('Identifier', |
70 | - 'The identifier '.$data['Identifier'].' already exists', |
|
70 | + 'The identifier ' . $data['Identifier'] . ' already exists', |
|
71 | 71 | 'error' |
72 | 72 | ); |
73 | 73 | } |
74 | 74 | |
75 | 75 | |
76 | 76 | // Check number of results per page >= 1 |
77 | - if ($data['ResultsPerPage'] <= 0) { |
|
77 | + if($data['ResultsPerPage'] <= 0) { |
|
78 | 78 | $valid = false; |
79 | 79 | $this->validationError('ResultsPerPage', |
80 | 80 | 'Results per page must be >=1' |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | $searchPage = $this->getSearchPage($identifier); |
14 | 14 | |
15 | - if ($searchPage) { |
|
15 | + if($searchPage) { |
|
16 | 16 | $result = $searchPage->AbsoluteLink(); |
17 | 17 | } |
18 | 18 | return $result; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | $searchPage = $this->getSearchPage($identifier); |
26 | 26 | |
27 | - if ($searchPage) { |
|
27 | + if($searchPage) { |
|
28 | 28 | $result = $searchPage->SearchForm($buttonTextOverride); |
29 | 29 | } |
30 | 30 | return $result; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | |
34 | 34 | public function getSearchPage($identifier) { |
35 | - if (!isset($this->_CachedLastEdited)) { |
|
35 | + if(!isset($this->_CachedLastEdited)) { |
|
36 | 36 | $this->_CachedLastEdited = ElasticSearchPage::get()->max('LastEdited'); |
37 | 37 | } |
38 | 38 | $ck = $this->_CachedLastEdited; |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | |
43 | 43 | $cache = SS_Cache::factory('searchpagecache'); |
44 | 44 | $searchPage = null; |
45 | - $cachekeyname = 'searchpageuri'.$identifier.$this->owner->Locale.$ck; |
|
45 | + $cachekeyname = 'searchpageuri' . $identifier . $this->owner->Locale . $ck; |
|
46 | 46 | |
47 | 47 | if(!($searchPage = unserialize($cache->load($cachekeyname)))) { |
48 | - $searchPage = ElasticSearchPage::get()->filter('Identifier',$identifier)->first(); |
|
48 | + $searchPage = ElasticSearchPage::get()->filter('Identifier', $identifier)->first(); |
|
49 | 49 | $cache->save(serialize($searchPage), $cachekeyname); |
50 | 50 | } |
51 | 51 | return $searchPage; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | $fields = $sf->getCMSFields(); |
17 | 17 | |
18 | - $tab = $this->checkTabExists($fields,'Main'); |
|
18 | + $tab = $this->checkTabExists($fields, 'Main'); |
|
19 | 19 | |
20 | 20 | //Check fields |
21 | 21 | $nf = $this->checkFieldExists($tab, 'Name'); |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | $extraFields = array('Searchable' => 1, 'SimilarSearchable' => 1, 'Active' => 1, |
34 | 34 | 'Weight' => 0); |
35 | 35 | $esfs = $searchPage->ElasticaSearchableFields(); |
36 | - foreach ($esfs as $sf) { |
|
37 | - if ($sf->Name == 'Title' || $sf->Name == 'Description') { |
|
36 | + foreach($esfs as $sf) { |
|
37 | + if($sf->Name == 'Title' || $sf->Name == 'Description') { |
|
38 | 38 | $esfs->remove($sf); |
39 | 39 | $esfs->add($sf, $extraFields); |
40 | 40 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $this->fail('Searchable fail should have failed to write'); |
46 | 46 | } catch (ValidationException $e) { |
47 | 47 | $this->assertInstanceOf('ValidationException', $e); |
48 | - $expected = 'The field SearchableTestPage.Title has a zero weight. ; The field '. |
|
48 | + $expected = 'The field SearchableTestPage.Title has a zero weight. ; The field ' . |
|
49 | 49 | 'SiteTree.Title has a zero weight. ; The field Page.Title has a zero weight. '; |
50 | 50 | $this->assertEquals($expected, $e->getMessage()); |
51 | 51 | } |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | $extraFields = array('Searchable' => 1, 'SimilarSearchable' => 1, 'Active' => 1, |
65 | 65 | 'Weight' => -1); |
66 | 66 | $esfs = $searchPage->ElasticaSearchableFields(); |
67 | - foreach ($esfs as $sf) { |
|
68 | - if ($sf->Name == 'Title' || $sf->Name == 'Description') { |
|
67 | + foreach($esfs as $sf) { |
|
68 | + if($sf->Name == 'Title' || $sf->Name == 'Description') { |
|
69 | 69 | $esfs->remove($sf); |
70 | 70 | $esfs->add($sf, $extraFields); |
71 | 71 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $this->fail('Searchable fail should have failed to write'); |
77 | 77 | } catch (ValidationException $e) { |
78 | 78 | $this->assertInstanceOf('ValidationException', $e); |
79 | - $expected = 'The field SearchableTestPage.Title has a negative weight. ; The field '. |
|
79 | + $expected = 'The field SearchableTestPage.Title has a negative weight. ; The field ' . |
|
80 | 80 | 'SiteTree.Title has a negative weight. ; The field Page.Title has a negative weight. '; |
81 | 81 | $this->assertEquals($expected, $e->getMessage()); |
82 | 82 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $this->checkForSimulatedServerDown(); |
119 | 119 | |
120 | 120 | // now actually perform the search using the original query |
121 | - $paginated = $es->search($this->QueryText, $this->FieldsToSearch,$this->TestMode); |
|
121 | + $paginated = $es->search($this->QueryText, $this->FieldsToSearch, $this->TestMode); |
|
122 | 122 | |
123 | 123 | // This is the case of the original query having a better one suggested. Do a |
124 | 124 | // second search for the suggested query, throwing away the original |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | |
320 | 320 | // For a 'more like this' search, use the original unstemmed words |
321 | 321 | // This means using the .standard named field of text |
322 | - if ($this->action == 'similar') { |
|
322 | + if($this->action == 'similar') { |
|
323 | 323 | // Use the standard field for more like this, ie not stemmed |
324 | 324 | foreach($fieldsToSearch as $field => $value) { |
325 | 325 | $fieldsToSearch[$field . '.standard'] = $value; |
@@ -255,7 +255,7 @@ |
||
255 | 255 | |
256 | 256 | private function getFormatForDate($class) { |
257 | 257 | $format = 'y-M-d'; // default |
258 | - switch ($class) { |
|
258 | + switch($class) { |
|
259 | 259 | case 'Date': |
260 | 260 | $format = 'y-M-d'; |
261 | 261 | break; |
@@ -45,6 +45,7 @@ discard block |
||
45 | 45 | * @param string &$name |
46 | 46 | * @param boolean $storeMethodName |
47 | 47 | * @param boolean $recurse |
48 | + * @param string $name |
|
48 | 49 | */ |
49 | 50 | public static function assignSpecForRelationship(&$name, $resultType, &$spec, $storeMethodName, $recurse) { |
50 | 51 | $resultTypeInstance = \Injector::inst()->create($resultType); |
@@ -161,6 +162,9 @@ discard block |
||
161 | 162 | } |
162 | 163 | |
163 | 164 | |
165 | + /** |
|
166 | + * @param boolean $recurse |
|
167 | + */ |
|
164 | 168 | public static function storeRelationshipValue($instance, $field, &$fields, $config, $recurse) { |
165 | 169 | if(isset($config['properties']['__method'])) { |
166 | 170 | $methodName = $config['properties']['__method']; |
@@ -206,6 +210,9 @@ discard block |
||
206 | 210 | } |
207 | 211 | |
208 | 212 | |
213 | + /** |
|
214 | + * @param \DataObject $searchableClass |
|
215 | + */ |
|
209 | 216 | public static function findOrCreateSearchableField($className, $fieldName, $searchableField, $searchableClass) { |
210 | 217 | $filter = array('ClazzName' => $className, 'Name' => $fieldName); |
211 | 218 | $doSF = \SearchableField::get()->filter($filter)->first(); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @param \Elastica\Query|string|array $query |
142 | 142 | * @param string|array $types List of comma separated SilverStripe classes to search, or blank for all |
143 | - * @return \Elastica\ResultList |
|
143 | + * @return \Elastica\ResultSet |
|
144 | 144 | */ |
145 | 145 | public function search($query, $types = '') { |
146 | 146 | $query = Query::create($query); // may be a string |
@@ -244,6 +244,10 @@ discard block |
||
244 | 244 | } |
245 | 245 | |
246 | 246 | |
247 | + /** |
|
248 | + * @param Query $elasticaQuery |
|
249 | + * @param Search $search |
|
250 | + */ |
|
247 | 251 | private function checkForTermsMoreLikeThis($elasticaQuery, $search) { |
248 | 252 | if($elasticaQuery->MoreLikeThis) { |
249 | 253 |