Getting cities and countries from places widget in instantsearch.js

I’m using the places widget for my instantsearch implementation. Relevant source code shared below.

It works as expected, but only lets me search for cities. I would like to search for both cities and countries, but nothing else. How can I do this?

I did find this issue from 2016. It has some suggested solutions combining two autocompletes into one. I haven’t been able to make this work with my code though. It seems the suggestions are quite old and don’t apply to using the (most recent) instantsearch version with the places widget.

Any up-to-date suggestions?

import algoliaPlaces from "places.js";
import instantsearch from "instantsearch.js";
import { configure, searchBox, infiniteHits, places } from "instantsearch.js/es/widgets";

let placesWidget = places({
  placesReference: algoliaPlaces, // refering to places.js
  container: "#search-input",
  type: "city" // "country" works too, but a combination does not

const search = instantsearch({ … }); // typical setup

  placesWidget // adding the widget

Apologies for the late response…

It seems you were able to make it work like this @marc:

Just posting here for anyone else looking on this forum.

Thanks for sharing!

1 Like