1. The document describes using ElasticSearch to search for hotels that meet certain criteria, providing a more flexible approach than SQL. 2. It explains how ElasticSearch allows storing and querying structured and unstructured data using a document-oriented model with an inverted index. 3. Key features discussed include ElasticSearch's distributed architecture, RESTful API, relevance scoring, and ability to handle requirements and preferences more intelligently than SQL.
47. Example(inverted(index
Term Doc_1 Doc_2
-------------------------
brown | X | X
dog | X | X
fox | X | X
in | | X
jump | X | X
lazy | X | X
over | X | X
quick | X | X
summer | | X
the | X | X
------------------------
61. Full$text$search
1. Add%a%full%text%index.%1
2. Alter%the%query,%and%search%across%both%name%and%company.
select *
from `hotels`
where match (`name`, `company`) against ("Renaissance")
and `price` <= 150
and `disability_access` = 1
1"h$p://dev.mysql.com/doc/refman/5.0/en/fulltext<search.html
63. Adding&"wants"&in
select *, if (`floor_levels` > 1, 1, 0) as `has_multiple_floor_levels`
from `hotels`
where match (`name`, `company`) against ("Renaissance")
and `price` <= 150
and `disability_access` = 1
order by `wifi` desc, `has_multiple_floor_levels` desc -- ^1
1"We're"priori*sing"Wifi"over"mul*ple"floor"levels...
90. Eloquent)repository
class EloquentHotelRepository implements HotelRepository
{
public function create($name)
{
// Create and save the model
}
public function search($name, array $filters)
{
// Perform search as best you can without ElasticSearch...
}
// Truncated for brevity...
}
91. Decora'ng*the*repository
class ElasticSearchHotelRepository implements HotelRepository
{
protected $eloquent;
public function __construct(EloquentHotelRepository $eloquent)
{
$this->eloquent = $eloquent;
}
public function create($name)
{
$this->eloquent->create($name);
}
public function search($name, array $filters)
{
// Truncated for brevity...
}
}
92. Decora'ng*the*repository
class ElasticSearchHotelRepository implements HotelRepository
{
public function search($name, array $filters)
{
$results = $client->search([
// ...
]);
return array_map(function ($result) {
$hotel = new Hotel([
//
]);
$hotel->exists = true;
return $hotel;
}, $results);
}
}