【问题标题】:Different result templates for indices instantsearch.js algolia索引 Instantsearch.js 算法的不同结果模板
【发布时间】:2018-10-09 02:26:36
【问题描述】:

我想为两个不同的索引使用两个不同的项目模板自定义我的 algolia 搜索结果,但我不知道该怎么做。我在文档中也找不到这方面的内容。

在这里你可以看到我现在是如何做到的。

        <script type="text/html" id="hit-template">
          <div class="hit">
            <div class="head">
              <span class="title">@{{{_highlightResult.title.value}}}</span>
              <span class="tag">@{{{_highlightResult.category.value}}}</span>
            </div>
            <div class="details">
              <span>@{{{ article_votes }}} @{{{ comment_votes }}} Points</span> &middot;
              <span>@{{{ username }}}</span> &middot;
              <span>@{{{ created_at }}}</span>
              <span class="domain">@{{{_highlightResult.link.value}}}</span>
            </div>
            <p class="comment-text">@{{{_highlightResult.body.value}}} 
           @{{{_highlightResult.description.value}}}</p>
          </div>
        </script>

    search.addWidget(
      instantsearch.widgets.hits({
        container: '#hits-container',
        templates: {
          empty: 'Sorry, there are no results.',
          // Here I need two item templates one for comments and one for articles
          item: document.getElementById('hit-template').innerHTML 
        },
        escapeHits: true,
        transformItems: items => items.map(item => item),
      })
    );

【问题讨论】:

    标签: templates algolia


    【解决方案1】:

    使用InstantSearch 显示来自多个索引的命中的推荐方法是每个索引有一个instantsearch() 实例。

    例如,在您的用例中,您将有一个 articlesinstantsearch 和一个 commentsinstantsearch,响应单个 searchBox 小部件。每个都有自己的hits 小部件。

    这是一个fiddle,显示来自多个索引的点击以获取灵感。

    【讨论】:

      猜你喜欢
      • 2018-01-12
      • 1970-01-01
      • 2014-06-22
      • 2012-08-19
      • 2018-10-17
      • 2017-10-07
      • 2021-06-15
      • 1970-01-01
      • 2018-02-17
      相关资源
      最近更新 更多