wintercms / wn-search-plugin

Enables full-text search capabilities in Winter.
MIT License
7 stars 2 forks source link

"Call to undefined method Winter\Storm\Halcyon\Builder::where()" error #3

Closed steva82 closed 4 months ago

steva82 commented 1 year ago

Hi, I have this situation:

I have created a custom Model by Builder and it is accurately searchable (adding the component to the layout).

Then, in the component settings, I have checked "Static Page" handler in order to search my static pages by title, but I have this error:

"Call to undefined method Winter\Storm\Halcyon\Builder::where()" on line 790 of /Applications/MAMP/htdocs/cds/vendor/winter/storm/src/Halcyon/Builder.php

Screenshot

I have tried to debug inside the file "/plugins/winter/search/components/Search.php" and the problem seems to be here (line 193):

if (is_callable($class)) { $results = $class()->doSearch($query)->paginate($this->property('perPage', 20), 'page', ($handlerPage === $id) ? $page : 1); } else { $results = $class->doSearch($query)->paginate($this->property('perPage', 20), 'page', ($handlerPage === $id) ? $page : 1); }

What could I do to search Static Pages? Thanks in advanced.

Ste

steva82 commented 1 year ago

Hi, I have tried a more simple way in order to use the "Search" plugin:

  1. I have installed a new clean Winter instance by composer
  2. I have added the "Search" plugin
  3. I have created a new CMS page
  4. I have added the "Search" component to the default layout and I selected "CMS Pages" as Search handler
  5. If a open the website ad try to search a CMS page there is the same error

"Call to undefined method Winter\Storm\Halcyon\Builder::where()" on line 790 of /Applications/MAMP/htdocs/canc/vendor/winter/storm/src/Halcyon/Builder.php

Reading the documentation, there are no tasks to do related to CMS Pages (Static Pages and Blog, too).

I discovered Artisan has some specific commands related to Search and I executed: php artisan search:import "\Cms\Classes\Page" but even in this case the error appears.

Any suggestion? Thanks again.

Screenshot1

bennothommo commented 1 year ago

The Search plugin is still in active development, so there's probably some bugs left in it, like this one.

The issue is simply that Halcyon doesn't have a query builder quite like the normal Eloquent query builder, because it's file based and not using a database.

You should have a more thorough backtrace of the issue either in the Event logs in the Backend, or in the storage/logs/system.log file. If you can get us a backtrace, it might give a better indication of where to look further into this.

steva82 commented 1 year ago

Hi, thank you for your answer.

This is the what i found in the Event log:

BadMethodCallException: Call to undefined method Winter\Storm\Halcyon\Builder::where() in /Applications/MAMP/htdocs/canc/vendor/winter/storm/src/Halcyon/Builder.php:790 Stack trace:

0 /Applications/MAMP/htdocs/canc/vendor/laravel/scout/src/Engines/DatabaseEngine.php(201): Winter\Storm\Halcyon\Builder->__call('where', Array)

1 /Applications/MAMP/htdocs/canc/vendor/laravel/scout/src/Engines/DatabaseEngine.php(145): Laravel\Scout\Engines\DatabaseEngine->initializeSearchQuery(Object(Laravel\Scout\Builder), Array, Array, Array)

2 /Applications/MAMP/htdocs/canc/vendor/laravel/scout/src/Engines/DatabaseEngine.php(74): Laravel\Scout\Engines\DatabaseEngine->buildSearchQuery(Object(Laravel\Scout\Builder))

3 /Applications/MAMP/htdocs/canc/vendor/laravel/scout/src/Builder.php(391): Laravel\Scout\Engines\DatabaseEngine->paginate(Object(Laravel\Scout\Builder), '3', 1)

4 /Applications/MAMP/htdocs/canc/plugins/winter/search/components/Search.php(195): Laravel\Scout\Builder->paginate('3', 'page', 1)

5 /Applications/MAMP/htdocs/canc/modules/cms/Classes/ComponentBase.php(194): Winter\Search\Components\Search->onSearch()

6 /Applications/MAMP/htdocs/canc/modules/cms/Classes/Controller.php(823): Cms\Classes\ComponentBase->runAjaxHandler('onSearch')

7 /Applications/MAMP/htdocs/canc/modules/cms/Classes/Controller.php(714): Cms\Classes\Controller->runAjaxHandler('search::onSearc...')

8 /Applications/MAMP/htdocs/canc/modules/cms/Classes/Controller.php(371): Cms\Classes\Controller->execAjaxHandlers()

9 /Applications/MAMP/htdocs/canc/modules/cms/Classes/Controller.php(217): Cms\Classes\Controller->runPage(Object(Cms\Classes\Page))

10 /Applications/MAMP/htdocs/canc/modules/cms/Classes/CmsController.php(50): Cms\Classes\Controller->run('pagina-di-prova')

11 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Cms\Classes\CmsController->run('pagina-di-prova')

12 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\Routing\Controller->callAction('run', Array)

13 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Routing/Route.php(260): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Cms\Classes\CmsController), 'run')

14 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route->runController()

15 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(798): Illuminate\Routing\Route->run()

16 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))

17 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

18 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))

19 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

20 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))

21 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

22 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest(Object(Illuminate\Http\Request), Object(Illuminate\Session\Store), Object(Closure))

23 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))

24 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

25 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))

26 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

27 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))

28 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

29 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(799): Illuminate\Pipeline\Pipeline->then(Object(Closure))

30 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(776): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))

31 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Routing/Router.php(740): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))

32 /Applications/MAMP/htdocs/canc/vendor/winter/storm/src/Router/CoreRouter.php(20): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))

33 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(190): Winter\Storm\Router\CoreRouter->dispatch(Object(Illuminate\Http\Request))

34 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http{closure}(Object(Illuminate\Http\Request))

35 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

36 /Applications/MAMP/htdocs/canc/vendor/winter/storm/src/Foundation/Http/Middleware/CheckForMaintenanceMode.php(25): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle(Object(Illuminate\Http\Request), Object(Closure))

37 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Winter\Storm\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))

38 /Applications/MAMP/htdocs/canc/vendor/winter/storm/src/Foundation/Http/Middleware/CheckForTrustedProxies.php(56): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

39 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Winter\Storm\Foundation\Http\Middleware\CheckForTrustedProxies->handle(Object(Illuminate\Http\Request), Object(Closure))

40 /Applications/MAMP/htdocs/canc/vendor/winter/storm/src/Http/Middleware/TrustHosts.php(46): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

41 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Winter\Storm\Http\Middleware\TrustHosts->handle(Object(Illuminate\Http\Request), Object(Closure))

42 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

43 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\Pipeline\Pipeline->then(Object(Closure))

44 /Applications/MAMP/htdocs/canc/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(134): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))

45 /Applications/MAMP/htdocs/canc/index.php(43): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))

46 {main}

Thank you for your help, it would be very useful this plugin.

bennothommo commented 1 year ago

Thanks @steva82 - that helps a lot!

I can't promise any timeframes, but we will look into this.

steva82 commented 1 year ago

Hi @bennothommo , any news? Thanks.

spanjaan commented 1 year ago

Hi @bennothommo , i found also same issue. when you solve this issue?

Thank you.

bennothommo commented 1 year ago

@spanjaan @steva82 I have done some preliminary work on this in #4. Would you mind testing this and letting me know if you encounter any issues? You can either swap out the version in Composer:

"winter/wn-search-plugin": "dev-fix/halcyon-search"

Or just apply the changes directly to the modified files.

steva82 commented 1 year ago

Hi @bennothommo , it seems to work, thanks! I hope @spanjaan can confirm...

Can you could tell us how and when us your custom Artisan commands? In the "console" folder there are 4 scripts and , maybe, 2 of them are empty. Thanks again.

bennothommo commented 1 year ago

@steva82 the console commands are mainly used when you use a separate index service for model records, like ElasticSearch, Algolia or Meilisearch. They allow you to manipulate and pre-index all model records in this external service.

If you use the default database search in the Search plugin, they don't need to be used.

steva82 commented 1 year ago

Hi @bennothommo , sorry for the delay. I am trying to improve my new website with your plugin.

I prepared my model (Feed.php) with :

I edit my Plugin.php with the registerSearchHandlers method.

Now, I have some difficulties to custom the search field and the "results" page. I mean, you have a single component related to the search form and I copied that html code (default.htm and form.htm) in my template:

{{ form_ajax(__SELF__ ~ '::onSearch') }}
    <div class="search-input">
     <input type="text" name="query" class="search-control" placeholder="{{ 'Enter your search query'|trans }}" />
        </div>
       <div class="search-actions">
     <input type="submit" class="search-submit" value="{{ 'Search'|trans }}">
         </div>
  {{ form_close() }}

but I need to see the results in a different page. How can I edit the form_ajax parameters?

Thank you.

bennothommo commented 4 months ago

@steva82 my sincere apologies for letting this one fall through the cracks.

I take it to mean that you would like the results of the search to appear on a new page as opposed to being loaded via AJAX into the current page? Right now, it's not possible, but it could theoretically be done using external property values to the Search component. I will make a note to allow this in a future version.

steva82 commented 4 months ago

I take it to mean that you would like the results of the search to appear on a new page as opposed to being loaded via AJAX into the current page?

Yes, correct.

I will make a note to allow this in a future version.

I hope it will be possible, I really appreciate your effort and help, thank you.