C
C
chelkaz2017-04-17 17:09:22
elasticsearch
chelkaz, 2017-04-17 17:09:22

Search by part of the city or How to create an analyzer for cities?

I'm doing a city search.
The first field is name for example:
СНТ Москва
The second field is text in detail, for example:

Россия, Московская область, Орехово-Зуевский район, СНТ Москва

I make a request:
'query' => [
                            'query_string' => [
                                'query' => $q,
                                'boost' => 1,
                                'phrase_slop' => 2,
                                'fields' => [
                                    'name^3',
                                    'text^2',
                                ],
                                'default_operator' => 'and',
                            ]
                        ],
                        'sort' => [
                            '_score' => [
                                'order' => 'desc'
                            ]
                        ]

But if I enter only a part of the city of Mosk or Barnaul Kurg, then it does not give out anything.
And it gives out only by whole names:
Moscow or Barnaul Kurgan
If I put a request through asterisks - 'query' => '*'.$q.'*',
Then the sorting stops working and at the request of Moscow, in the first place, for example , the village of New Moscow , but simply Moscow is in 5-7th place.
And without asterisks in the query, 'query' => $q',Moscow is in the first place, as it should.
How to make a request, what would be searched for by part of the word and the most similar result would be the first in the search results?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2017-04-17
@dimonchik2013

'query' => $q.'*',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question