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
+7-139
Original file line number
Diff line number
Diff line change
@@ -59,153 +59,21 @@ You can also [create your own Adapter](docs/create-own-adapter.md) to use other
59
59
60
60
## Usage
61
61
62
-
To use the bundle, create your first `Search`. To do this, simply create a class and add the `AsSearch` attribute.
62
+
To use the bundle, create your first `Search`. To do this, just use the `make:search` command and follow indications.
63
+
64
+
```bash
65
+
php bin/console make:search
66
+
```
63
67
64
68
In the case of Meilisearch, you need to specify the name of the index to use, and for Doctrine, the FQCN of the entity to use.
65
69
66
70
By default, the name of your search will be the name of your class with the `Search` suffix removed. You can change this by specifying a custom name.
67
71
68
72
Also, by default, the Adapter used is the one specified in the configuration under `default_adapter`. You can specify the name of the Adapter to use, for example, if you have multiple `Search` instances that use different Adapters.
69
73
70
-
### Create a search
71
-
```php
72
-
<?php
73
-
74
-
declare(strict_types=1);
75
-
76
-
namespace App\Search;
77
-
78
-
use Mezcalito\UxSearchBundle\Attribute\AsSearch;
79
-
use Mezcalito\UxSearchBundle\Search\AbstractSearch;
80
-
81
-
#[AsSearch('products')]
82
-
class ListingSearch extends AbstractSearch
83
-
{
84
-
}
85
-
```
86
-
### Add facets
87
-
88
-
If you wish, you can add facets to your Search. To do this, you need to use the `addFacet` method.
| key | Attribute key and order separate by ':' | ?string |
134
-
| label | Label displayed | string |
74
+
After that, you have a fully functional simple search.
75
+
Feel free to check the documentation to [customize your search](docs/usage/customize-your-search.md) (adding facets, sorting, ...) or if you prefer not to use the maker.
135
76
136
-
If you do not specify a sort or if the key is empty, the default sorting of your adapter will be applied.
137
-
138
-
```php
139
-
use Mezcalito\UxSearchBundle\Search\Sort;
140
-
141
-
// ..
142
-
143
-
public function build(array $options = []): void
144
-
{
145
-
$this
146
-
// ..
147
-
->addAvailableSort(null, 'Relevancy')
148
-
->addAvailableSort('price:asc', 'Price ↑')
149
-
->addAvailableSort('price:desc', 'Price ↓')
150
-
;
151
-
}
152
-
```
153
-
154
-
### Add EventListener or EventSubscriber
155
-
For example, you can modify the `ResultSet` on the `PostSearchEvent` to enrich a `Hit` with data from database.
156
-
157
-
```php
158
-
use Mezcalito\UxSearchBundle\Event\PreSearchEvent;
159
-
use Mezcalito\UxSearchBundle\Event\PostSearchEvent;
160
-
// ..
161
-
162
-
public function build(array $options = []): void
163
-
{
164
-
$this
165
-
// ...
166
-
->addEventListener(PreSearchEvent::class, function (PreSearchEvent $event) {
167
-
// $event->getSearch();
168
-
// $event->getQuery();
169
-
})
170
-
->addEventListener(PostSearchEvent::class, function (PostSearchEvent $event) {
171
-
// $event->getSearch();
172
-
// $event->getQuery();
173
-
// $event->getResultSet();
174
-
})
175
-
->addEventSubscriber(YourEventSubscriber::cass)
176
-
;
177
-
}
178
-
```
179
-
180
-
### Enable urlRewriting and set up an urlFormater
181
-
It is possible to enable a URL rewriting system to allow sharing of configured search URLs. To do this, simply add the `->enableUrlRewriting` method. By default, a `DefaultUrlFormater` is provided in the bundle. This allows you to add query parameters with the values of the selected facets.
182
-
183
-
```php
184
-
185
-
public function build(array $options = []): void
186
-
{
187
-
$this
188
-
// ...
189
-
->enableUrlRewriting()
190
-
;
191
-
}
192
-
```
193
-
194
-
You can also create your own UrlFormater. To do so, you need to implement the `UrlFormaterInterface` and define your own logic in the `generateUrl` and `applyFilters` methods. All that is left is to use it in a search via the `->setUrlFormater()` method.
| key | Attribute key and order separate by ':' | ?string |
73
+
| label | Label displayed | string |
74
+
75
+
If you do not specify a sort or if the key is empty, the default sorting of your adapter will be applied.
76
+
77
+
```php
78
+
use Mezcalito\UxSearchBundle\Search\Sort;
79
+
80
+
// ..
81
+
82
+
public function build(array $options = []): void
83
+
{
84
+
$this
85
+
// ..
86
+
->addAvailableSort(null, 'Relevancy')
87
+
->addAvailableSort('price:asc', 'Price ↑')
88
+
->addAvailableSort('price:desc', 'Price ↓')
89
+
;
90
+
}
91
+
```
92
+
93
+
## Add EventListener or EventSubscriber
94
+
For example, you can modify the `ResultSet` on the `PostSearchEvent` to enrich a `Hit` with data from database.
95
+
96
+
```php
97
+
use Mezcalito\UxSearchBundle\Event\PreSearchEvent;
98
+
use Mezcalito\UxSearchBundle\Event\PostSearchEvent;
99
+
// ..
100
+
101
+
public function build(array $options = []): void
102
+
{
103
+
$this
104
+
// ...
105
+
->addEventListener(PreSearchEvent::class, function (PreSearchEvent $event) {
106
+
// $event->getSearch();
107
+
// $event->getQuery();
108
+
})
109
+
->addEventListener(PostSearchEvent::class, function (PostSearchEvent $event) {
110
+
// $event->getSearch();
111
+
// $event->getQuery();
112
+
// $event->getResultSet();
113
+
})
114
+
->addEventSubscriber(YourEventSubscriber::cass)
115
+
;
116
+
}
117
+
```
118
+
119
+
## Enable urlRewriting and set up an urlFormater
120
+
It is possible to enable a URL rewriting system to allow sharing of configured search URLs. To do this, simply add the `->enableUrlRewriting` method. By default, a `DefaultUrlFormater` is provided in the bundle. This allows you to add query parameters with the values of the selected facets.
121
+
122
+
```php
123
+
124
+
public function build(array $options = []): void
125
+
{
126
+
$this
127
+
// ...
128
+
->enableUrlRewriting()
129
+
;
130
+
}
131
+
```
132
+
133
+
You can also create your own UrlFormater. To do so, you need to implement the `UrlFormaterInterface` and define your own logic in the `generateUrl` and `applyFilters` methods. All that is left is to use it in a search via the `->setUrlFormater()` method.
0 commit comments