7
7
8
8
namespace Drupal \search_api_solr \Plugin \SearchApi \Backend ;
9
9
10
+ use Drupal \Core \Config \Config ;
10
11
use Drupal \Core \Form \FormBuilderInterface ;
11
12
use Drupal \search_api \Exception \SearchApiException ;
12
13
use Drupal \search_api \Index \IndexInterface ;
@@ -76,13 +77,21 @@ class SearchApiSolrBackend extends BackendPluginBase {
76
77
*/
77
78
protected $ formBuilder ;
78
79
80
+ /**
81
+ * A config object for 'search_api_solr.settings'.
82
+ *
83
+ * @var \Drupal\Core\Config\Config
84
+ */
85
+ protected $ searchApiSolrSettings ;
86
+
79
87
/**
80
88
* {@inheritdoc}
81
89
*/
82
- public function __construct (array $ configuration , $ plugin_id , array $ plugin_definition , FormBuilderInterface $ form_builder ) {
90
+ public function __construct (array $ configuration , $ plugin_id , array $ plugin_definition , FormBuilderInterface $ form_builder, Config $ search_api_solr_settings ) {
83
91
parent ::__construct ($ configuration , $ plugin_id , $ plugin_definition );
84
92
85
93
$ this ->formBuilder = $ form_builder ;
94
+ $ this ->searchApiSolrSettings = $ search_api_solr_settings ;
86
95
}
87
96
88
97
/**
@@ -93,7 +102,8 @@ public static function create(ContainerInterface $container, array $configuratio
93
102
$ configuration ,
94
103
$ plugin_id ,
95
104
$ plugin_definition ,
96
- $ container ->get ('form_builder ' )
105
+ $ container ->get ('form_builder ' ),
106
+ $ container ->get ('config.factory ' )->get ('search_api_solr.settings ' )
97
107
);
98
108
}
99
109
@@ -1862,7 +1872,7 @@ public function getAutocompleteSuggestions(SearchApiQueryInterface $query, Searc
1862
1872
// Don't suggest terms that are too frequent (by default in more
1863
1873
// than 90% of results).
1864
1874
$ result_count = $ response ->response ->numFound ;
1865
- $ max_occurrences = $ result_count * variable_get ( ' search_api_solr_autocomplete_max_occurrences ' , 0.9 );
1875
+ $ max_occurrences = $ result_count * $ this -> searchApiSolrSettings -> get ( ' autocomplete_max_occurrences ' );
1866
1876
if (($ max_occurrences >= 1 || $ i > 0 ) && $ max_occurrences < $ result_count ) {
1867
1877
foreach ($ matches as $ match => $ count ) {
1868
1878
if ($ count > $ max_occurrences ) {
@@ -2259,8 +2269,9 @@ public function getFile($file = NULL) {
2259
2269
* Prefixes an index ID as configured.
2260
2270
*
2261
2271
* The resulting ID will be a concatenation of the following strings:
2262
- * - If set, the "search_api_solr_index_prefix" variable.
2263
- * - If set, the index-specific "search_api_solr_index_prefix_INDEX" variable.
2272
+ * - If set, the "search_api_solr.settings.index_prefix" configuration.
2273
+ * - If set, the index-specific "search_api_solr.settings.index_prefix_INDEX"
2274
+ * configuration.
2264
2275
* - The index's machine name.
2265
2276
*
2266
2277
* @param string $machine_name
@@ -2271,9 +2282,9 @@ public function getFile($file = NULL) {
2271
2282
*/
2272
2283
protected function getIndexId ($ machine_name ) {
2273
2284
// Prepend per-index prefix.
2274
- $ id = variable_get ( ' search_api_solr_index_prefix_ ' . $ machine_name, '' ) . $ machine_name ;
2285
+ $ id = $ this -> searchApiSolrSettings -> get ( ' index_prefix_ ' . $ machine_name ) . $ machine_name ;
2275
2286
// Prepend environment prefix.
2276
- $ id = variable_get ( ' search_api_solr_index_prefix ' , ' ' ) . $ id ;
2287
+ $ id = $ this -> searchApiSolrSettings -> get ( ' index_prefix ' ) . $ id ;
2277
2288
return $ id ;
2278
2289
}
2279
2290
0 commit comments