Search function not returning anything.
Created 4 years ago by gonziisI 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.
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.
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.
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()
?
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? 😄
Cool - working then?
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
What's your version?
Everything is working for me after php artisan streams:index
, but also additional question - does search function limit the results to 15 or something? Because it doesn't give me pagination even if I paginate. {% set posts = query.search(q).orderBy("publish_at","desc").paginate() %}
I get 15 results, but no pagination buttons at the bottom. If I take out the search function, I get the pagination element at the bottom with 60+ pages.
<div class="pagination">
{{posts.appends({"q":q}).render()|raw}}
</div>
This is the pagination code
@gonziis check this out for pagination links: https://github.com/anomalylabs/posts-module/blob/2.4/resources/views/posts/index.twig#L11
.render()
and .links()
will both do it (per Laravel's paginator object).
I THINK.. limit changes per page? Maybe it's the param on the .paginate($perPage)
I can't quite recall. It's defaulted to your settings value.
I think this is not the case. If I make .paginate(5)
, it still shows 5 items, but no pagination, but .paginate()
shows 15 items (default), still not pagination elements at the bottom. If I take out the .search()
, the pagination elements suddenly work. I think this has something to do with .search()
and .paginate()
not working together well?
What is the object you get if you dd
the result of search AND paginate?
Dig around in those objects a bit. What's the total? Do you know you have multiple pages of pagination? You should be able to get some answers by looking into the data that's dumped there.
Yes, I know there should be multiple pages. If there would only be 15 items total, I would get 3 pages with .paginate(5)
, but I still get a single page with just 5 items.
{% set posts = query.search(q).orderBy("publish_at","desc").paginate() %}
{{dd(posts)}}
Result:
Paginator {#16429 â–¼
#hasMore: false
#items: PostCollection {#16584 â–¼
#items: array:15 [â–¶]
}
#perPage: 15
#currentPage: 1
#path: "/"
#query: []
#fragment: null
#pageName: "page"
}
{% set posts = query.search(q).orderBy("publish_at","desc").paginate(5) %}
{{dd(posts)}}
Result:
Paginator {#14894 â–¼
#hasMore: false
#items: PostCollection {#14949 â–¼
#items: array:5 [â–¶]
}
#perPage: 5
#currentPage: 1
#path: "/"
#query: []
#fragment: null
#pageName: "page"
}
{% set posts = query.orderBy("publish_at","desc").paginate() %}
{{dd(posts)}}
Gives me this though:
LengthAwarePaginator {#14098 â–¼
#total: 690
#lastPage: 46
#items: PostCollection {#14074 â–¼
#items: array:15 [â–¶]
}
#perPage: 15
#currentPage: 1
#path: "http://sub.domain.lv/search"
#query: []
#fragment: null
#pageName: "page"
}
Also tested with manual search parameter just entering
search("kp")
, also 0 results, but existing results on my local machine.