1 | <?php |
||
35 | class SpellChecker |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * Search instance |
||
40 | * |
||
41 | * @var Search |
||
42 | */ |
||
43 | protected $search; |
||
44 | |||
45 | /** |
||
46 | * Configuration |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $configuration; |
||
51 | |||
52 | /** |
||
53 | * Constructor |
||
54 | * |
||
55 | */ |
||
56 | 25 | public function __construct() |
|
57 | { |
||
58 | 25 | $this->search = GeneralUtility::makeInstance(Search::class); |
|
59 | 25 | $this->configuration = Util::getSolrConfiguration(); |
|
|
|||
60 | 25 | } |
|
61 | |||
62 | /** |
||
63 | * Gets the collated suggestion |
||
64 | * |
||
65 | * @return string collated suggestion |
||
66 | */ |
||
67 | 3 | public function getCollatedSuggestion() |
|
68 | { |
||
69 | 3 | $suggestions = $this->search->getSpellcheckingSuggestions(); |
|
70 | |||
71 | 3 | return $suggestions['collation']; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * Checks whether the user's query was correctly spelled. |
||
76 | * |
||
77 | * @return bool TRUE if the query terms were correctly spelled, FALSE otherwise |
||
78 | */ |
||
79 | public function isIncorrectlySpelled() |
||
80 | { |
||
81 | $suggestions = $this->getSuggestions(); |
||
82 | |||
83 | return $suggestions['correctlySpelled']; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Gets the raw spellchecking suggestions |
||
88 | * |
||
89 | * @return array Array of suggestions |
||
90 | */ |
||
91 | 20 | public function getSuggestions() |
|
92 | { |
||
93 | 20 | $suggestions = $this->search->getSpellcheckingSuggestions(); |
|
94 | |||
95 | 20 | return $suggestions; |
|
96 | } |
||
97 | |||
98 | /** |
||
99 | * Query URL with a suggested/corrected query |
||
100 | * |
||
101 | * @return string Suggestion/spell checked query URL |
||
102 | */ |
||
103 | public function getSuggestionQueryUrl() |
||
104 | { |
||
105 | $suggestions = $this->getSuggestions(); |
||
106 | |||
107 | $query = clone $this->search->getQuery(); |
||
108 | $query->setKeywords($suggestions['collation']); |
||
109 | |||
110 | $queryLinkBuilder = GeneralUtility::makeInstance(LinkBuilder::class, $query); |
||
111 | $queryLinkBuilder->setLinkTargetPageId($GLOBALS['TSFE']->id); |
||
112 | |||
113 | return $queryLinkBuilder->getQueryUrl(); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Generates a link with spell checking suggestions if it is activated and |
||
118 | * spell checking suggestions are returned by Solr. |
||
119 | * |
||
120 | * @return string A link to start over with a new search using the suggested keywords. |
||
121 | */ |
||
122 | 25 | public function getSpellCheckingSuggestions() |
|
138 | |||
139 | /** |
||
140 | * Query link with a suggested/corrected query |
||
141 | * |
||
142 | * @return string Suggestion/spell checked query link |
||
143 | */ |
||
144 | 5 | public function getSuggestionQueryLink() |
|
156 | } |
||
157 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..