New This Week: Site Search

The big news this week is that I have – finally – added a Search facility to the site. There were a few other improvements and changes that went into this release, but this was the biggy.

I’m going to be completely honest here: I’m using my third choice for the search implementation.

It’s taken me ages to do this because I wanted to use Elasticsearch. I’ve got previous experience with Elasticsearch and it is, honestly, awesome.

However, deploying Elasticsearch isn’t straightforward. There are some security implications (as is to be expected), and as ever with a “free” solution, a bunch of admin tasks to add to my plate.

I wasn’t overly bothered about any of this though. What bothered me was that whenever I ran my Ansible role to deploy the Elasticsearch stack, the whole thing fell over. Fortunately this was in dev, and I could revert to my VM snapshot, try a few tweaks, and try to deploy again. After a bunch of failed attempts I got really paranoid about trying this against my production box, and so, site search got put onto the backlog.

On a weekly basis I would get at least one, often several emails asking why there was no site search facility. It hurt to receive those emails. Each one served as a reminder of my failure to implement.

Now, for those who don’t know, I am currently revamping the entire back end from the current approach (all Symfony / Twig) to be Symfony as an API, and React on the front end. It’s going ok, but slower than I envisaged. The main reason for this is my prioritisation – I choose to prioritise recording / editing / writing up new content over improving the site itself.

With this in mind, I’d love to hear your opinion on this. Would you prefer I continue prioritising new video content, or switch focus for a few weeks to improve the site and get the new version launched?

Anyway, with deploying Elasticsearch proving problematic, as mentioned I had put search onto the backlog.

Then quite recently I was browsing Symfony.com and noticed they use Algolia. Given that the good people of SensioLabs are likely to know a thing or two about running search for traffic (at least) an order of magnitude greater than what CodeReviewVideos needs to handle, I figured I would check Algolia out as a potential solution.

My first stop was to Packagist. Sure enough, there’s a Bundle – AlgoliaSearchBundle – that pretty much gets you up and running with very little effort. I just needed to add the bundle, enable it, and annotate the entities I wanted to be searchable.

Here I hit upon a problem.

To separate between Free and Members Only episodes, I have used Single Table Inheritance.

This works really well. However, Algolia would only allow me to create an index per entity. From Algolia’s point of view, a Free tutorial is different to a Members Only tutorial, and therefore my search results were… weird.

I thought I could be smart about it and merge the two, but there was no apparent way to access the ‘score’ from the returned array of results, so merging would either be extremely naive or very flawed.

That led to me ditching Algolia.

I would say however, if you have a setup without my interesting design choices (ahem) then Algolia’s results were great. Well worth a look. Though, potentially, a little pricey.

Feeling a little dejected, but not yet ready to give up, I remembered back to days gone by. Long before I had ever heard of Elasticsearch or Apache Solr, I would simply use MySQL’s FULLTEXT indexing to offer a search facility.

With a little coaxing (and help from this StackOverflow post) I had a working solution up and running in an embarrassingly short amount of time. I say I was embarrassed because if I had gone with this solution originally, instead of trying to be “perfect” then I could have had this online shortly after CodeReviewVideos launched over two years ago.

BRB, shaking the Shame Bell.

Anyway, it’s there now. So that’s good.

The results are not quite as refined as if I were using a more robust solution, but it’s better than nothing. Hopefully you agree.

Battle of the Admin Bundles

Infrequently I get asked if I have any video content or tutorials for Sonata Admin Bundle.

The answer as it stands currently is: no.

The reasoning for this is that the last time I tried Sonata Admin Bundle I found it overly complex for my needs. I could use Symfony’s CRUD generators to get most of the functionality I needed for a simple back end, without the overhead of an extra bundle, and learning all about that bundle to boot.

That said, the last time I tried Sonata Admin Bundle was at least two years ago. Times may have changed.

For a recent video series I did want a ready made Admin panel. I’d heard a bunch of good things about EasyAdminBundle, and have been super impressed with it so far. A huge thanks to Javier Eguiluz (in general) and all the contributors for this one, as it is great.

I’m curious though. Would a Sonata Admin Bundle tutorial series be something you’d like to see? I’m happy to do a course on this if there is enough demand. I would really appreciate it if you could please hit reply and let me know your thoughts.

Video Update

Aside from the tweaks and new features, this week saw 3 new videos added to the site.

https://codereviewvideos.com/course/let-s-build-a-wallpaper-website-in-symfony-3/video/pagination

In this video we will add the ability to Paginate over multiple pages of Wallpapers / Desktop Backgrounds, making use of KnpPaginatorBundle along the way.

https://codereviewvideos.com/course/let-s-build-a-wallpaper-website-in-symfony-3/video/adding-a-detail-view

Probably the easiest video tutorial in the entire series – in this one we simply add a Detail View where a user can download the full sized wallpaper.

https://codereviewvideos.com/course/let-s-build-a-wallpaper-website-in-symfony-3/video/creating-a-home-page

In this video we create a home page for our site, displaying 8 random wallpapers, and then 2 of the “top” wallpapers from each of our categories.

I’d really appreciate any feedback you have on this series.

I also blogged this week. As a heads up, if you are migrating to SwiftMailer version 6 any time soon, be aware of a potential problem you may encounter:

How I Fixed: Swift_Message::newInstance() not found

Before I go, can I also ask that when logged in, have you experienced a problem with being timed out / logged out after watching videos on the site?

I get infrequent reports of this problem, and I cannot reproduce it. I’d be interested to know if you’ve been affected by this?

I’d also like to apologise to anyone who has left a blog comment to which it took me a few days to reply. If you have left a blog comment before, WordPress was kindly auto-accepting the comment but not informing me of new comments. The upshot being that I was missing a bunch of new comments without realising it.

I have switched to “all comments need moderation” now, which although feels like a step backwards, at least means I won’t miss anything. I hope!

As ever, thank you very much for reading and being a part of CodeReviewVideos. I really appreciate it.

Have a great and sunny weekend, and happy coding.

Chris

Published by

Code Review

CodeReviewVideos is a video training site helping software developers learn Symfony faster and easier.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.