簡體   English   中英

使用FacetFilters進行Laravel Scout搜索?

[英]Laravel Scout Search with FacetFilters?

如您所知,在搜索方法之后使用where()語句使用numericFilter 我試圖用字符串過濾過濾我的搜索結果。

如何在搜索語句中使用Facet Filter?

我很樂意回答我自己的問題。 首先,很難找到任何有關Laravel Scout的文檔。 如果要使用字符串參數過濾搜索結果。 即使很難找到答案也是如此。 我逐行檢查了整個圖書館。最后,結果讓我感到自豪。

如果你想與過濾字符串參數你的結果,你需要回調函數設計到您的search()方法和there.Simply注入你FacetFilters,讓我們假設你有Posts說您正在使用Algolia模式,你必須輸入枚舉category的列它。 您可以使用以下代碼過濾博客搜索結果。

$post = Post::search($query, function ($algolia, $query, $options) use ($category){
    $new_options = [];
    if (!is_null($type)) {
        $new_options = ["facetFilters"=>"category_name:".$category];
    }
    return $algolia->search($query, array_merge($options,$new_options));
});

根據algolia文檔,您可以修改搜索參數,如下所示:

$results = Product::search($q)->with(
    [
        'facets' => ['*'],
        'facetFilters' => [$facetFilters],
    ]
)->paginate(24);

https://www.algolia.com/doc/framework-integration/laravel/searching/server-side-search/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM