Thanks, #-Link-Snipped-# . Since posting the thread, I've learned more about ES. Right now, I'm in the 'fine-tuning' phase for @mention suggestions.
Let's say a user starts typing a name. Ideally, we should return multiple matches that have the starting characters, but these matches have to be relevant. I'm therefor experimenting with
'edge-ngram' tokenizer.
Here's the query I posted on a forum -
Here's how my current settings look like -
protected $settings = [
'analysis' => [
'filter' => [
'autocomplete_filter' => [
'type' => 'edge_ngram',
'min_gram' => 2,
'max_gram' => 12,
],
],
'analyzer' => [
'autocomplete' => [
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => ['lowercase', 'autocomplete_filter']
]
]
]
];
and
public function buildQueryPayload()
{
return [
'must' => [
'multi_match' => [
'query' => $this->builder->query,
'fields' => ['first_name', 'last_name', 'name^2'],
'type' => 'phrase_prefix'
]
]
];
}
This is my best try so far; but I'm not happy with the results. I've the following in my User model -
public function toSearchableArray() {
return [
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'name' => $this->first_name . ' ' . $this->last_name
];
}
I'm thinking of adding an extra field from my database to the index called last_activity_at and then sort the suggested users according to those who've the most recent last_activity.
Can someone suggest if I need to make changes to my filter, analyzer or the query? The end result I want to achieve is -
User types: @Joh . The system should return
- 'John Doe' [most recently active]
- 'John Doe' [second most recently active]
- 'Johan Kent'
- 'Johar Woe'
... like that. If the last_activity_at field is null, ES should only match based upon the closest search.
Would welcome suggestions.