FOS Elastica,在整个句子中搜索
FOS Elastica, Search in whole sentences
我对 elasticsearch 和 FOSElastica 还很陌生,
我想获取代表学校名称的映射字段的相关结果。
我的配置:
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
app:
settings:
index:
analysis:
analyzer:
czech :
tokenizer: standard
filter : [czech_stop, czech_stemmer ,lowercase, asciifolding]
filter:
czech_stop:
type: stop
stopwords: _czech_
czech_stemmer:
type: stemmer
languague: czech
types:
school:
mappings:
name:
type: string
analyzer : czech
boost : 10
persistence:
driver: orm
model: Yearbook\SUBundle\Entity\School
provider: ~
listener:
immediate: ~
finder: ~
名称字段中存储的是学校名称。我使用命令行 fos:elastica:search school "Hi"
得到零结果,但是搜索整个单词工作正常 fos:elastica:search school "High"
我也试过不同的方法来在控制器中获得结果,但是 none 它起作用了。我认为问题可能出在配置文件中。
没有发现相关问题。
谢谢大家的回复
找到解决方案,
通过将 custom_filter EdgeNGram 添加到 confing 文件:
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
app:
settings:
index:
analysis:
analyzer:
custom_search_analyzer :
type : custom
tokenizer: standard
filter : [czech_stop, czech_stemmer ,lowercase, asciifolding,standard]
custom_index_analyzer :
tokenizer: standard
type : custom
filter : [czech_stop, czech_stemmer ,lowercase, asciifolding,standard,custom_filter]
filter:
custom_filter:
type: edgeNGram
side: front
min_gram: 1
max_gram: 20
czech_stop:
type: stop
stopwords: _czech_
czech_stemmer:
type: stemmer
languague: czech
types:
school:
mappings:
name:
type: string
search_analyzer : custom_search_analyzer
index_analyzer : custom_index_analyzer
boost : 10
urlFriendly:
type: string
persistence:
driver: orm
model: Yearbook\SUBundle\Entity\School
provider: ~
listener:
immediate: ~
finder: ~
正在控制器中获取结果列表:
$needle=$request->request->get('needle');
$index =$this->container->get('fos_elastica.index.app.school');
$searchQuery=new QueryString();
$searchQuery->setParam('query',$needle);
$searchQuery->setDefaultOperator('OR');
$searchQuery->setParam('fields',array('name','urlFriendly'));
$results=$index->search($searchQuery,10)->getResults();
我对 elasticsearch 和 FOSElastica 还很陌生, 我想获取代表学校名称的映射字段的相关结果。
我的配置:
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
app:
settings:
index:
analysis:
analyzer:
czech :
tokenizer: standard
filter : [czech_stop, czech_stemmer ,lowercase, asciifolding]
filter:
czech_stop:
type: stop
stopwords: _czech_
czech_stemmer:
type: stemmer
languague: czech
types:
school:
mappings:
name:
type: string
analyzer : czech
boost : 10
persistence:
driver: orm
model: Yearbook\SUBundle\Entity\School
provider: ~
listener:
immediate: ~
finder: ~
名称字段中存储的是学校名称。我使用命令行 fos:elastica:search school "Hi"
得到零结果,但是搜索整个单词工作正常 fos:elastica:search school "High"
我也试过不同的方法来在控制器中获得结果,但是 none 它起作用了。我认为问题可能出在配置文件中。
没有发现相关问题。 谢谢大家的回复
找到解决方案,
通过将 custom_filter EdgeNGram 添加到 confing 文件:
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
app:
settings:
index:
analysis:
analyzer:
custom_search_analyzer :
type : custom
tokenizer: standard
filter : [czech_stop, czech_stemmer ,lowercase, asciifolding,standard]
custom_index_analyzer :
tokenizer: standard
type : custom
filter : [czech_stop, czech_stemmer ,lowercase, asciifolding,standard,custom_filter]
filter:
custom_filter:
type: edgeNGram
side: front
min_gram: 1
max_gram: 20
czech_stop:
type: stop
stopwords: _czech_
czech_stemmer:
type: stemmer
languague: czech
types:
school:
mappings:
name:
type: string
search_analyzer : custom_search_analyzer
index_analyzer : custom_index_analyzer
boost : 10
urlFriendly:
type: string
persistence:
driver: orm
model: Yearbook\SUBundle\Entity\School
provider: ~
listener:
immediate: ~
finder: ~
正在控制器中获取结果列表:
$needle=$request->request->get('needle');
$index =$this->container->get('fos_elastica.index.app.school');
$searchQuery=new QueryString();
$searchQuery->setParam('query',$needle);
$searchQuery->setDefaultOperator('OR');
$searchQuery->setParam('fields',array('name','urlFriendly'));
$results=$index->search($searchQuery,10)->getResults();