Closed redeemefy closed 5 years ago
Thanks for creating this issue, I am here to help you.
First question, you are using scout extended right?
I did ran composer require algolia/scout-extended
and
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
.
After that I php artisan scout:flush
and php artisan scout:import
.
Perfect. Now I need you to check if the record that haves the objectID App\Pattern::17
is the exacly the record with the id 17
in your database.
@diazgilberto This is super weird. Can you try add a dd($options);
on the line 135 of the file Laravel\Scout\Engines\AlgoliaEngine
and perform a search? And tell me the results of the dd
.
Laravel\Scout\src\Engines\AlgoliaEngine
instead?
Exacly.
Perfect. Now, remove the previous dd
. And on the line 135 replace the current line by: return dd($algolia->search($builder->query, $options));
. And tell the results.
Weird, "hits" => []
You need to put the exact same query that returned the The record that I get back has the user_id 3.
.
Because the screenshot you have posted, shows that algolia returns 0 records.
it is the same query. The search term is test
Perfect. Algolia is returning 0 results from that query. As you can see, hits
are empty.
Just to make sure, please use this code on your controller:
$patterns = Pattern::search('test')->where('user_id', '=', 1)->get();
dd($patterns);
And confirm that you really got a pattern with the user_id === 3.
In algolia the user_id
is 3
. What I search for the term test
, I'm using the user_id
1 expecting to get nothing from algolia. "hits" => []
is exactly what I'm expecting.
Exacly, but you told me that using this code, The result of the $patterns
is a model with the user_id == 3 right?
$patterns = Pattern::search('test')->where('user_id', '=', 1)->get();
dd($patterns);
Collection is empty as expected utilizing your snippet and my code.
$patterns = Pattern::search('test')->where('user_id', '=', 1)->get();
// or
$patterns = Pattern::search('test')->where('user_id', '=', Auth::user()->id)->get();
dd($patterns);
The problem should be when I render the view. Seems like vue-instantsearch
is performing a search on render.
@extends('layout._base')
@section('content')
<ais-index
app-id="{{ config('scout.algolia.id') }}"
api-key="{{ config('scout.algolia.public') }}"
index-name="patterns"
id="app"
query="{{ request('q') }}"
>
<div class="row">
<div class="col">
<ais-results>
<template slot-scope="{ result }">
<div class="card">
<div class="card-header">
<a :href="result.path">
<ais-highlight :result="result" attribute-name="name"></ais-highlight>
</a>
</div>
<div class="card-body">
<ais-highlight :result="result" attribute-name="description"></ais-highlight>
</div>
</div>
<p>
</p>
</template>
</ais-results>
</div>
<div class="col-3">
<div class="card mb-5">
<div class="card-header font-weight-bold">Search</div>
<div class="card-body">
<ais-input placeholder="Search patterns..." class="form-control" :autofocus="true"></ais-input>
</div>
</div>
<div class="card">
<div class="card-header">
Filter By Category
</div>
<div class="card-body">
<ais-refinement-list attribute-name="category"></ais-refinement-list>
</div>
</div>
</div>
</div>
</ais-index>
@endsection
Ahah. You have been searching with vue-instantsearch
this whole time. Since you are using client-side search, you just have to inspect your network to debug your problem.
Otherwise you can address this issue with our vue-instasearch
team : https://github.com/algolia/vue-instantsearch.
Well, my initial search is server side. Even though the server side search returns the correct object, looks like vue-instantsearch
is querying again when I pass uery="{{ request('q') }}"
.
Closing since scout-extended
is behaving as expected and the problem resides somewhere else.
Thanks Nuno!!!
Thanks! Since you are doing client side search you don't need the server side search.
Don't hesitate to check the docs of vue instasearch: https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/vue.
Be sure to stay tuned to my twitter account @enunomaduro for more information about this package. Are you enjoying this package? Please tweet the link https://github.com/algolia/scout-extended and tells us your favourite feature! 🚀
This is next level support! Thanks @nunomaduro for your work!
I'm trying to integrate algolia in a personal project. The table I'm indexing is the
patterns
table that has theuser_id
asFK
and is included as one of the fileds I upload to algolia.If I dump the
user_id
I get1
. Intentionally I'm searching for something that doesn't belong to that user expecting to get nothing from algoia but I still get the record back. The record that I get back has theuser_id
3.I'm not sure if I'm missing some setting in the algolia dashboard or the code is missing something.
I'm searching for the word
test
and is the only record that contains that word.