diff --git a/src/QueryGrammar.php b/src/QueryGrammar.php index 0c1386e..4f7c1f6 100644 --- a/src/QueryGrammar.php +++ b/src/QueryGrammar.php @@ -514,19 +514,17 @@ protected function compileWhereSearch(Builder $builder, array $where): array 'match' => [ $field => [ 'query' => $where['value'], - ] + ], ], ]; } - if (! empty($where['options']['fuzziness'])) { - $matchType = array_keys($query)[0]; + $matchType = array_keys($query)[0]; - if ($matchType === 'multi_match') { - $query[$matchType]['fuzziness'] = $where['options']['fuzziness']; - } else { - $query[$matchType][$field]['fuzziness'] = $where['options']['fuzziness']; - } + if (! empty($where['options']['fuzziness']) && $matchType === 'multi_match') { + $query[$matchType]['fuzziness'] = $where['options']['fuzziness']; + } elseif (! empty($where['options']['fuzziness'])) { + $query[$matchType][$field]['fuzziness'] = $where['options']['fuzziness']; } if (! empty($where['options']['constant_score'])) { @@ -537,6 +535,17 @@ protected function compileWhereSearch(Builder $builder, array $where): array ]; } + $otherOptions = array_diff_key( + $where['options'], + array_flip(['fields', 'fuzziness', 'constant_score']) + ); + + if ($matchType === 'multi_match') { + $query['multi_match'] = $query['multi_match'] + $otherOptions; + } else { + $query[$matchType][$field] = $query[$matchType][$field] + $otherOptions; + } + return $query; }