阿尔及利亚-具有多个搜索框的即时搜索

我有以下HTML(简体)

<form action="#" method="post">
  <input type="text" class="form-control" name="keyWord" id="keyWord" placeholder="key Word">
  <input type="text" id="town" class="form-control" name="town"  placeholder="town">
  <button id="form_button" type="submit" class=""><i class="icon-search"></i></button>
</form>

我有一个索引列表,具有标题,城镇,描述等属性

对于第一个文本输入(#keyWork),我希望第二个输入(#town)的可搜索属性为“ title”,“ description”和“ town”

我不知道如何在不同属性内搜索2个搜索框,并且在任何地方都找不到示例。我试图创建一个自定义窗口小部件,但是我不知道如何指定自定义属性,而不是重写整个查询。

这是到目前为止我所取得的成就的一些代码示例

const searchClient = algoliasearch( /* keys */ );
const search = instantsearch({
  indexName: 'my_index_name',searchClient: searchClient,});

const renderCustomTown = (renderOptions,isFirstRendering) => {

  const {
    items,currentRefinement,refine,clearMapRefinement,widgetParams,} = renderOptions;

  element.addEventListener('input',event => {
    refine(event.target.value)
  }); /* Specify attributes here ? */
}

// Create the custom widget
const searchTown = instantsearch.connectors.connectSearchBox(
  renderCustomTown
);

search.addWidget(
  searchTown({
    element: document.querySelector('#town'),})
);

谢谢您的帮助

zhoubng 回答:阿尔及利亚-具有多个搜索框的即时搜索

有点晚了,我忘了回答我的问题

使用algolia小部件无法实现我想要归档的内容,因此我使用了另一个API方法: https://www.algolia.com/doc/api-reference/api-methods/search/

本文链接:https://www.f2er.com/3165621.html

大家都在问