我想定制我的算法搜索结果两个不同的项目模板两个不同的索引,但我不知道如何做到这一点。我在纪录片里也找不到这方面的东西。
在这里你可以看到我现在是怎么做到的。
<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> ·
<span>@{{{ username }}}</span> ·
<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),
})
);发布于 2018-10-08 18:26:36
使用InstantSearch显示来自多个索引的点击的推荐方法是每个索引有一个instantsearch()实例。
例如,在您的用例中,您将有一个articles实例化搜索和一个comments实例化搜索,响应于单个searchBox小部件。每个小部件都有自己的hits小部件。
下面是一个小提琴,它显示来自多个索引的点击以获取灵感。
https://stackoverflow.com/questions/52686274
复制相似问题