1

Is it possible to use multiple fields for searchkick's autocomplete feature? It seems to be searching only the first field specified.

For example, for a person with the first_name "Foo" and last_name "Bar"

Person.search("Fo", fields: [first_name: :text_start, last_name: :text_start]) - returns result

Person.search("Ba", fields: [first_name: :text_start, last_name: :text_start]) - no results found

Musannif Zahir
  • 3,001
  • 1
  • 21
  • 31

1 Answers1

2

I'm not too familiar with it, but I think so. From the docs:

https://github.com/ankane/searchkick#autocomplete

City.search "san fr", fields: [{name: :text_start}]

That seems to imply that you can give an Array of Hashes. When you don't specify the squiggly brackets like you do that will make one Array with one Hash.

Brian Underwood
  • 10,746
  • 1
  • 22
  • 34
  • good catch but I'm having the same issue with `Person.search("Ba", fields: [{first_name: :text_start}, {last_name: :text_start}])` – Musannif Zahir Sep 16 '15 at 08:43
  • 1
    Hrmm, I'm not sure. The docs seem to indicate that something like that would work. Do you have the `word_start` specified in the `searchkick` call? This is what it shows for one field: `searchkick word_start: [:name]` – Brian Underwood Sep 16 '15 at 08:49
  • Thanks, that was it. I had removed `last_name` from the `searchkick` call during debugging and it was ultimately the missing `{}` that caused the issue. – Musannif Zahir Sep 16 '15 at 08:51
  • Yay, nice. Good luck! ;) – Brian Underwood Sep 16 '15 at 08:53