Skip to content

Instantly share code, notes, and snippets.

@xyhp915
Created May 6, 2014 03:34
Show Gist options
  • Save xyhp915/11552837 to your computer and use it in GitHub Desktop.
Save xyhp915/11552837 to your computer and use it in GitHub Desktop.
elasticsearch test
<?php
/* Elasticsearch pinyin index setting */
$index->create( array(
"analysis" => array(
"analyzer" => array(
"hl_pinyin_analyzer" => array(
"tokenizer" => "my_pinyin",
"filter" => array("standard","my_ngram_tokenizer"),
),
"hl_pinyin_first_letter_analyzer" => array(
"tokenizer" => "pinyin_first_letter",
"filter" => array( "standard", "my_ngram_tokenizer" ),
),
),
"tokenizer" => array(
"my_pinyin" => array(
"type" => "pinyin",
"first_letter" => "none",
"padding_char" => "",
),
),
"filter" => array(
"my_ngram_tokenizer" => [
"type" => "edgeNGram",
"min_gram" => "2",
"max_gram" => "10",
]
)
),
), true );
/* Mapping setting */
$map->setParam('_id', array(
"path" => "id",
) );
$map->setProperties( array(
'id' => array(
'type' => 'integer',
'index' => 'not_analyzed',
),
'name' => array(
'type' => 'multi_field',
'fields' => array(
'name' => array(
'type' => 'string',
'store' => 'no',
'term_vector' => 'with_positions_offsets',
'analyzer' => 'hl_pinyin_analyzer',
'boost' => 7,
),
'py_first' => array(
'type' => 'string',
'store' => 'yes',
'analyzer' => 'hl_pinyin_first_letter_analyzer',
'term_vector' => 'with_positions_offsets',
'boost' => 8,
),
'primitive' => array(
'type' => 'string',
'store' => 'yes',
'analyzer' => 'mmseg',
'boost' => 9,
),
'original' => array(
'type' => 'string',
'store' => 'yes',
'analyzer' => 'keyword',
'boost' => 10,
)
)
),
'email' => array(
'type' => 'string',
'analyzer' => 'pinyin',
)
) );
/* user for hl */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment