22
33namespace ProtoneMedia \LaravelCrossEloquentSearch ;
44
5- use Illuminate \Support \Collection ;
65use Illuminate \Support \Traits \ForwardsCalls ;
76
87class SearchFactory
98{
109 use ForwardsCalls;
1110
1211 /**
13- * Create a new Searcher instance.
12+ * Returns a new Searcher instance.
13+ *
14+ * @return \ProtoneMedia\LaravelCrossEloquentSearch\Searcher
1415 */
1516 public function new (): Searcher
1617 {
1718 return new Searcher ;
1819 }
1920
20- /**
21- * Add a model to search through.
22- */
23- public function add ($ query , $ columns = null , string $ orderByColumn = null ): Searcher
24- {
25- return $ this ->new ()->add ($ query , $ columns , $ orderByColumn );
26- }
27-
28- /**
29- * Add a full-text searchable model.
30- */
31- public function addFullText ($ query , $ columns = null , array $ options = [], string $ orderByColumn = null ): Searcher
32- {
33- return $ this ->new ()->addFullText ($ query , $ columns , $ options , $ orderByColumn );
34- }
35-
36- /**
37- * Add multiple models at once.
38- */
39- public function addMany (array $ queries ): Searcher
40- {
41- return $ this ->new ()->addMany ($ queries );
42- }
43-
44- /**
45- * Set the order by column for the most recently added model.
46- */
47- public function orderBy (string $ orderByColumn ): Searcher
48- {
49- return $ this ->new ()->orderBy ($ orderByColumn );
50- }
51-
52- /**
53- * Order results in ascending order.
54- */
55- public function orderByAsc (): Searcher
56- {
57- return $ this ->new ()->orderByAsc ();
58- }
59-
60- /**
61- * Order results in descending order.
62- */
63- public function orderByDesc (): Searcher
64- {
65- return $ this ->new ()->orderByDesc ();
66- }
67-
68- /**
69- * Order results by relevance.
70- */
71- public function orderByRelevance (): Searcher
72- {
73- return $ this ->new ()->orderByRelevance ();
74- }
75-
76- /**
77- * Order results by model type.
78- */
79- public function orderByModel ($ modelClasses ): Searcher
80- {
81- return $ this ->new ()->orderByModel ($ modelClasses );
82- }
83-
84- /**
85- * Configure wildcard behavior.
86- */
87- public function beginWithWildcard (bool $ state = true ): Searcher
88- {
89- return $ this ->new ()->beginWithWildcard ($ state );
90- }
91-
92- /**
93- * Configure wildcard behavior.
94- */
95- public function endWithWildcard (bool $ state = true ): Searcher
96- {
97- return $ this ->new ()->endWithWildcard ($ state );
98- }
99-
100- /**
101- * Enable case-insensitive searching.
102- */
103- public function ignoreCase (bool $ state = true ): Searcher
104- {
105- return $ this ->new ()->ignoreCase ($ state );
106- }
107-
108- /**
109- * Enable sounds like searching.
110- */
111- public function soundsLike (bool $ state = true ): Searcher
112- {
113- return $ this ->new ()->soundsLike ($ state );
114- }
115-
116- /**
117- * Configure term parsing.
118- */
119- public function parseTerm (bool $ state = true ): Searcher
120- {
121- return $ this ->new ()->parseTerm ($ state );
122- }
123-
124- /**
125- * Configure pagination.
126- */
127- public function paginate (int $ perPage = 15 , string $ pageName = 'page ' , int $ page = null ): Searcher
128- {
129- return $ this ->new ()->paginate ($ perPage , $ pageName , $ page );
130- }
131-
132- /**
133- * Configure simple pagination.
134- */
135- public function simplePaginate (int $ perPage = 15 , string $ pageName = 'page ' , int $ page = null ): Searcher
136- {
137- return $ this ->new ()->simplePaginate ($ perPage , $ pageName , $ page );
138- }
139-
140- /**
141- * Include model type in results.
142- */
143- public function includeModelType (string $ key = 'type ' ): Searcher
144- {
145- return $ this ->new ()->includeModelType ($ key );
146- }
147-
148- /**
149- * Perform the search.
150- *
151- * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Contracts\Pagination\LengthAwarePaginator
152- */
153- public function search (string $ terms = null )
154- {
155- return $ this ->new ()->search ($ terms );
156- }
157-
158- /**
159- * Count the search results.
160- */
161- public function count (string $ terms = null ): int
162- {
163- return $ this ->new ()->count ($ terms );
164- }
165-
166- /**
167- * Parse search terms.
168- */
169- public static function parseTerms (string $ terms , callable $ callback = null ): Collection
170- {
171- return Searcher::parseTerms ($ terms , $ callback );
172- }
173-
17421 /**
17522 * Handle dynamic method calls into a new Searcher instance.
23+ *
24+ * @param string $method
25+ * @param array $parameters
26+ * @return mixed
17627 */
17728 public function __call ($ method , $ parameters )
17829 {
179- return $ this ->forwardCallTo ($ this ->new (), $ method , $ parameters );
30+ return $ this ->forwardCallTo (
31+ $ this ->new (),
32+ $ method ,
33+ $ parameters
34+ );
18035 }
181- }
36+ }
0 commit comments