@@ -54,6 +54,94 @@ Model::search('query')
54
54
```
55
55
56
56
57
+ ## ` with `
58
+
59
+ The ` with ` method gives you complete access to the Algolia options parameter. This allows you
60
+ to customise the search parameters exactly the same as you would using the algolia php library directly.
61
+
62
+ ``` php
63
+
64
+ $filters = [
65
+ 'averge_ratings >= 3',
66
+ 'total_reviews >= 1'
67
+ ];
68
+
69
+ $filterString = implode(' AND ', $filters);
70
+
71
+ $params = [
72
+ 'aroundLatLng' => $lat.','.$lon,
73
+ 'hitsPerPage' => 30,
74
+ 'page' => 0,
75
+ 'aroundRadius' => 30000, //30km
76
+ 'aroundPrecision' => 200), //200 Meters
77
+ 'getRankingInfo' => true, //return ranking information in results
78
+ 'filters' => $filterString // add filters
79
+ ];
80
+
81
+ $result = Model::search('')->with($params)->get();
82
+
83
+ ```
84
+
85
+
86
+ ## ` hydrate `
87
+
88
+ The ` hydrate ` method is similar to the standard get() method, except it hydrates the models from your Algolia index
89
+ instead of of using the objects keys to pull the related models from your database, meaning much quicker response times.
90
+
91
+ This also gives you the ability to overide the fill() method on any model to use the additional data that you store
92
+ in your indexes.
93
+
94
+ Note: By using this method you must be sure that you are correctly keeping your algolia index in sync with your database
95
+ to avoid populating stale data.
96
+
97
+ Example model with additional data from Algolia Index being populated:
98
+
99
+ ``` php
100
+
101
+ class ExampleModel extends Model
102
+ {
103
+ use Searchable;
104
+
105
+ protected $appends = [
106
+ 'rankingInfo' //Add rankingInfo when converted to array
107
+ ];
108
+
109
+ protected $rankingInfo = [];
110
+ protected $highlightResult = [];
111
+
112
+ /**
113
+ * Adds the ranking & highlight results from the search request to get search score/geo distance etc
114
+ *
115
+ * @param array $attributes
116
+ * @return mixed
117
+ */
118
+ public function fill(array $attributes)
119
+ {
120
+
121
+ if (isset($attributes['_rankingInfo']))
122
+ {
123
+ $this->setRankingInfo($attributes['_rankingInfo']);
124
+ }
125
+
126
+ //Add any additional data stored in algolia as required
127
+
128
+ return parent::fill($attributes);
129
+ }
130
+
131
+ public function getRankingInfoAttribute(): array
132
+ {
133
+ return $this->rankingInfo;
134
+ }
135
+
136
+ public function setRankingInfo(array $rankingInfo)
137
+ {
138
+ $this->rankingInfo = $rankingInfo;
139
+ }
140
+
141
+ $result = ExampleModel::search('')->with($params)->get();
142
+
143
+ ```
144
+
57
145
## Contributing
58
146
59
147
Feel free to open an issue to request a macro.
0 commit comments