Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch 5.x compatibility: multi_field has been depreciated #144

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/elasticsearch/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ static function clear()
// will throw an exception if index does not exist
}

$index->create();
$settings = array();
$settings = Config::apply_filters('indexer_index_settings', $settings);

$index->create($settings);

self::_map($index);
}
Expand Down Expand Up @@ -125,9 +128,7 @@ static function addOrUpdate($post, $index = null)

$data = self::_build_document($post);

if ($data) {
$type->addDocument(new \Elastica\Document($post->ID, $data));
}
$type->addDocument(new \Elastica\Document($post->ID, $data));
}

/**
Expand Down Expand Up @@ -282,12 +283,17 @@ static function _map_values(&$properties, $type, $config_fields, $kind)
$notanalyzed = Config::option('not_analyzed');

foreach ($config_fields as $field) {

// set default
$props = array('type' => 'string');
$props = array(
'type' => 'text',
'store' => true,
);
// detect special field type
if (isset($numeric[$field])) {
$props['type'] = 'float';
} elseif (isset($notanalyzed[$field]) || $kind == 'taxonomy' || $field == 'post_type') {
$props['type'] = 'keyword';
$props['index'] = 'not_analyzed';
} elseif ($field == 'post_date') {
$props['type'] = 'date';
Expand All @@ -296,12 +302,13 @@ static function _map_values(&$properties, $type, $config_fields, $kind)
$props['index'] = 'analyzed';
}

if ($props['type'] == 'string' && $props['index'] == 'analyzed') {
if ($props['type'] == 'text' && $props['index'] == 'analyzed') {
// provides more accurate searches

$lang = Config::apply_filters('string_language', 'english');
$props = array(
'type' => 'multi_field',
'type' => 'text',
'store' => true,
'fields' => array(
$field => $props,
$lang => array_merge($props, array(
Expand All @@ -311,12 +318,16 @@ static function _map_values(&$properties, $type, $config_fields, $kind)
);
}



// generic filter indexer_map_field| indexer_map_meta | indexer_map_taxonomy
$props = Config::apply_filters('indexer_map_' . $kind, $props, $field);

//var_dump($props); var_dump($field);

// also index taxonomy_name field
if ($kind == 'taxonomy') {
$tax_name_props = array('type' => 'string');
$tax_name_props = array('type' => 'text');
$tax_name_props = Config::apply_filters('indexer_map_taxonomy_name', $tax_name_props, $field);
}

Expand Down Expand Up @@ -368,4 +379,3 @@ static function _index($write = false)
}
}

?>