Skip to content

Commit aa0bcbf

Browse files
committed
Update README.md
1 parent ae953ea commit aa0bcbf

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ This means simply using this package as shown is not everything – you need to
1111
composer require whitecube/laravel-search-builder
1212
```
1313

14-
## Usage
15-
16-
### How to structure your query
14+
## How to structure your query
1715

1816
To make your search queries extremely fast, the search builder will pack all of your conditions in a subquery that will aim to hit as many covering indexes as possible, in order to build an aggregated table that only contains ids of the pertinent models (along with a score, more on this later). This aggregated table will then be used to filter down the actual table with an inner join. This means that the processing of your search logic is done entirely on your indexes, and the full table is only accessed at the end, which dramatically speeds everything up.
1917

2018
However, the package can not detect your database structure, so it is your responsibility to create your indexes correctly, and in such a way that your search condition queries will not have to access your main tables' data.
2119

22-
Here's an example of what we're looking to achieve, in raw SQL. Given we have a products table, and we want to search it by reference and by name, and prioritise the reference over the name:
20+
Here's an example of what we're looking to achieve, in raw SQL. Given that we have a products table, and we want to search it by reference and by name, and prioritise the reference over the name:
2321

2422
```sql
2523
with id_and_total_score as (
@@ -45,7 +43,7 @@ inner join id_and_total_score on id_and_total_score.id = products.id
4543
order by score desc;
4644
```
4745

48-
### The search builder instance
46+
## The search builder instance
4947

5048
You can get a search builder instance just by passing it the model you want to search.
5149

@@ -71,7 +69,7 @@ class Product extends Model
7169
$builder = Product::searchBuilder();
7270
```
7371

74-
### Defining search conditions
72+
## Defining search conditions
7573

7674
Once you have a search builder instance, you can use it to define your search conditions, by passing eloquent builder instances to the `search` method.
7775

@@ -115,7 +113,7 @@ Product::searchBuilder()
115113
});
116114
```
117115

118-
### Getting the results
116+
## Getting the results
119117

120118
After defining your conditions, you can get the collection of results by calling the `get` method.
121119

@@ -149,7 +147,7 @@ Thanks!
149147

150148
When adding a new feature or fixing a bug, please add corresponding unit tests. The current set of tests is limited, but every unit test added will improve the quality of the package.
151149

152-
Run PHPUnit by calling `composer test`.
150+
Run the test suite by calling `./vendor/bin/pest`.
153151

154152
## Made with ❤️ for open source
155153

0 commit comments

Comments
 (0)