Elasticsearch 和 symfony 搜索单词的一部分
Elasticsearch and symfony search for a part of a word
我是 Elastic Search 的新手,也许你可以帮助我:
所以,我有 symfony 和 Elasticsearch (FOSElasticaBundle)。
如果我正在搜索标题中的完整单词 - 一切正常(例如,如果我键入 "hello",我将在 "hello" 世界所在的位置获得结果)。
But problem is, that, I want to be able to search for a part of word
too, for example if I type "hel" I want to get result where "hel" is
part of a word.
我的config.yml
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
app:
client: default
settings:
index:
analysis:
analyzer:
custom_search_analyzer:
type: custom
tokenizer: standard
filter : [standard, lowercase, asciifolding]
custom_index_analyzer:
type: custom
tokenizer: standard
filter : [standard, lowercase, asciifolding, custom_filter]
filter:
custom_filter:
type: edgeNGram
side: front
min_gram: 1
max_gram: 20
types:
book:
mappings:
Author:
isbn:
title: { analyzer: custom_search_analyzer, analyzer: custom_index_analyzer, filter: custom_filter, type: string }
persistence:
driver: orm
model: VienasVienas\Bundle\BooksBundle\Entity\Book
provider:
listener:
finder:
我的php函数
public function indexAction(Request $request)
{
$finder = $this->get('fos_elastica.finder.app.book');
$searchTerm = $request->query->get('q');
$searchQuery = new \Elastica\Query\QueryString();
$searchQuery->setParam('query', $searchTerm);
$searchQuery->setDefaultOperator('AND');
$books = $finder->find($searchQuery);
return array(
'entities' => $books
);
}
有人能帮忙吗?
所以我只是忘记为字段添加 setParam...
$searchQuery->setParam('fields', array(
'Author',
'title',
'isbn',
));
现在一切正常!
我是 Elastic Search 的新手,也许你可以帮助我:
所以,我有 symfony 和 Elasticsearch (FOSElasticaBundle)。
如果我正在搜索标题中的完整单词 - 一切正常(例如,如果我键入 "hello",我将在 "hello" 世界所在的位置获得结果)。
But problem is, that, I want to be able to search for a part of word too, for example if I type "hel" I want to get result where "hel" is part of a word.
我的config.yml
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
app:
client: default
settings:
index:
analysis:
analyzer:
custom_search_analyzer:
type: custom
tokenizer: standard
filter : [standard, lowercase, asciifolding]
custom_index_analyzer:
type: custom
tokenizer: standard
filter : [standard, lowercase, asciifolding, custom_filter]
filter:
custom_filter:
type: edgeNGram
side: front
min_gram: 1
max_gram: 20
types:
book:
mappings:
Author:
isbn:
title: { analyzer: custom_search_analyzer, analyzer: custom_index_analyzer, filter: custom_filter, type: string }
persistence:
driver: orm
model: VienasVienas\Bundle\BooksBundle\Entity\Book
provider:
listener:
finder:
我的php函数
public function indexAction(Request $request)
{
$finder = $this->get('fos_elastica.finder.app.book');
$searchTerm = $request->query->get('q');
$searchQuery = new \Elastica\Query\QueryString();
$searchQuery->setParam('query', $searchTerm);
$searchQuery->setDefaultOperator('AND');
$books = $finder->find($searchQuery);
return array(
'entities' => $books
);
}
有人能帮忙吗?
所以我只是忘记为字段添加 setParam...
$searchQuery->setParam('fields', array( 'Author', 'title', 'isbn', ));
现在一切正常!