我正在努力弄清楚Elastica / FOSElastica是如何工作的。我把它运行得很好,就像非常简单的搜索查询一样,产品名称与我的搜索字符串完全匹配。
由于这不是一种好的搜索方式,我必须添加分析器才能执行更好的搜索结果。但他们没有工作..
我试图复制并粘贴此示例代码(插入我的索引/类型当然)=> http://obtao.com/blog/2013/10/configure-elasticsearch-on-an-efficient-way/#comment-16733
所以,这是我的问题:如何让我的分析仪工作?我想,我必须在我的控制器中应用它们,但我不完全确定我会怎么做......
这是我的配置
#app/config/config.yml
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
search:
client: default
settings:
index:
analysis:
analyzer:
custom_analyzer :
type : custom
tokenizer: nGram
filter : [stopwords, asciifolding ,lowercase, snowball, elision, worddelimiter]
custom_search_analyzer :
type : custom
tokenizer: standard
filter : [stopwords, asciifolding ,lowercase, snowball, elision, worddelimiter]
my_analyzer _:
type: snowball
language: German
tokenizer:
nGram:
type: nGram
min_gram: 2
max_gram: 20
filter:
snowball:
type: snowball
language: German
elision:
type: elision
articles: [l, m, t, qu, n, s, j, d]
stopwords:
type: stop
stopwords: [_german_]
ignore_case : true
worddelimiter :
type: word_delimiter
types:
article :
mappings:
articleNumber:
shortName: [ boost: 6, analyzer : custom_analyzer, custom_search_analyzer, my_analyzer]
shortDescription:
index_analyzer : custom_analyzer
search_analyzer : custom_search_analyzer
longDescription:
index_analyzer : custom_analyzer
search_analyzer : custom_search_analyzer
persistence:
driver: orm
model: IndexBundle\Entity\Articles
finder: ~
provider: ~
listener: ~
这是我的控制者:
$query = new \Elastica\Query\Match();
$query->setFieldQuery(‘shortName’, $searchTerm);
$query->setFieldFuzziness(‘shortName’, 0.7);
$query->setFieldMinimumShouldMatch(‘shortName’, ’80%’);
$boolQuery = new \Elastica\Query\Bool();
$boolQuery->addMust($query);
$baseQuery = $query;
$filtered = new \Elastica\Query\Filtered($baseQuery);
$query = \Elastica\Query::create($filtered);
$articles = $finder->find($query);