Skip to content

Commit

Permalink
Merge pull request #37 from timezoneone/36-multiple-fields-results
Browse files Browse the repository at this point in the history
fix for issue #36 - find all keywords across any of the source fields
  • Loading branch information
Damian Mooyman authored Jan 23, 2018
2 parents d85d124 + d23df6a commit 57ad821
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions code/AutoCompleteField.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,14 @@ public function Suggest(SS_HTTPRequest $request)
->sort($this->sourceSort)
->limit($limit);

// Go through each source field and apply each keyword separately using ->filter() to ensure they are combined via "AND".
// Fetch results that match all of the keywords across any of the source fields
$keywords = preg_split('/[\s,]+/', $q);
foreach ($sourceFields as $sourceField) {
foreach($keywords as $keyword) {
$query = $query->filter([
"{$sourceField}:PartialMatch" => $keyword
]);
foreach($keywords as $keyword) {
$filters = array();
foreach ($sourceFields as $sourceField) {
$filters["{$sourceField}:PartialMatch"] = $keyword;
}
$query = $query->filterAny($filters);
}

if ($this->sourceFilter) {
Expand Down

0 comments on commit 57ad821

Please sign in to comment.