1

Is there any way of searching both entries and products at the same time? Wanting a single search on the site which will return all entries and products containing the searched for phrase.

Looked at combining the results from craft.entries.search() and craft.products.search() but this stops us from using pagination which we would like to have. Anybody got a solution or suggestions?

Would prefer not to split into 2 search pages if possible. Thank you.

1

Unfortunately you would need to do 2 element query searches and combine the results on the front end.

Most developers tend to go for https://algolia.com when they want fast advanced search, including searching across elements.

Probably easiest to get started by searching for an Algolia plugin in the plugin store. I only know https://github.com/Rias500/craft-scout for Craft 3 at the moment.

  • Thank you for your response Luke. Would be nice to have a built in function for this in the future if possible. Combining on the front end seems like it would cause pagination issues. Now that I know there is nothing available in core though I might try to throw together a plugin to achieve this. Trying to avoid adding any additional monthly costs such as Algolia for this client. Thanks again. – Matt Shearing Dec 7 '18 at 11:58
1

Ended up creating a custom plugin to achieve this functionality. Also added some custom pagination logic. Set up a gist showing the variable and service files of the plugin as well as an example twig template to output the results.

https://gist.github.com/matt-adigital/e79b2fd2e14327b3f306a907f4e7e02e

All working well but it would be great if this was in core or just a little easier to implement. If we could leverage Crafts pagination for our own usage by passing in a dataset instead of being confined to the craft\elements\db\ElementQueryInterface object, then this would be a big help.

Another option could be to allow craft\elements\db\ElementQuery to accept multiple elementTypes or a null value, tried to submit with null but it is in fact required to be a string.

Hopefully anyone else who wants to use this functionality without going down the Algolia route will find this helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.