gpt4 book ai didi

php - Elasticsearch和Symfony搜索单词的一部分

转载 作者:行者123 更新时间:2023-12-03 02:02:53 26 4
gpt4 key购买 nike

我是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',
));


现在一切正常!

关于php - Elasticsearch和Symfony搜索单词的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30137755/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com