@@ -18,13 +18,13 @@ discard block |
||
18 | 18 | |
19 | 19 | |
20 | 20 | // Delete and assert that it does not exist |
21 | - $sql = "SELECT ID,Name,ClazzName from SearchableField"; |
|
21 | + $sql = "SELECT ID,Name,ClazzName from SearchableField"; |
|
22 | 22 | $records = DB::query($sql); |
23 | 23 | |
24 | 24 | $filter = array('Name' => 'Title', 'ClazzName' => 'FlickrPhotoTO'); |
25 | 25 | $sf = SearchableField::get()->filter($filter)->first(); |
26 | - $sql = "UPDATE ElasticSearchPage_ElasticaSearchableFields SET Searchable=1,". |
|
27 | - "EnableAutocomplete=1 where SearchableFieldID=".$sf->ID; |
|
26 | + $sql = "UPDATE ElasticSearchPage_ElasticaSearchableFields SET Searchable=1," . |
|
27 | + "EnableAutocomplete=1 where SearchableFieldID=" . $sf->ID; |
|
28 | 28 | |
29 | 29 | DB::query($sql); |
30 | 30 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | |
44 | 44 | $this->assertEquals('the', $result->Query); |
45 | 45 | $lquery = strtolower($result->Query); |
46 | - foreach ($result->suggestions as $suggestion) { |
|
46 | + foreach($result->suggestions as $suggestion) { |
|
47 | 47 | $value = $suggestion->value; |
48 | 48 | $value = strtolower($value); |
49 | 49 | $this->assertContains($lquery, $value); |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | $locales = array(); |
33 | 33 | if(class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable')) { |
34 | - foreach (\Translatable::get_existing_content_languages('SiteTree') as $code => $val) { |
|
34 | + foreach(\Translatable::get_existing_content_languages('SiteTree') as $code => $val) { |
|
35 | 35 | array_push($locales, $code); |
36 | 36 | } |
37 | 37 | } else { |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | } |
40 | 40 | |
41 | 41 | // now iterate all the locales indexing each locale in turn using it's owner index settings |
42 | - foreach ($locales as $locale) { |
|
42 | + foreach($locales as $locale) { |
|
43 | 43 | Searchable::$index_ctr = 0; |
44 | - $message('Indexing locale '.$locale); |
|
44 | + $message('Indexing locale ' . $locale); |
|
45 | 45 | |
46 | - if (class_exists('Translatable')) { |
|
46 | + if(class_exists('Translatable')) { |
|
47 | 47 | \Translatable::set_current_locale($locale); |
48 | 48 | } |
49 | 49 | |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | $this->service->refresh(); |
61 | 61 | // display indexing speed stats |
62 | 62 | $endTime = microtime(true); |
63 | - $elapsed = $endTime-$startTime; |
|
63 | + $elapsed = $endTime - $startTime; |
|
64 | 64 | $perSecond = Searchable::$index_ctr / $elapsed; |
65 | - $info = "\nReindexing $locale completed \n ".Searchable::$index_ctr." docs in ".round($elapsed,2)." seconds "; |
|
66 | - $info .= "at ".round($perSecond,2)." documents per second\n\n"; |
|
65 | + $info = "\nReindexing $locale completed \n " . Searchable::$index_ctr . " docs in " . round($elapsed, 2) . " seconds "; |
|
66 | + $info .= "at " . round($perSecond, 2) . " documents per second\n\n"; |
|
67 | 67 | $message($info); |
68 | 68 | } |
69 | 69 |
@@ -25,11 +25,11 @@ discard block |
||
25 | 25 | |
26 | 26 | $locales = array(); |
27 | 27 | |
28 | - if ($this->locale == null) { |
|
29 | - if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
|
28 | + if($this->locale == null) { |
|
29 | + if(class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
|
30 | 30 | $this->locale = \Translatable::get_current_locale(); |
31 | 31 | } else { |
32 | - foreach (\Translatable::get_existing_content_languages('SiteTree') as $code => $val) { |
|
32 | + foreach(\Translatable::get_existing_content_languages('SiteTree') as $code => $val) { |
|
33 | 33 | array_push($locales, $code); |
34 | 34 | } |
35 | 35 | } |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | $es->setPageLength(20); |
43 | 43 | $es->addFilter('IsInSiteTree', true); |
44 | 44 | $results = $es->search($query); |
45 | - foreach ($results as $result) { |
|
46 | - $title = '['.$result->ClassName.', '.$result->ID.'] '; |
|
45 | + foreach($results as $result) { |
|
46 | + $title = '[' . $result->ClassName . ', ' . $result->ID . '] '; |
|
47 | 47 | $title .= $result->Title; |
48 | 48 | $message($title); |
49 | - if ($result->SearchHighlightsByField->Content) { |
|
50 | - foreach ($result->SearchHighlightsByField->Content as $highlight) { |
|
51 | - $message("- ".$highlight->Snippet); |
|
49 | + if($result->SearchHighlightsByField->Content) { |
|
50 | + foreach($result->SearchHighlightsByField->Content as $highlight) { |
|
51 | + $message("- " . $highlight->Snippet); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 |
@@ -18,7 +18,7 @@ |
||
18 | 18 | |
19 | 19 | $this->assertEquals('the', $result->Query); |
20 | 20 | $lquery = strtolower($result->Query); |
21 | - foreach ($result->suggestions as $suggestion) { |
|
21 | + foreach($result->suggestions as $suggestion) { |
|
22 | 22 | $value = $suggestion->value; |
23 | 23 | $value = strtolower($value); |
24 | 24 | $this->assertContains($lquery, $value); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * Note: characters are stripped from the content; make sure that your assertions take this into account. |
126 | 126 | * |
127 | 127 | * @param string $selector A basic CSS selector, e.g. 'li.jobs h3' |
128 | - * @param array|string $expectedMatches The content of at least one of the matched tags |
|
128 | + * @param integer $index |
|
129 | 129 | * @throws PHPUnit_Framework_AssertionFailedError |
130 | 130 | * @return boolean |
131 | 131 | */ |
@@ -155,7 +155,8 @@ discard block |
||
155 | 155 | * Note: characters are stripped from the content; make sure that your assertions take this into account. |
156 | 156 | * |
157 | 157 | * @param string $selector A basic CSS selector, e.g. 'li.jobs h3' |
158 | - * @param array|string $expectedMatches The content of at least one of the matched tags |
|
158 | + * @param integer $index |
|
159 | + * @param string $expectedClause |
|
159 | 160 | * @throws PHPUnit_Framework_AssertionFailedError |
160 | 161 | * @return boolean |
161 | 162 | */ |
@@ -183,6 +184,12 @@ discard block |
||
183 | 184 | /* |
184 | 185 | Check all the nodes matching the selector for attribute name = expected value |
185 | 186 | */ |
187 | + |
|
188 | + /** |
|
189 | + * @param string $selector |
|
190 | + * @param string $attributeName |
|
191 | + * @param string $expectedValue |
|
192 | + */ |
|
186 | 193 | public function assertAttributeHasExactValue($selector, $attributeName, $expectedValue) { |
187 | 194 | $items = $this->cssParser()->getBySelector($selector); |
188 | 195 | foreach ($items as $item) { |
@@ -191,6 +198,9 @@ discard block |
||
191 | 198 | } |
192 | 199 | |
193 | 200 | |
201 | + /** |
|
202 | + * @param string $selector |
|
203 | + */ |
|
194 | 204 | public function assertAttributesHaveExactValues($selector, $expectedValues) { |
195 | 205 | $attributeNames = array_keys($expectedValues); |
196 | 206 | $items = $this->cssParser()->getBySelector($selector); |
@@ -204,6 +214,10 @@ discard block |
||
204 | 214 | } |
205 | 215 | |
206 | 216 | |
217 | + /** |
|
218 | + * @param string $selector |
|
219 | + * @param integer $expectedAmount |
|
220 | + */ |
|
207 | 221 | public function assertNumberOfNodes($selector, $expectedAmount) { |
208 | 222 | $items = $this->cssParser()->getBySelector($selector); |
209 | 223 | foreach ($items as $item) { |
@@ -150,15 +150,15 @@ |
||
150 | 150 | |
151 | 151 | |
152 | 152 | /** |
153 | - *Assert that the indexth matching css node has a prefix as expected |
|
154 | - * |
|
155 | - * Note: characters are stripped from the content; make sure that your assertions take this into account. |
|
156 | - * |
|
157 | - * @param string $selector A basic CSS selector, e.g. 'li.jobs h3' |
|
158 | - * @param array|string $expectedMatches The content of at least one of the matched tags |
|
159 | - * @throws PHPUnit_Framework_AssertionFailedError |
|
160 | - * @return boolean |
|
161 | - */ |
|
153 | + *Assert that the indexth matching css node has a prefix as expected |
|
154 | + * |
|
155 | + * Note: characters are stripped from the content; make sure that your assertions take this into account. |
|
156 | + * |
|
157 | + * @param string $selector A basic CSS selector, e.g. 'li.jobs h3' |
|
158 | + * @param array|string $expectedMatches The content of at least one of the matched tags |
|
159 | + * @throws PHPUnit_Framework_AssertionFailedError |
|
160 | + * @return boolean |
|
161 | + */ |
|
162 | 162 | public function assertSelectorContains($selector, $index, $expectedClause) { |
163 | 163 | $items = $this->cssParser()->getBySelector($selector); |
164 | 164 |
@@ -171,7 +171,7 @@ |
||
171 | 171 | |
172 | 172 | $ctr = 0; |
173 | 173 | $item = strip_tags($items[$index]); |
174 | - if ($downcase) { |
|
174 | + if($downcase) { |
|
175 | 175 | $item = strtolower($item); |
176 | 176 | $expectedClause = strtolower($expectedClause); |
177 | 177 | } |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | $this->assertEquals(200, $searchPage->getStatusCode()); |
75 | 75 | $url = rtrim($url, '/'); |
76 | 76 | |
77 | - $response = $this->get($url); |
|
77 | + $response = $this->get($url); |
|
78 | 78 | |
79 | - $this->assertEquals(200, $response->getStatusCode()); |
|
79 | + $this->assertEquals(200, $response->getStatusCode()); |
|
80 | 80 | |
81 | - $this->assertSelectorStartsWithOrEquals('ul.iso span.count', 0, '(5)'); |
|
81 | + $this->assertSelectorStartsWithOrEquals('ul.iso span.count', 0, '(5)'); |
|
82 | 82 | $this->assertSelectorStartsWithOrEquals('ul.iso span.count', 1, '(11)'); |
83 | 83 | $this->assertSelectorStartsWithOrEquals('ul.iso span.count', 2, '(12)'); |
84 | 84 | $this->assertSelectorStartsWithOrEquals('ul.iso span.count', 3, '(13)'); |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | $url = rtrim($url, '/'); |
129 | 129 | $url .= '?ISO=400'; |
130 | 130 | |
131 | - $response = $this->get($url); |
|
131 | + $response = $this->get($url); |
|
132 | 132 | |
133 | - $this->assertEquals(200, $response->getStatusCode()); |
|
133 | + $this->assertEquals(200, $response->getStatusCode()); |
|
134 | 134 | |
135 | - // These are less than in the no facets selected case, as expected |
|
135 | + // These are less than in the no facets selected case, as expected |
|
136 | 136 | $this->assertSelectorStartsWithOrEquals('ul.focal_length span.count', 0, '(2)'); |
137 | 137 | $this->assertSelectorStartsWithOrEquals('ul.focal_length span.count', 1, '(1)'); |
138 | 138 | $this->assertSelectorStartsWithOrEquals('ul.focal_length span.count', 2, '(2)'); |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | $url = rtrim($url, '/'); |
177 | 177 | $url .= '?ISO=400&ShutterSpeed=2%2F250'; |
178 | 178 | |
179 | - $response = $this->get($url); |
|
180 | - $this->assertEquals(200, $response->getStatusCode()); |
|
179 | + $response = $this->get($url); |
|
180 | + $this->assertEquals(200, $response->getStatusCode()); |
|
181 | 181 | |
182 | - // These are less than in the one facet selected case, as expected |
|
183 | - $this->assertSelectorStartsWithOrEquals('ul.focal_length span.count', 0, '(1)'); |
|
182 | + // These are less than in the one facet selected case, as expected |
|
183 | + $this->assertSelectorStartsWithOrEquals('ul.focal_length span.count', 0, '(1)'); |
|
184 | 184 | $this->assertSelectorStartsWithOrEquals('ul.focal_length span.count', 1, '(2)'); |
185 | 185 | $this->assertSelectorStartsWithOrEquals('ul.aperture span.count', 0, '(1)'); |
186 | 186 | $this->assertSelectorStartsWithOrEquals('ul.aperture span.count', 1, '(1)'); |
@@ -207,11 +207,11 @@ discard block |
||
207 | 207 | $url = rtrim($url, '/'); |
208 | 208 | $url .= '?ISO=400&ShutterSpeed=2%2F250&Aspect=Vertical'; |
209 | 209 | |
210 | - $response = $this->get($url); |
|
211 | - $this->assertEquals(200, $response->getStatusCode()); |
|
210 | + $response = $this->get($url); |
|
211 | + $this->assertEquals(200, $response->getStatusCode()); |
|
212 | 212 | |
213 | - // These are less than in the one facet selected case, as expected |
|
214 | - $this->assertSelectorStartsWithOrEquals('span.count', 0, '(2)'); |
|
213 | + // These are less than in the one facet selected case, as expected |
|
214 | + $this->assertSelectorStartsWithOrEquals('span.count', 0, '(2)'); |
|
215 | 215 | $this->assertSelectorStartsWithOrEquals('span.count', 1, '(1)'); |
216 | 216 | $this->assertSelectorStartsWithOrEquals('span.count', 2, '(1)'); |
217 | 217 | } |
@@ -542,13 +542,13 @@ discard block |
||
542 | 542 | $searchPage = $this->get($searchPageObj->URLSegment); |
543 | 543 | $this->assertEquals(200, $searchPage->getStatusCode()); |
544 | 544 | |
545 | - $response = $this->submitForm("ElasticSearchForm_SearchForm", null, array( |
|
546 | - 'q' => 'New Zealand' |
|
547 | - )); |
|
545 | + $response = $this->submitForm("ElasticSearchForm_SearchForm", null, array( |
|
546 | + 'q' => 'New Zealand' |
|
547 | + )); |
|
548 | 548 | |
549 | 549 | $url = rtrim($url, '/'); |
550 | - $this->assertEquals(302, $response->getStatusCode()); |
|
551 | - $this->assertEquals($url . '?q=New Zealand&sfid=testwithagg', $response->getHeader('Location')); |
|
550 | + $this->assertEquals(302, $response->getStatusCode()); |
|
551 | + $this->assertEquals($url . '?q=New Zealand&sfid=testwithagg', $response->getHeader('Location')); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 |
@@ -413,7 +413,7 @@ |
||
413 | 413 | $this->assertEquals(200, $response->getStatusCode()); |
414 | 414 | |
415 | 415 | // results vary slightly due to sharding, hence check for a string instead of absolute results |
416 | - while ($ctr < 18) { |
|
416 | + while($ctr < 18) { |
|
417 | 417 | $this->assertSelectorContains('div.searchResult a', $ctr, 'New', true); |
418 | 418 | $ctr++; |
419 | 419 | $this->assertSelectorStartsWithOrEquals('div.searchResult a', $ctr, 'Similar'); |
@@ -96,20 +96,20 @@ discard block |
||
96 | 96 | //Need to check capitalisation of terms suggested that are different |
97 | 97 | |
98 | 98 | $chr = mb_substr ($possiblyUppercase, 0, 1, "UTF-8"); |
99 | - if (mb_strtolower($chr, "UTF-8") != $chr) { |
|
100 | - $upperLowercaseWord = $lowercaseWord; |
|
101 | - $upperLowercaseWord[0] = $chr; |
|
102 | - $withHighlights = str_replace($lowercaseWord, $upperLowercaseWord, $possiblyUppercaseHighlighted); |
|
103 | - $lowercaseWord[0] = $chr; |
|
104 | - array_push($plain, $lowercaseWord); |
|
105 | - array_push($highlighted, $withHighlights); |
|
106 | - } else { |
|
107 | - //No need to capitalise, so add suggested word |
|
108 | - array_push($plain, $lowercaseWord); |
|
109 | - |
|
110 | - //No need to capitalise, so add suggested highlighted word |
|
111 | - array_push($highlighted, $possiblyUppercaseHighlighted); |
|
112 | - } |
|
99 | + if (mb_strtolower($chr, "UTF-8") != $chr) { |
|
100 | + $upperLowercaseWord = $lowercaseWord; |
|
101 | + $upperLowercaseWord[0] = $chr; |
|
102 | + $withHighlights = str_replace($lowercaseWord, $upperLowercaseWord, $possiblyUppercaseHighlighted); |
|
103 | + $lowercaseWord[0] = $chr; |
|
104 | + array_push($plain, $lowercaseWord); |
|
105 | + array_push($highlighted, $withHighlights); |
|
106 | + } else { |
|
107 | + //No need to capitalise, so add suggested word |
|
108 | + array_push($plain, $lowercaseWord); |
|
109 | + |
|
110 | + //No need to capitalise, so add suggested highlighted word |
|
111 | + array_push($highlighted, $possiblyUppercaseHighlighted); |
|
112 | + } |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -140,38 +140,38 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public static function parseSuggestionExplanation($explanation) { |
142 | 142 | $explanation = explode('-ConstantScore', $explanation)[0]; |
143 | - $bracketPos = strpos($explanation, ')~'); |
|
143 | + $bracketPos = strpos($explanation, ')~'); |
|
144 | 144 | |
145 | - if (substr($explanation, 0,2) == '((') { |
|
146 | - $explanation = substr($explanation, 2, $bracketPos-2); |
|
147 | - } elseif (substr($explanation, 0,1) == '(') { |
|
148 | - $explanation = substr($explanation, 1, $bracketPos-2); |
|
149 | - } |
|
145 | + if (substr($explanation, 0,2) == '((') { |
|
146 | + $explanation = substr($explanation, 2, $bracketPos-2); |
|
147 | + } elseif (substr($explanation, 0,1) == '(') { |
|
148 | + $explanation = substr($explanation, 1, $bracketPos-2); |
|
149 | + } |
|
150 | 150 | |
151 | - $terms = array(); |
|
151 | + $terms = array(); |
|
152 | 152 | |
153 | - //Field name(s) => terms |
|
154 | - $splits = explode(' ', $explanation); |
|
153 | + //Field name(s) => terms |
|
154 | + $splits = explode(' ', $explanation); |
|
155 | 155 | |
156 | - foreach ($splits as $fieldAndTerm) { |
|
157 | - $splits = explode(':', $fieldAndTerm); |
|
156 | + foreach ($splits as $fieldAndTerm) { |
|
157 | + $splits = explode(':', $fieldAndTerm); |
|
158 | 158 | |
159 | - // This is the no terms case |
|
160 | - if (sizeof($splits) < 2) { |
|
161 | - break; |
|
162 | - } |
|
159 | + // This is the no terms case |
|
160 | + if (sizeof($splits) < 2) { |
|
161 | + break; |
|
162 | + } |
|
163 | 163 | |
164 | - $fieldname = $splits[0]; |
|
165 | - $term = $splits[1]; |
|
164 | + $fieldname = $splits[0]; |
|
165 | + $term = $splits[1]; |
|
166 | 166 | |
167 | - if (!isset($terms[$fieldname])) { |
|
168 | - $terms[$fieldname] = array(); |
|
169 | - } |
|
167 | + if (!isset($terms[$fieldname])) { |
|
168 | + $terms[$fieldname] = array(); |
|
169 | + } |
|
170 | 170 | |
171 | - array_push($terms[$fieldname], $term); |
|
172 | - } |
|
171 | + array_push($terms[$fieldname], $term); |
|
172 | + } |
|
173 | 173 | |
174 | - return $terms; |
|
174 | + return $terms; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @var string $content Text to display when in command line mode |
29 | 29 | */ |
30 | 30 | public static function message($content) { |
31 | - if (\Director::is_cli() && self::$cli_printer_output === true) { |
|
31 | + if(\Director::is_cli() && self::$cli_printer_output === true) { |
|
32 | 32 | echo "$content\n"; |
33 | 33 | } |
34 | 34 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $options = $alternativeQuerySuggestions[0]['options']; |
54 | 54 | |
55 | 55 | $resultArray = null; |
56 | - if (sizeof($options) > 0) { |
|
56 | + if(sizeof($options) > 0) { |
|
57 | 57 | //take the first suggestion |
58 | 58 | $suggestedPhrase = $options[0]['text']; |
59 | 59 | $suggestedPhraseHighlighted = $options[0]['highlighted']; |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | $originalParts = explode(' ', $originalQuery); |
63 | 63 | $suggestedParts = explode(' ', $suggestedPhrase); |
64 | 64 | |
65 | - $markedHighlightedParts = ' '.$suggestedPhraseHighlighted.' '; |
|
66 | - $markedHighlightedParts = str_replace(' '.$preTags, ' '.self::$pre_marker, $markedHighlightedParts); |
|
65 | + $markedHighlightedParts = ' ' . $suggestedPhraseHighlighted . ' '; |
|
66 | + $markedHighlightedParts = str_replace(' ' . $preTags, ' ' . self::$pre_marker, $markedHighlightedParts); |
|
67 | 67 | |
68 | - $markedHighlightedParts = str_replace($postTags.' ', self::$post_marker, $markedHighlightedParts); |
|
68 | + $markedHighlightedParts = str_replace($postTags . ' ', self::$post_marker, $markedHighlightedParts); |
|
69 | 69 | |
70 | 70 | $markedHighlightedParts = trim($markedHighlightedParts); |
71 | 71 | $markedHighlightedParts = trim($markedHighlightedParts); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $lowerToUpper = array(); |
77 | 77 | $lowerToHighlighted = array(); |
78 | 78 | $ctr = 0; |
79 | - foreach ($suggestedParts as $lowercaseWord) { |
|
79 | + foreach($suggestedParts as $lowercaseWord) { |
|
80 | 80 | $lowerToUpper[$lowercaseWord] = $originalParts[$ctr]; |
81 | 81 | $lowerToHighlighted[$lowercaseWord] = $highlightedParts[$ctr]; |
82 | 82 | $ctr++; |
@@ -84,19 +84,19 @@ discard block |
||
84 | 84 | |
85 | 85 | $plain = array(); |
86 | 86 | $highlighted = array(); |
87 | - foreach ($suggestedParts as $lowercaseWord) { |
|
87 | + foreach($suggestedParts as $lowercaseWord) { |
|
88 | 88 | $possiblyUppercase = $lowerToUpper[$lowercaseWord]; |
89 | 89 | $possiblyUppercaseHighlighted = $lowerToHighlighted[$lowercaseWord]; |
90 | 90 | |
91 | 91 | //If the terms are identical other than case, e.g. new => New, then simply swap |
92 | - if (strtolower($possiblyUppercase) == $lowercaseWord) { |
|
92 | + if(strtolower($possiblyUppercase) == $lowercaseWord) { |
|
93 | 93 | array_push($plain, $possiblyUppercase); |
94 | 94 | array_push($highlighted, $possiblyUppercase); |
95 | 95 | } else { |
96 | 96 | //Need to check capitalisation of terms suggested that are different |
97 | 97 | |
98 | - $chr = mb_substr ($possiblyUppercase, 0, 1, "UTF-8"); |
|
99 | - if (mb_strtolower($chr, "UTF-8") != $chr) { |
|
98 | + $chr = mb_substr($possiblyUppercase, 0, 1, "UTF-8"); |
|
99 | + if(mb_strtolower($chr, "UTF-8") != $chr) { |
|
100 | 100 | $upperLowercaseWord = $lowercaseWord; |
101 | 101 | $upperLowercaseWord[0] = $chr; |
102 | 102 | $withHighlights = str_replace($lowercaseWord, $upperLowercaseWord, $possiblyUppercaseHighlighted); |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - $highlighted = ' '.implode(' ', $highlighted).' '; |
|
117 | - $highlighted = str_replace(self::$pre_marker, ' '.$preTags, $highlighted); |
|
118 | - $highlighted = str_replace(self::$post_marker, $postTags.' ', $highlighted); |
|
116 | + $highlighted = ' ' . implode(' ', $highlighted) . ' '; |
|
117 | + $highlighted = str_replace(self::$pre_marker, ' ' . $preTags, $highlighted); |
|
118 | + $highlighted = str_replace(self::$post_marker, $postTags . ' ', $highlighted); |
|
119 | 119 | |
120 | 120 | $resultArray['suggestedQuery'] = implode(' ', $plain); |
121 | 121 | $resultArray['suggestedQueryHighlighted'] = trim($highlighted); |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | $explanation = explode('-ConstantScore', $explanation)[0]; |
143 | 143 | $bracketPos = strpos($explanation, ')~'); |
144 | 144 | |
145 | - if (substr($explanation, 0,2) == '((') { |
|
146 | - $explanation = substr($explanation, 2, $bracketPos-2); |
|
147 | - } elseif (substr($explanation, 0,1) == '(') { |
|
148 | - $explanation = substr($explanation, 1, $bracketPos-2); |
|
145 | + if(substr($explanation, 0, 2) == '((') { |
|
146 | + $explanation = substr($explanation, 2, $bracketPos - 2); |
|
147 | + } elseif(substr($explanation, 0, 1) == '(') { |
|
148 | + $explanation = substr($explanation, 1, $bracketPos - 2); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | $terms = array(); |
@@ -153,18 +153,18 @@ discard block |
||
153 | 153 | //Field name(s) => terms |
154 | 154 | $splits = explode(' ', $explanation); |
155 | 155 | |
156 | - foreach ($splits as $fieldAndTerm) { |
|
156 | + foreach($splits as $fieldAndTerm) { |
|
157 | 157 | $splits = explode(':', $fieldAndTerm); |
158 | 158 | |
159 | 159 | // This is the no terms case |
160 | - if (sizeof($splits) < 2) { |
|
160 | + if(sizeof($splits) < 2) { |
|
161 | 161 | break; |
162 | 162 | } |
163 | 163 | |
164 | 164 | $fieldname = $splits[0]; |
165 | 165 | $term = $splits[1]; |
166 | 166 | |
167 | - if (!isset($terms[$fieldname])) { |
|
167 | + if(!isset($terms[$fieldname])) { |
|
168 | 168 | $terms[$fieldname] = array(); |
169 | 169 | } |
170 | 170 | |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | * @return function print content to either web browser or command line. Can be optionally supressed |
192 | 192 | */ |
193 | 193 | public static function getPrinter() { |
194 | - return function ($content) { |
|
195 | - if (self::$cli_printer_output === true) { |
|
194 | + return function($content) { |
|
195 | + if(self::$cli_printer_output === true) { |
|
196 | 196 | print(\Director::is_cli() ? "T1 $content\n" : "T2 <p>$content</p>"); |
197 | 197 | } |
198 | 198 |