Skip to content

Commit

Permalink
fix(search): fix exclusionary search and search url on subtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Aug 27, 2024
1 parent f8d677b commit 245fa04
Show file tree
Hide file tree
Showing 5 changed files with 877 additions and 564 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Add basic site data:
$ php artisan add-site-settings
$ php artisan add-text-pages
$ php artisan copy-default-images
$ php artisan convert-character-subtype
```

Finally, set up the admin account for logging in:
Expand Down
26 changes: 18 additions & 8 deletions app/Http/Controllers/BrowseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,25 @@ public function getCharacters(Request $request) {
$query->havingRaw('COUNT(*) > '.(in_array('hybrid', $request->get('subtype_ids')) ? 1 : 0));
});
} else {
$imageQuery->whereHas('subtypes', function ($query) use ($request) {
if (config('lorekeeper.extensions.exclusionary_search')) {
// If exclusionary search is enabled, we need to make sure that the character has all of the subtypes specified.
$query->whereIn('character_image_subtypes.subtype_id', $request->get('subtype_ids'))->havingRaw('COUNT(*) = ?', [count($request->get('subtype_ids'))]);
} else {
// If exclusionary search is not enabled, any of the subtypes is acceptable.
if (config('lorekeeper.extensions.exclusionary_search')) {
$imageQuery->whereHas('subtypes', function ($query) use ($request) {
$subtypeIds = $request->get('subtype_ids');

// Filter to ensure the character has all the specified subtypes
$query->whereIn('character_image_subtypes.subtype_id', $subtypeIds)
->groupBy('character_image_subtypes.character_image_id')
->havingRaw('COUNT(character_image_subtypes.subtype_id) = ?', [count($subtypeIds)]);
})->whereDoesntHave('subtypes', function ($query) use ($request) {
$subtypeIds = $request->get('subtype_ids');

// Ensure that no additional subtypes are present
$query->whereNotIn('character_image_subtypes.subtype_id', $subtypeIds);
});
} else {
$imageQuery->whereHas('subtypes', function ($query) use ($request) {
$query->whereIn('character_image_subtypes.subtype_id', $request->get('subtype_ids'));
}
});
});
}
}
}
if ($request->get('feature_ids')) {
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Species/Subtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function getUrlAttribute() {
* @return string
*/
public function getSearchUrlAttribute() {
return url('masterlist?subtype_id='.$this->id);
return url('masterlist?subtype_ids[]='.$this->id);
}

/**
Expand Down
Loading

0 comments on commit 245fa04

Please sign in to comment.