gonziis - 4 months ago

I have this weird problem after migrating my project to a live server. I have identical code (I think so) on both sides, dumped my DB so it's the same there. But the search page is not working on my live page.

{% set q = request_get("q") %}
{% set query = entries("posts", "posts") %}
{% set query = query.search(q) %}
{% set posts = query.orderBy("publish_at","desc").paginate(0) %}
{{dd(query.paginate())}}

nor posts, nor dump is returning anything. But if I take out the search function and just do a pagination with sorting, the results are there, so the posts are actually there, the search function alone is somehow not returning anything. Do you have any clue? I can't think of any reasons yet of this happening.

gonziis - 4 months ago

Also tested with manual search parameter just entering search("kp"), also 0 results, but existing results on my local machine.

ryanthompson - 4 months ago

The search index uses SQLite so it's physically in your application (somewhere in storage directory). To rebuild your search index use php artisan streams:index and all searchable streams will rebuild their index.

mitch - 4 months ago

Did this work for you? I recently tried adding search capabilities, but when I do php artisan streams:index it gives me the error: Call to a member function searchable() on null. If I dd($models) in SearchableScope->extend(), I see the model in there with searchable: true. But $models->filter->shouldBeSearchable() is null.

ryanthompson - 4 months ago

Yes I get the following:

configuration.configuration is not searchable.
dashboard.dashboards is not searchable.
dashboard.widgets is not searchable.
files.disks is not searchable.
files.folders is not searchable.
Imported [Anomaly\FilesModule\File\FileModel] models up to ID: 8
All [Anomaly\FilesModule\File\FileModel] records have been imported.
navigation.menus is not searchable.
navigation.links is not searchable.
Imported [Anomaly\PagesModule\Page\PageModel] models up to ID: 33
All [Anomaly\PagesModule\Page\PageModel] records have been imported.
pages.types is not searchable.
posts.categories is not searchable.
Imported [Anomaly\PostsModule\Post\PostModel] models up to ID: 124
All [Anomaly\PostsModule\Post\PostModel] records have been imported.
posts.types is not searchable.
preferences.preferences is not searchable.
redirects.redirects is not searchable.
settings.settings is not searchable.
Imported [Anomaly\UsersModule\User\UserModel] models up to ID: 2
All [Anomaly\UsersModule\User\UserModel] records have been imported.
users.roles is not searchable.
page_link_type.pages is not searchable.
url_link_type.urls is not searchable.
files.images is not searchable.
files.documents is not searchable.
pages.default_pages is not searchable.
posts.default_posts is not searchable.
forms.forms is not searchable.
forms.notifications is not searchable.
grid.content is not searchable.
grid.html is not searchable.
files.publications is not searchable.
forms.request_reserve is not searchable.
forms.volunteer is not searchable.

Which model is failing for you?

What is $models->filter->shouldBeSearchable()?

mitch - 4 months ago

configuration.configuration is not searchable. dashboard.dashboards is not searchable. dashboard.widgets is not searchable. files.disks is not searchable. files.folders is not searchable. null $models->filter->shouldBeSearchable() returns null as well, that's the piece of code it's using to filter out non-searchable models in Laravel\Scout\SearchableScope.

EDIT: How do I format multiple lines as code on this forum? :)

ryanthompson - 4 months ago

@mitch can you try using php artisan scout:import 'YourModel' and see if that works? Is it a streams entry model?

If it's a stream (assuming, being Pyro) you can try php artisan streams:import $namespace $slug as well.

mitch - 4 months ago

In SearchableScope.php line 36ish: Call to a member function searchable() on null Which is $models->filter->shouldBeSearchable()->searchable() in vendor/laravel/scout/src/searchableScope.php: 36ish.

mitch - 4 months ago

Also, command streams:import is not defined for me.

ryanthompson - 4 months ago

@mitch what version are you on? Perhaps you are a bit out of date and that is causing issues?

mitch - 4 months ago

Ok, so searchable is actually false for my Model, I must have been looking at the wrong module before.. I've added use Searchable, toSearchableArray.

ryanthompson - 4 months ago

Cool - working then?

mitch - 4 months ago

Nope, I've had those in my model the whole time. Is there anything else I'm missing from it?

ryanthompson - 4 months ago

Make sure your model is bound to the generated one is all I can think of. The system might not be getting your extended model.

Like this: https://github.com/anomalylabs/pages-module/blob/2.4/src/PagesModuleServiceProvider.php#L47

mitch - 4 months ago

Yep, that's in there. So this is happening on the FilesModel as well, which I haven't touched anything on. If I knew of another searchable model I could try it on, I'd bet it'd happen with that one, too.

ryanthompson - 4 months ago

What's your version?