如果查询为空白,如何将Algolia设置为不返回任何结果Laravel&Vue Instant Search

易卜拉欣·哈杰(Ibrahim Hajjaj)|

嘿,我在新的Laravel项目中使用了Algolia,但是我发现Algolia显示了我所有具有“ Titel-description”的数据。

我只想在搜索框中输入内容时显示结果。

我的HTML代码

<div id="app">
    <!-- Components will go here -->
    <ais-index app-id="{{ config('scout.algolia.id') }}"
               api-key="{{ env('ALGOLIA_SEARCH') }}"
               index-name="posts">

        <ais-search-box placeholder="Find products..."></ais-search-box>


        <ais-results>
            <template slot-scope="{ result }">
                <div>

                    <h4>@{{ result.progName }}</h4>
                    <ul>
                        <li>@{{ result.description }}</li>
                    </ul>
                </div>
            </template>
        </ais-results>

    </ais-index>
</div>

邮政模型

  <?php

  namespace App;

  use Illuminate\Database\Eloquent\Model;
  use Laravel\Scout\Searchable;

  class Post extends Model
     {
        //
         use Searchable;

     }
哈罗恩·维亚内(Haroen Viaene)

您应该替换ais-results为根据查询将其隐藏的组件。该组件看起来像这样:

<!-- MyResults.vue -->
<template>
  <div v-if="query.length > 0">
    <slot name="header"></slot>
    <slot name="default" v-for="(result, index) in results" :result="result" :index="index">
      {{index}}. Result 'objectID': {{ result.objectID }}
    </slot>
    <slot name="footer"></slot>
  </div>
</template>

<script>
import { Component } from 'vue-instantsearch';

export default {
  mixins: [Component],
  computed: {
    query() {
      return this.searchStore.query;
    },
    results() {
      return this.searchStore.results;
    },
  },
};
</script>

然后将您的用法替换为ais-results您自己的my-results组件:

<div id="app">
    <!-- Components will go here -->
    <ais-index app-id="{{ config('scout.algolia.id') }}"
               api-key="{{ env('ALGOLIA_SEARCH') }}"
               index-name="posts">

        <ais-search-box placeholder="Find products..."></ais-search-box>


        <my-results>
            <template slot-scope="{ result }">
                <div>

                    <h4>@{{ result.progName }}</h4>
                    <ul>
                        <li>@{{ result.description }}</li>
                    </ul>
                </div>
            </template>
        </my-results>

    </ais-index>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如果查询为空,如何将Algolia设置为不返回任何结果?

为JodaTime Instant添加几天

如果key为1,array_search不返回结果

如何实现安全的全局 Instant?

如何从Instant转换为LocalDate

如何将LocalDate转换为Instant?

如何将Instant转换为LocalTime?

Android SearchManager 在 Instant App 中为 null

Instant App 因多个查询参数而崩溃

将Instant格式化为String

Instant Apps:如何添加外部库?

我如何使用Powermock存根Instant对象

如何从Instant.now()获取DayOfWeek

Hibernate Search不返回任何结果

将时区字符串日期解析为 Java 的 Instant

将非ISO 8601解析为ISO_INSTANT

如何将Crashlytics与Android Instant Apps集成?

Java:如何将Instant类型转换为XMLGregorianCalendar类型?

将 Instant 转换为 OffsetDateTime 然后 Instant.parse() 在 OffsetDateTime 上导致 DateTimeParseException 零秒的情况

将ZonedDateTime和Instant设置为不同的字符串格式

如何将 "uuuu'-'MM'-'dd'T'HH':'mm':'ss;FFFFFFFFo<Z+HHmm>" 解析为 Instant?

不兼容的类型:long 不能转换为 Instant

angular $translate.instant 返回对象而不是字符串

ngx-translate .instant返回键而不是值

带有枚举字段的Hibernate Search / Lucene范围查询不返回任何结果

带有“日期= YYYY-MM-DD”的GAE Search API查询不返回任何结果

使用特定模式将Instant格式化为String

micronaut将请求参数转换为Instant或ZonedDateTime

将Java Instant转换为.Net DateTime.Ticks