@@ -173,6 +173,7 @@ protected function buildQuery(SearchOptions $searchOpts, Entity $entityModelInst
173173 // Handle exact term matching
174174 foreach ($ searchOpts ->exacts as $ inputTerm ) {
175175 $ entityQuery ->where (function (EloquentBuilder $ query ) use ($ inputTerm , $ entityModelInstance ) {
176+ $ inputTerm = str_replace ('\\' , '\\\\' , $ inputTerm );
176177 $ query ->where ('name ' , 'like ' , '% ' . $ inputTerm . '% ' )
177178 ->orWhere ($ entityModelInstance ->textField , 'like ' , '% ' . $ inputTerm . '% ' );
178179 });
@@ -218,7 +219,7 @@ protected function applyTermSearch(EloquentBuilder $entityQuery, SearchOptions $
218219 $ subQuery ->where ('entity_type ' , '= ' , $ entity ->getMorphClass ());
219220 $ subQuery ->where (function (Builder $ query ) use ($ terms ) {
220221 foreach ($ terms as $ inputTerm ) {
221- $ inputTerm = ( strpos ( $ inputTerm , "\\" ) !== false ) ? str_replace ("\\" , " \\\\" , $ inputTerm ) : $ inputTerm ;
222+ $ inputTerm = str_replace ('\\' , ' \\\\' , $ inputTerm );
222223 $ query ->orWhere ('term ' , 'like ' , $ inputTerm . '% ' );
223224 }
224225 });
@@ -355,6 +356,9 @@ protected function applyTagSearch(EloquentBuilder $query, string $tagTerm): Eloq
355356 $ tagValue = (float ) trim ($ connection ->getPdo ()->quote ($ tagValue ), "' " );
356357 $ query ->whereRaw ("value {$ tagOperator } {$ tagValue }" );
357358 } else {
359+ if ($ tagOperator === 'like ' ) {
360+ $ tagValue = str_replace ('\\' , '\\\\' , $ tagValue );
361+ }
358362 $ query ->where ('value ' , $ tagOperator , $ tagValue );
359363 }
360364 } else {
0 commit comments