@@ -648,7 +648,7 @@ public function searchFor($value, $columns = ['*'], $options = [], $boolean = 'a
648
648
649
649
public function searchTerm ($ term , $ fields = ['* ' ], $ options = [], $ boolean = 'and ' ): static
650
650
{
651
-
651
+ $ this -> _ensureValueAsArray ( $ fields );
652
652
$ this ->wheres [] = [
653
653
'column ' => '* ' ,
654
654
'type ' => 'Search ' ,
@@ -664,6 +664,7 @@ public function searchTerm($term, $fields = ['*'], $options = [], $boolean = 'an
664
664
665
665
public function searchTermMost ($ term , $ fields = ['* ' ], $ options = [], $ boolean = 'and ' ): static
666
666
{
667
+ $ this ->_ensureValueAsArray ($ fields );
667
668
$ this ->wheres [] = [
668
669
'column ' => '* ' ,
669
670
'type ' => 'Search ' ,
@@ -679,6 +680,7 @@ public function searchTermMost($term, $fields = ['*'], $options = [], $boolean =
679
680
680
681
public function searchTermCross ($ term , $ fields = ['* ' ], $ options = [], $ boolean = 'and ' ): static
681
682
{
683
+ $ this ->_ensureValueAsArray ($ fields );
682
684
$ this ->wheres [] = [
683
685
'column ' => '* ' ,
684
686
'type ' => 'Search ' ,
@@ -694,6 +696,7 @@ public function searchTermCross($term, $fields = ['*'], $options = [], $boolean
694
696
695
697
public function searchPhrase ($ phrase , $ fields = ['* ' ], $ options = [], $ boolean = 'and ' ): static
696
698
{
699
+ $ this ->_ensureValueAsArray ($ fields );
697
700
$ this ->wheres [] = [
698
701
'column ' => '* ' ,
699
702
'type ' => 'Search ' ,
@@ -709,6 +712,7 @@ public function searchPhrase($phrase, $fields = ['*'], $options = [], $boolean =
709
712
710
713
public function searchPhrasePrefix ($ phrase , $ fields = ['* ' ], $ options = [], $ boolean = 'and ' ): static
711
714
{
715
+ $ this ->_ensureValueAsArray ($ fields );
712
716
$ this ->wheres [] = [
713
717
'column ' => '* ' ,
714
718
'type ' => 'Search ' ,
@@ -724,6 +728,7 @@ public function searchPhrasePrefix($phrase, $fields = ['*'], $options = [], $boo
724
728
725
729
public function searchBoolPrefix ($ phrase , $ fields = ['* ' ], $ options = [], $ boolean = 'and ' ): static
726
730
{
731
+ $ this ->_ensureValueAsArray ($ fields );
727
732
$ this ->wheres [] = [
728
733
'column ' => '* ' ,
729
734
'type ' => 'Search ' ,
@@ -846,6 +851,21 @@ public function setMinShouldMatch(int $value): static
846
851
return $ this ;
847
852
}
848
853
854
+ public function setBoost (int $ value ): static
855
+ {
856
+ $ wheres = $ this ->wheres ;
857
+ if (! $ wheres ) {
858
+ throw new RuntimeException ('No where clause found ' );
859
+ }
860
+ $ lastWhere = end ($ wheres );
861
+ if ($ lastWhere ['type ' ] != 'Search ' ) {
862
+ throw new RuntimeException ('Min Should Match can only be applied to Search type queries ' );
863
+ }
864
+ $ this ->_attachOption ('boost ' , $ value );
865
+
866
+ return $ this ;
867
+ }
868
+
849
869
//----------------------------------------------------------------------
850
870
// Options
851
871
//----------------------------------------------------------------------
@@ -1781,6 +1801,13 @@ private function _formatTimestamp($value): string|int
1781
1801
}
1782
1802
}
1783
1803
1804
+ private function _ensureValueAsArray (&$ value ): void
1805
+ {
1806
+ if (! is_array ($ value )) {
1807
+ $ value = [$ value ];
1808
+ }
1809
+ }
1810
+
1784
1811
//----------------------------------------------------------------------
1785
1812
// Disabled Methods
1786
1813
//----------------------------------------------------------------------
0 commit comments