public function SearchApiSolrBackend::getSolrFieldNames in Search API Solr 8
Same name and namespace in other branches
- 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getSolrFieldNames()
- 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getSolrFieldNames()
- 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getSolrFieldNames()
Creates a list of all indexed field names mapped to their Solr field names.
The special fields "search_api_id" and "search_api_relevance" are also included. Any Solr fields that exist on search results are mapped back to to their local field names in the final result set.
Parameters
\Drupal\search_api\IndexInterface $index: The Search Api index.
bool $reset: (optional) Whether to reset the static cache.
Overrides SolrBackendInterface::getSolrFieldNames
See also
SearchApiSolrBackend::search()
5 calls to SearchApiSolrBackend::getSolrFieldNames()
- SearchApiSolrBackend::extractResults in src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php - Extract results from a Solr response.
- SearchApiSolrBackend::getAutocompleteFields in src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php - Get the fields to search for autocomplete terms.
- SearchApiSolrBackend::getDocuments in src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php - Retrieves Solr documents from search api index items.
- SearchApiSolrBackend::indexFieldsUpdated in src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php - Checks if the recently updated index had any fields changed.
- SearchApiSolrBackend::search in src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php - Options on $query prefixed by 'solr_param_' will be passed natively to Solr as query parameter without the prefix. For example you can set the "Minimum Should Match" parameter 'mm' to '75%' like this:
File
- src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php, line 1108
Class
- SearchApiSolrBackend
- Apache Solr backend for search api.
Namespace
Drupal\search_api_solr\Plugin\search_api\backendCode
public function getSolrFieldNames(IndexInterface $index, $reset = FALSE) {
// @todo The field name mapping should be cached per index because custom
// queries needs to access it on every query. But we need to be aware of
// datasource additions and deletions.
if (!isset($this->fieldNames[$index
->id()]) || $reset) {
// This array maps "local property name" => "solr doc property name".
$ret = array(
'search_api_relevance' => 'score',
'search_api_random' => 'random',
);
// Add the names of any fields configured on the index.
$fields = $index
->getFields();
$fields += $this
->getSpecialFields($index);
foreach ($fields as $key => $field) {
if (empty($ret[$key])) {
// Generate a field name; this corresponds with naming conventions in
// our schema.xml.
$type = $field
->getType();
$type_info = SearchApiSolrUtility::getDataTypeInfo($type);
$pref = isset($type_info['prefix']) ? $type_info['prefix'] : '';
if ($this->fieldsHelper
->isFieldIdReserved($key)) {
$pref .= 's';
}
else {
if ($field
->getDataDefinition()
->isList() || $this
->isHierarchicalField($field)) {
$pref .= 'm';
}
else {
try {
$datasource = $field
->getDatasource();
if (!$datasource) {
throw new SearchApiException();
}
else {
$pref .= $this
->getPropertyPathCardinality($field
->getPropertyPath(), $datasource
->getPropertyDefinitions()) != 1 ? 'm' : 's';
}
} catch (SearchApiException $e) {
// Thrown by $field->getDatasource(). Assume multi value to be
// safe.
$pref .= 'm';
}
}
}
$name = $pref . '_' . $key;
$ret[$key] = SearchApiSolrUtility::encodeSolrName($name);
// Add a distance pseudo field for any location field. These fields
// don't really exist in the solr core, but we tell solr to name the
// distance calculation results that way. Later we directly pass these
// as "fields" to Drupal and especially Views.
if ($type == 'location') {
$ret[$key . '__distance'] = SearchApiSolrUtility::encodeSolrName($name . '__distance');
}
}
}
// Let modules adjust the field mappings.
$this->moduleHandler
->alter('search_api_solr_field_mapping', $index, $ret);
$this->fieldNames[$index
->id()] = $ret;
}
return $this->fieldNames[$index
->id()];
}