Reputation: 91
I'm quite new to Elastic Search, maybe you can help me:
So, I have symfony and Elasticsearch (FOSElasticaBundle).
If I'm searching for a full word in title - everything is working (for example if I type "hello", I will get results where "hello" world is).
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.
my 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:
my php function
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
);
}
Can anyone help ?
Upvotes: 0
Views: 1451
Reputation: 91
So I just forget to add setParam for Fields...
$searchQuery->setParam('fields', array( 'Author', 'title', 'isbn', ));
Now Everything is working!
Upvotes: 1