You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-8Lines changed: 6 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,15 +11,13 @@ This means simply using this package as shown is not everything – you need to
11
11
composer require whitecube/laravel-search-builder
12
12
```
13
13
14
-
## Usage
15
-
16
-
### How to structure your query
14
+
## How to structure your query
17
15
18
16
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.
19
17
20
18
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.
21
19
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:
You can get a search builder instance just by passing it the model you want to search.
51
49
@@ -71,7 +69,7 @@ class Product extends Model
71
69
$builder = Product::searchBuilder();
72
70
```
73
71
74
-
###Defining search conditions
72
+
## Defining search conditions
75
73
76
74
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.
77
75
@@ -115,7 +113,7 @@ Product::searchBuilder()
115
113
});
116
114
```
117
115
118
-
###Getting the results
116
+
## Getting the results
119
117
120
118
After defining your conditions, you can get the collection of results by calling the `get` method.
121
119
@@ -149,7 +147,7 @@ Thanks!
149
147
150
148
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.
151
149
152
-
Run PHPUnit by calling `composer test`.
150
+
Run the test suite by calling `./vendor/bin/pest`.
0 commit comments