@@ -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 | |
@@ -13,15 +13,15 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | $fields = $searchPage->getCMSFields(); |
| 15 | 15 | |
| 16 | - $mainTab = $this->checkTabExists($fields,'Main'); |
|
| 16 | + $mainTab = $this->checkTabExists($fields, 'Main'); |
|
| 17 | 17 | $this->checkFieldExists($mainTab, 'Identifier'); |
| 18 | 18 | $this->checkFieldExists($mainTab, 'ContentForEmptySearch'); |
| 19 | 19 | |
| 20 | - $searchTab = $this->checkTabExists($fields,'Search.SearchFor'); |
|
| 21 | - $fieldsTab = $this->checkTabExists($fields,'Search.Fields'); |
|
| 22 | - $autoCompleteTab = $this->checkTabExists($fields,'Search.AutoComplete'); |
|
| 23 | - $aggTab = $this->checkTabExists($fields,'Search.Aggregations'); |
|
| 24 | - $simTab = $this->checkTabExists($fields,'Search.Similarity'); |
|
| 20 | + $searchTab = $this->checkTabExists($fields, 'Search.SearchFor'); |
|
| 21 | + $fieldsTab = $this->checkTabExists($fields, 'Search.Fields'); |
|
| 22 | + $autoCompleteTab = $this->checkTabExists($fields, 'Search.AutoComplete'); |
|
| 23 | + $aggTab = $this->checkTabExists($fields, 'Search.Aggregations'); |
|
| 24 | + $simTab = $this->checkTabExists($fields, 'Search.Similarity'); |
|
| 25 | 25 | |
| 26 | 26 | $this->checkFieldExists($searchTab, 'InfoField'); |
| 27 | 27 | $this->checkFieldExists($searchTab, 'SiteTreeOnly'); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $pageLength = 10; // the default |
| 177 | 177 | $searchPageObj->ResultsPerPage = $pageLength; |
| 178 | 178 | $searchPageObj->write(); |
| 179 | - $searchPageObj->publish('Stage','Live'); |
|
| 179 | + $searchPageObj->publish('Stage', 'Live'); |
|
| 180 | 180 | |
| 181 | 181 | $form = $searchPageObj->SearchForm(); |
| 182 | 182 | $fields = $form->Fields(); |
@@ -306,11 +306,11 @@ discard block |
||
| 306 | 306 | $filter = array('ClazzName' => 'FlickrPhotoTO', 'Name' => 'Title'); |
| 307 | 307 | |
| 308 | 308 | //Check fieldnames as expected |
| 309 | - $searchableFields = $searchPage->ElasticaSearchableFields()->filter('Active',1); |
|
| 309 | + $searchableFields = $searchPage->ElasticaSearchableFields()->filter('Active', 1); |
|
| 310 | 310 | $sfs = $searchableFields->map('Name')->toArray(); |
| 311 | 311 | sort($sfs); |
| 312 | - $expected = array('Aperture','AspectRatio','Description','FirstViewed','FlickrID', |
|
| 313 | - 'FlickrSetTOs','FlickrTagTOs','FocalLength35mm','ISO','Photographer','ShutterSpeed', |
|
| 312 | + $expected = array('Aperture', 'AspectRatio', 'Description', 'FirstViewed', 'FlickrID', |
|
| 313 | + 'FlickrSetTOs', 'FlickrTagTOs', 'FocalLength35mm', 'ISO', 'Photographer', 'ShutterSpeed', |
|
| 314 | 314 | 'TakenAt', 'TakenAtDT', 'TestMethod', 'TestMethodHTML', 'Title'); |
| 315 | 315 | $this->assertEquals($expected, $sfs); |
| 316 | 316 | |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | $searchPage->Title = '**** SiteTree Search ****'; |
| 321 | 321 | $searchPage->write(); |
| 322 | 322 | |
| 323 | - $searchableFields = $searchPage->ElasticaSearchableFields()->filter('Active',1); |
|
| 323 | + $searchableFields = $searchPage->ElasticaSearchableFields()->filter('Active', 1); |
|
| 324 | 324 | $sfs = $searchableFields->map('Name')->toArray(); |
| 325 | 325 | sort($sfs); |
| 326 | 326 | $expected = array('Content', 'Country', 'PageDate', 'Title'); |
@@ -340,15 +340,15 @@ discard block |
||
| 340 | 340 | // expected mapping of searchable classes to searchable fields that will be |
| 341 | 341 | // stored in the database as SearchableClass and SearchableField |
| 342 | 342 | $expected = array( |
| 343 | - 'Page' => array('Title','Content'), |
|
| 344 | - 'SiteTree' => array('Title','Content'), |
|
| 345 | - 'SearchableTestPage' => array('Title','Content','Country','PageDate'), |
|
| 343 | + 'Page' => array('Title', 'Content'), |
|
| 344 | + 'SiteTree' => array('Title', 'Content'), |
|
| 345 | + 'SearchableTestPage' => array('Title', 'Content', 'Country', 'PageDate'), |
|
| 346 | 346 | 'FlickrTagTO' => array('RawValue'), |
| 347 | - 'FlickrAuthorTO' => array('PathAlias','DisplayName','FlickrPhotoTOs'), |
|
| 348 | - 'FlickrPhotoTO' => array('Title','FlickrID','Description','TakenAt', 'TakenAtDT', 'Aperture', |
|
| 349 | - 'ShutterSpeed','FocalLength35mm','ISO','Photographer','FlickrTagTOs','FlickrSetTOs', |
|
| 350 | - 'FirstViewed','AspectRatio', 'TestMethod', 'TestMethodHTML'), |
|
| 351 | - 'FlickrSetTO' => array('Title','FlickrID','Description') |
|
| 347 | + 'FlickrAuthorTO' => array('PathAlias', 'DisplayName', 'FlickrPhotoTOs'), |
|
| 348 | + 'FlickrPhotoTO' => array('Title', 'FlickrID', 'Description', 'TakenAt', 'TakenAtDT', 'Aperture', |
|
| 349 | + 'ShutterSpeed', 'FocalLength35mm', 'ISO', 'Photographer', 'FlickrTagTOs', 'FlickrSetTOs', |
|
| 350 | + 'FirstViewed', 'AspectRatio', 'TestMethod', 'TestMethodHTML'), |
|
| 351 | + 'FlickrSetTO' => array('Title', 'FlickrID', 'Description') |
|
| 352 | 352 | ); |
| 353 | 353 | |
| 354 | 354 | // check the expected classes |
@@ -369,21 +369,21 @@ discard block |
||
| 369 | 369 | // check the names expected to appear |
| 370 | 370 | |
| 371 | 371 | $fieldCtr = 0; |
| 372 | - foreach ($expectedClasses as $expectedClass) { |
|
| 372 | + foreach($expectedClasses as $expectedClass) { |
|
| 373 | 373 | $expectedFields = array(); |
| 374 | 374 | $sc = SearchableClass::get()->filter('Name', $expectedClass)->first(); |
| 375 | - $this->assertEquals($expectedClass,$sc->Name); |
|
| 375 | + $this->assertEquals($expectedClass, $sc->Name); |
|
| 376 | 376 | |
| 377 | 377 | $inSiteTree = 1; |
| 378 | - $start = substr($expectedClass, 0,6); |
|
| 379 | - if ($start == 'Flickr') { |
|
| 378 | + $start = substr($expectedClass, 0, 6); |
|
| 379 | + if($start == 'Flickr') { |
|
| 380 | 380 | $inSiteTree = 0; |
| 381 | 381 | }; |
| 382 | - $this->assertEquals($inSiteTree,$sc->InSiteTree); |
|
| 382 | + $this->assertEquals($inSiteTree, $sc->InSiteTree); |
|
| 383 | 383 | |
| 384 | 384 | $expectedNames = $expected[$expectedClass]; |
| 385 | - foreach ($expectedNames as $expectedName) { |
|
| 386 | - $filter = array('Name' => $expectedName, 'SearchableClassID' => $sc->ID ); |
|
| 385 | + foreach($expectedNames as $expectedName) { |
|
| 386 | + $filter = array('Name' => $expectedName, 'SearchableClassID' => $sc->ID); |
|
| 387 | 387 | $sf = SearchableField::get()->filter($filter)->first(); |
| 388 | 388 | $this->assertEquals($expectedName, $sf->Name); |
| 389 | 389 | $fieldCtr++; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | $expected = array('first'); |
| 27 | 27 | $this->assertEquals($expected, array_keys($terms['Title.standard']['terms'])); |
| 28 | 28 | |
| 29 | - $expected = array('fi','fir','firs','first','ir','irs','irst','rs','rst','st'); |
|
| 29 | + $expected = array('fi', 'fir', 'firs', 'first', 'ir', 'irs', 'irst', 'rs', 'rst', 'st'); |
|
| 30 | 30 | $this->assertEquals($expected, array_keys($terms['Title.autocomplete']['terms'])); |
| 31 | 31 | |
| 32 | 32 | // ---- now a parental class page ---- |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | $terms = $page->getTermVectors(); |
| 51 | 51 | |
| 52 | 52 | //Check the expected fields are indexed |
| 53 | - $expected = array('Content','Content.shingles','Content.standard','FatherText','FatherText.shingles','FatherText.standard', |
|
| 54 | - 'GrandFatherText','GrandFatherText.shingles','GrandFatherText.standard','Link','Title','Title.autocomplete', |
|
| 55 | - 'Title.shingles','Title.standard'); |
|
| 53 | + $expected = array('Content', 'Content.shingles', 'Content.standard', 'FatherText', 'FatherText.shingles', 'FatherText.standard', |
|
| 54 | + 'GrandFatherText', 'GrandFatherText.shingles', 'GrandFatherText.standard', 'Link', 'Title', 'Title.autocomplete', |
|
| 55 | + 'Title.shingles', 'Title.standard'); |
|
| 56 | 56 | $indexedFields = array_keys($terms); |
| 57 | 57 | sort($indexedFields); |
| 58 | 58 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | $fatherTerms = $terms['FatherText.standard']['terms']; |
| 62 | 62 | $grandFatherTerms = $terms['GrandFatherText.standard']['terms']; |
| 63 | 63 | |
| 64 | - $expected = array('father', 'field', 'grandfather', 'page', 'trace3');; |
|
| 64 | + $expected = array('father', 'field', 'grandfather', 'page', 'trace3'); ; |
|
| 65 | 65 | $this->assertEquals($expected, array_keys($fatherTerms)); |
| 66 | 66 | |
| 67 | 67 | $expected = array('grandfather', 'page', 'trace4'); |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | |
| 15 | 15 | public function setUpOnce() { |
| 16 | 16 | //Add translatable if it exists |
| 17 | - if (class_exists('Translatable')) { |
|
| 17 | + if(class_exists('Translatable')) { |
|
| 18 | 18 | SiteTree::add_extension('Translatable'); |
| 19 | 19 | } |
| 20 | 20 | parent::setUpOnce(); |
@@ -102,7 +102,7 @@ |
||
| 102 | 102 | $es->setLocale($locale); |
| 103 | 103 | $es->setClasses('FlickrPhotoTO'); |
| 104 | 104 | |
| 105 | - $fields = array('Description.standard' => 1,'Title.standard' => 1); |
|
| 105 | + $fields = array('Description.standard' => 1, 'Title.standard' => 1); |
|
| 106 | 106 | $results = $es->moreLikeThis($fp, $fields, true); |
| 107 | 107 | |
| 108 | 108 | $terms = $results->getList()->MoreLikeThisTerms; |