function apachesolr_autocomplete_get_stopwords in Apache Solr Autocomplete 7
Same name and namespace in other branches
- 6 apachesolr_autocomplete.module \apachesolr_autocomplete_get_stopwords()
- 7.2 apachesolr_autocomplete.module \apachesolr_autocomplete_get_stopwords()
Gets the current stopwords list configured in Solr.
1 call to apachesolr_autocomplete_get_stopwords()
- apachesolr_autocomplete_suggest in ./
apachesolr_autocomplete.module - Helper function to get suggestions from Solr.
File
- ./
apachesolr_autocomplete.module, line 576 - Alters search forms to suggest terms using Apache Solr using AJAX. Thanks to: robertDouglass who contributed some of the code. sch4lly for contributing to D7 version
Code
function apachesolr_autocomplete_get_stopwords($solr = NULL) {
static $static_cache = array();
if (!$solr) {
$env_id = apachesolr_default_environment();
$solr = apachesolr_get_solr($env_id);
}
else {
$env_id = $solr
->getId();
}
// Try static cache.
if (isset($static_cache[$env_id])) {
return $static_cache[$env_id];
}
// Try Drupal cache.
$cid = 'apachesolr_autocomplete_stopwords:' . $env_id;
$cached = cache_get($cid);
if ($cached && $cached->expire > REQUEST_TIME) {
return $cached->data;
}
try {
$response = $solr
->makeServletRequest('admin/file', array(
'file' => 'stopwords.txt',
));
} catch (Exception $e) {
$static_cache[$env_id] = array();
return array();
}
$words = array();
foreach (explode("\n", $response->data) as $line) {
if (drupal_substr($line, 0, 1) == "#") {
continue;
}
if ($word = trim($line)) {
$words[] = $word;
}
}
// Cache in Drupal cache for 10 minutes.
cache_set($cid, $words, 'cache', REQUEST_TIME + 600);
$static_cache[$env_id] = $words;
return $words;
}