Full-text search with Laravel and Meilisearch

https://blog.meilisearch.com/content/images/size/w1200/2023/11/laravel_meili_test.jpg

In this guide, we will see how to use the search functionality in Laravel 10. We’ll start with by introducing the benefits of full-text search. Then, we’ll walk you through setting up full-text search in your Laravel application.

Why use full-text search?

In traditional SQL or NoSQL databases, queries find results exactly matching given criteria. Conversely, full-text search queries can match some or all of a text query with the database’s content. So essentially, full-text search can provide results even in case of partial matches.

When building user-facing search interfaces, full-text search is empowering for users. Tolerance to typos, prefix search, and synonyms help them get results more quickly. It improves discoverability when users do not know what they’re looking for.

How to use search functionality in Laravel 10?

Installing Laravel Scout

Laravel comes with out-of-the-box full-text search capabilities via Laravel Scout.

To enable it, navigate to your Laravel application directory and install Scout via the Composer package manager:

composer require laravel/scout

After installing Scout, you should publish the Scout configuration file. You can do this by running the following artisan command:

php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"

This command should create a new configuration file in your application directory: config/scout.php.

Configuring the Laravel Scout driver

Let’s configure Laravel Scout to use the Meilisearch driver. Meilisearch is an open-source search engine built in Rust. This will allow to get the best full-text search performance. Indeed, the database driver comes with limitations inherent to SQL databases.

First, install the dependencies required to use Scout with Meilisearch via Composer:

composer require meilisearch/meilisearch-php http-interop/http-factory-guzzle

Then, update the environment variables in your .env file:

SCOUT_DRIVER=meilisearch
# Use the host below if you're running Meilisearch via Laravel Sail
MEILISEARCH_HOST=http://meilisearch:7700
MEILISEARCH_KEY=masterKey

Laravel’s official Docker development environment, Laravel Sail, comes with a Meilisearch service out-of-the-box. Please note that when running Meilisearch via Sail, Meilisearch’s host is http://meilisearch:7700.

For production use cases, we recommend using a managed Meilisearch via Meilisearch Cloud. On Meilisearch Cloud, you can find your host URL in your project settings.

Making Eloquent models searchable

With Scout installed and configured, just add the Laravel\Scout\Searchable trait to your Eloquent models to make them searchable. This trait will use Laravel’s model observers to keep the data in your model in sync with Meilisearch.

Here’s an example model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;

class Contact extends Model
{
	use Searchable;
}

You can use the toSearchableArray method to configure which fields to store in Meilisearch. This notably enables storing a model and its relationships’ data in the same document.

The example below shows how to store a model’s relationships data in Meilisearch:

<?php

namespace App\Models;

use App\Models\Company;
use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Contact extends Model
{
    use Searchable;

    public function company(): BelongsTo
    {
        return $this->belongsTo(Company::class);
    }

    public function toSearchableArray(): array
    {
	    // All model attributes are made searchable
        $array = $this->toArray();

		// Then we add some additional fields
        $array['organization_id'] = $this->company->organization->id;
        $array['company_name'] = $this->company->name;
        $array['company_url'] = $this->company->url;

        return $array;
    }
}

Configuring filterable and sortable attributes

Meilisearch allows you to perform advanced filtering and sorting on your search results. Choose which attributes are filterable and sortable via your Meilisearch index settings.

Configure your Meilisearch index settings via the config/scout.php file:

<?php

use App\Models\Contact;

return [
	// additional configuration...
	
    'meilisearch' => [
        'host' => env('MEILISEARCH_HOST', 'http://localhost:7700'),
        'key' => env('MEILISEARCH_KEY'),
        'index-settings' => [
            Contact::class => [
                'filterableAttributes' => ['organization_id'],
                'sortableAttributes' => ['name', 'company_name']
            ],
        ],
    ],

The example above updates Meilisearch index settings for the Contact model:

  • it makes the organization_id field filterable
  • it makes the name and company_name fields sortable

Update your Meilisearch index settings by running the following Artisan command:

php artisan scout:sync-index-settings

Laravel full-text search example

We built a demo application to give you a feel of what full-text search looks like in a Laravel application. This demo showcases an app-wide search in a CRM (Customer Relationship Management) application.

CRM demo application build with Laravel
Laravel SaaS search demo

This demo application uses the following search features:

The code is open-sourced on Github. ????

???? Check out the repository: https://github.com/meilisearch/saas-demo


We hope this guide helped to understand the importance of full-text search and how to implement it with Laravel. For more information, read the Laravel Scout and Meilisearch docs.

Meilisearch is an open-source search engine with intuitive developer experience to build user-facing search. You can self-host it or get a premium experience with Meilisearch Cloud.

For more things Meilisearch, you can join the community on Discord or subscribe to the newsletter. You can learn more about the product by checking out the roadmap and participating in product discussions.

Laravel News Links

Chicken McNuggets Training Video

https://theawesomer.com/photos/2023/11/1980s_mcnuggets_training_video_t.jpg

Chicken McNuggets Training Video

Link

There was lots to love about the 1980s, like Max Headroom, VHS tape boxes, and this McDonald’s training video, created to familiarize the crew with Chicken McNuggets and their sauces. What we got was a hilariously surreal short film with googly-eyed Big Macs and french fries welcoming their new friends to the menu. Brought to you by Tony Pepperoni.

The Awesomer

Smith & Wesson Releases New Performance Center M&P9 Metal M2.0 Spec Series

https://www.ammoland.com/wp-content/uploads/2023/11/Smith-Wesson-MP-9-500×472.jpg

Smith & Wesson Releases New Performance Center M&P9 Metal M2.0 Spec Series
Smith & Wesson Releases New Performance Center M&P9 Metal M2.0 Spec Series

Smith & Wesson Brands, Inc.(NASDAQ Global Select: SWBI), a leader in firearm manufacturing and design, today announces the release of its latest Spec Series Kit with the new Performance Center M&P9 Metal M2.0.

True to its design, this pistol not only sets a new benchmark for the Spec Series line but also places a heightened focus on performance, ensuring users encounter the pinnacle of what Smith & Wesson’s Performance Center models have to offer.

Upgraded features integrated into this Spec Series pistol include a built-in Faxon compensator to mitigate felt recoil and muzzle rise, custom lightening cuts in the slide to reduce weight and improve reliability while being compensated, an enhanced sear for a lighter, crisp trigger let-off, suppressor height sights, and a sharp OD Green Cerakote© finish. Within its sleek new look lies a testament to durability – a robust all-metal frame that can withstand the elements while still maintaining a well-balanced feel in the hand.

“Our M&P polymer handguns have long been recognized for their reliability and ergonomic design. By combining these trusted attributes with the durability of the Metal M2.0 platform and adding modern performance upgrades, we were able to elevate the Spec Series to next level. This design is a bridge between tradition and progress, and offers a distinct edge across today’s dynamic shooting environments,” said Corey Beaudreau, Product Manager.

The PC M&P9 Metal M2.0 Spec Series ships in a custom hardcase and includes two 23-round magazines, two 17-round magazines, C.O.R.ETM plate system for mounting optics, a karambit style knife, and custom M&P Spec Series Challenge Coin. The MSRP for this kit is $999.

For more information on the Performance Center M&P9 Metal M2.0 Spec Series, visit https://www.smith-wesson.com/.

Smith & Wesson Releases New Performance Center M&P9 Metal M2.0 Spec Series by AmmoLand Shooting Sports News on Scribd


About Smith & Wesson Brands, Inc.

Smith & Wesson Brands, Inc. (NASDAQ Global Select: SWBI) is a U.S.-based leader in firearm manufacturing and design, delivering a broad portfolio of quality handgun, long gun, and suppressor products to the global consumer and professional markets under the iconic Smith & Wesson® and Gemtech® brands. The company also provides manufacturing services including forging, machining, and precision plastic injection molding services. For more information call (844) 363-5386 or visit smithwesson.com.

Smith and Wesson

AmmoLand Shooting Sports News

This ‘Little Mac’ Is a Pint-Sized Windows Version of Apple’s Famed PC

https://i.kinja-img.com/image/upload/c_fill,h_675,pg_1,q_80,w_1200/b2f6d8cbcbcb26633528968529ecc571.jpg

How best can you display the advances in technology over the years? Let’s take a PC like the landmark original 1984 Apple Macintosh—later rebranded the Macintosh 128K—and shrink it by more than half. Then, boost its processing capability and memory by a factor of thousands or even tens of thousands—AKA modern mobile gaming standards. That’s what Ayaneo is doing with its upcoming Mini PC AM01, a pint-sized homage to the all-in-one computing system that weighs a little more than a pound.

Like It or Not, Your Doctor Will Use AI | AI Unlocked

Ayaneo first shared images and a few scant details of its Mini PC earlier this month, but the company launched its funding campaign Retro Mini PC Tuesday and shared full PC specs on its Indiegogo page.

It seems the “Little Mac,” as we at Gizmodo have taken to calling it, is pretty powerful for its size. The Mini PC will come with either an AMD Ryzen 3 3200U at 3.5 GHz or a Ryzen 7 5700U at 4.3 GHz. The “U” signifies they’re the low-power versions of the CPU, but it is plenty powerful to run most web-based applications. It will also sport up to 64GB of DDR4 memory, plus an integrated Vega or RDNA2 video card. It means the Mini PC might have a good deal of function for its petite size. The 3200U version will start at a $149 baseline for those going in early on the crowdfunding campaign, while the 5700U will shoot upwards of $219. The retail price will be $199 and $259 for the less and more powerful CPUs at base.

Novelty is surely a factor, but it only weighs less than 466 grams, or a little more than 1 pound. The box itself measures 5.2 by 5.2 inches and is a little more than 2 inches deep, meaning it is plenty portable even though you’re going to be missing out on any sort of display. The Mini PC supports Wi-Fi 6 or 5, and it contains three USB 3.2 ports, a USB-C (only for data transfer), and an HDMI 2.0 and DisplayPort 1.4 to connect to other displays.

The big sticking point may be memory or, more, the lack of it. The bare system does not contain HDD or SSD, so you’ll have to pay more for 256 GB, 512 GB, or 2 TB of internal storage. It has a PCIe 3.0 slot to support a VMe or SATA SSD, plus a SATA 3.0 interface without the bracket.

The system comes pre-installed with Windows 11, and as a handheld console maker, Ayaneo is trying to share how it could be used for gaming. However, you can also install Linux, Ubuntu, and Debian and gaming-based operating systems like Steam OS. Videocardz also offered a nice rundown of the specs and compared them to the original $2,495 Macintosh released back in ‘84.

When the company first revealed the Mini PC, it displayed it next to a few small, extremely cute game cartridges, but the company confirmed with Gizmodo all that was just set dressing. In effect, the PC is much akin to the new wave of portable gaming consoles, though the starting price on a Mini PC is far, far lower than even the $399 LCD Steam Deck with 256 GB of storage, let alone the newer OLED Steam Decks. Without a screen, the Mini PC offers a different kind of portability, so long as you have controls and a monitor to hook it up to.

So no, it’s not a device meant to play physical media, and the slot on the original Macintosh is instead just a bar to house the power button. There’s also no in-built monochrome screen like the Macintosh 128K, but there is a cheeky nod on the black bar to Apple’s original Finder logo.

It’s a shame nobody outside Ayaneo has had the chance to test out the Mini PC, and we can’t advise anybody to drop money on a crowdfunding campaign when nobody has had the chance to put it through its paces. That doesn’t stop the retro throwback from looking absolutely adorable.

Ayaneo, the China-based handheld PC brand that’s been making waves since 2020, has a penchant for crafting devices that not-so-gently scratch at tech nostalgia. The company is also gearing up to release the Ayaneo Slide, a portable PC that resembles the Nokia Sidekick thanks to the slideout screen hiding a keyboard underneath.

Gizmodo

Building a Working Star Wars Plasma Blaster

https://theawesomer.com/photos/2023/11/star_wars_plasma_blaster_irl_t.jpg

Building a Working Star Wars Plasma Blaster

Link

The blasters in Star Wars supposedly fire bolts of plasma energy held together with a magnetic field. This sounds like pure science fiction, but Jake Makes wanted to see if he could create the same effect with a real-world weapon. While he came up with an approach that looks pretty accurate, it’s not technically the same idea at all.

The Awesomer

Ted Lasso returns to promote Hannah Waddingham’s special

https://photos5.appleinsider.com/gallery/57420-116906-000-lead-Waddingham-promo-xl.jpgTed Lasso — or at least star Jason Sudeikis — is back in a new role as taxi driver to Hannah Waddingham, ahead of her Apple TV+ Christmas special.

Jason Sudeikis (left) and Hannah Waddingham (right)Jason Sudeikis (left) and Hannah Waddingham (right)

"Ted Lasso" was the first breakout hit for Apple TV+, and when it officially concluded after three seasons, its stars including co-creator Jason Sudeikis have both hoped and hinted at a future return for the character.

Read more…AppleInsider News

How Coins Are Made

https://theawesomer.com/photos/2023/11/japan_coin_factory_t.jpg

How Coins Are Made

Link

While the use of physical currency continues to dwindle, there’s still a need for coins to be produced. Process X takes us on an in-depth tour of Japan’s only coin factory for a look at how they make coins. The Osaka mint produces six kinds of coins, from aluminum 1 yen coins to the copper, nickel, and zinc 500 yen coins shown in the video.

The Awesomer

Tiny House in an Old Airplane

https://theawesomer.com/photos/2023/11/airplane_tiny_house_t.jpg

Tiny House in an Old Airplane

Link

Unless you score Business Class seats, it’s pretty hard to sleep on an airplane. That is, unless it’s this old Douglas DC-6 that’s been converted into a home. Tiny House Giant Journey visits with homeowners and flight trainers Jon and Stephanie, who turned the airplane into a 2 BR, 1 BA Airbnb with a kitchen, a wing deck, and a flight simulator in the cockpit.

The Awesomer