Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump guzzlehttp/psr7 from 1.8.3 to 2.4.3 #48

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
4 changes: 2 additions & 2 deletions app/Console/Commands/Import/ImportCollectionsFull.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ protected function importEndpoint($endpoint, $page = 1)
{
$model = $this->getModelForEndpoint($endpoint);

if (!$this->isPartial) {
if (!$this->isPartial && app('Resources')->isModelSearchable($model)) {
$model::disableSearchSyncing();
}

$this->import('Collections', $model, $endpoint, $page);

if (!$this->isPartial) {
if (!$this->isPartial && app('Resources')->isModelSearchable($model)) {
$model::enableSearchSyncing();
}
}
Expand Down
15 changes: 10 additions & 5 deletions app/Http/Search/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,16 @@ public function getBaseParams(array $input)
// Make resources into a Laravel collection
$resources = collect($resources);

// If more artworks are being searched alongside other resource types, disbale artworks boost
$artworksUseBoost = true;
if ($resources->contains('artworks') && $resources->count() > 1) {
$artworksUseBoost = false;
}

// Grab settings from our models via the service provider
$settings = $resources->map(function ($resource) {
$settings = $resources->map(function ($resource) use ($artworksUseBoost) {
return [
$resource => app('Search')->getSearchScopeForEndpoint($resource),
$resource => app('Search')->getSearchScopeForEndpoint($resource, $resource == 'artworks' ? $artworksUseBoost : null),
];
})->collapse();

Expand Down Expand Up @@ -330,6 +336,7 @@ public function getSearchParams($input = null, $withAggregations = true)
* 2. If `q` is present, add full-text search to the `must` clause.
* 3. If `q` is absent, show all results.
*/

if (isset($input['query'])) {
$params = $this->addFullSearchParams($params, $input);
}
Expand Down Expand Up @@ -817,9 +824,7 @@ private function addFullSearchParams(array $params, array $input)
{
// TODO: Validate `query` input to reduce shenanigans
// TODO: Deep-find `fields` in certain queries + replace them w/ our custom field list
$params['body']['query']['bool']['must'][] = [
Arr::get($input, 'query'),
];
$params['body']['query']['bool']['must'][] = Arr::get($input, 'query');

return $params;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Search/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private function paginate()
// This method should not be used for endpoints that return no results

// LengthAwarePaginator has trouble here
$total = $this->searchResponse['hits']['total'];
$total = $this->searchResponse['hits']['total']['value'] ?? 0;
$limit = $this->searchParams['size'] ?? 10;
$offset = $this->searchParams['from'] ?? 0;

Expand Down
2 changes: 1 addition & 1 deletion app/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static function addRestrictContentScopes($isDump = false)

// For present and future exhibitions, only show if they're published on the web
// WEB-1419: Using subquery here instead of join to avoid field overrides
$builder->orWhereIn('id', function ($query) {
$builder->orWhereIn('exhibitions.id', function ($query) {
$query->select('datahub_id')
->from('web_exhibitions');
});
Expand Down
23 changes: 23 additions & 0 deletions app/Models/Collections/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ public static function searchScopeArtists()
];
}

/**
* Add relevancy tweaks to agents.
*
* @return array
*/
public static function searchBoostAgents()
{
return [
// Boost agents that are artists
'term' => [
'is_artist' => true,
],

// Boost agents that have an image
'exists' => [
'field' => 'image_id',
],

'terms' => [
'id' => $this->boostedIds(),
]
];
}
/**
* API-341: Needed for the mobile app. Our mobile app frontends query `api/v1/autocomplete`,
* which uses the `suggest_autocomplete_boosted` field. Per the `filter` on that field in
Expand Down
6 changes: 2 additions & 4 deletions app/Models/Collections/Artwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,8 @@ public static function searchBoostArtworks()
{
return [
// Boost anything that has an image
[
'exists' => [
'field' => 'image_id',
],
'exists' => [
'field' => 'image_id',
],
];
}
Expand Down
15 changes: 15 additions & 0 deletions app/Models/Collections/Exhibition.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ public function isBoosted()
return $this->webExhibition->is_featured ?? false;
}

/**
* Add relevancy tweaks to exhibitions.
*
* @return array
*/
public static function searchBoostExhibitions()
{
return [
// Boost anything that has an image
'exists' => [
'field' => 'image_id',
],
];
}

public function getDateAicStartAttribute($value)
{
return $this->webExhibition->public_start_at ?? $this->castAttribute('date_aic_start', $value);
Expand Down
4 changes: 1 addition & 3 deletions app/Models/ElasticSearchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ public function elasticsearchMapping()

// Now bring it all together
return [
$this->searchableType() => [
'properties' => $default,
],
'properties' => $default,
];
}

Expand Down
32 changes: 15 additions & 17 deletions app/Providers/SearchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function updateElasticsearchConfig()
* @param string $endpoint
* @return array
*/
public function getSearchScopeForEndpoint($endpoint)
public function getSearchScopeForEndpoint($endpoint, $useBoost = true)
{
$model = app('Resources')->getModelForEndpoint($endpoint);

Expand All @@ -253,21 +253,23 @@ public function getSearchScopeForEndpoint($endpoint)
$settings['scope'] = $this->getScopedQuery($resource, $scope);
}

// ex. `searchBoostArtworks` for `artworks` endpoint boosts `is_on_view`
$searchBoostMethod = 'searchBoost' . Str::studly($endpoint);
if ($useBoost) {
// ex. `searchBoostArtworks` for `artworks` endpoint boosts `is_on_view`
$searchBoostMethod = 'searchBoost' . Str::studly($endpoint);

if (method_exists($model, $searchBoostMethod)) {
$boost = $model::$searchBoostMethod();
if (method_exists($model, $searchBoostMethod)) {
$boost = $model::$searchBoostMethod();

$settings['boost'] = $this->getScopedQuery($resource, $boost);
}
$settings['boost'] = $this->getScopedQuery($resource, $boost);
}

// ex. `searchFunctionScoreArtworks` for `artworks` endpoint applies `pageviews` and `boost_rank`
$searchFunctionScoreMethod = 'searchFunctionScore' . Str::studly($endpoint);
// ex. `searchFunctionScoreArtworks` for `artworks` endpoint applies `pageviews` and `boost_rank`
$searchFunctionScoreMethod = 'searchFunctionScore' . Str::studly($endpoint);

if (method_exists($model, $searchFunctionScoreMethod)) {
// TODO: Inject `getScopedQuery` into the filter..?
$settings['function_score'] = $model::$searchFunctionScoreMethod();
if (method_exists($model, $searchFunctionScoreMethod)) {
// TODO: Inject `getScopedQuery` into the filter..?
$settings['function_score'] = $model::$searchFunctionScoreMethod();
}
}

return $settings;
Expand All @@ -289,17 +291,13 @@ public function getScopedQuery($resource, $scope)
];
}

if (Arr::isAssoc($scope)) {
$scope = [$scope];
}

return [
'bool' => [
'should' => [
[
'bool' => [
'must' => [
[$query],
$query,
$scope,
],
],
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"php": "^7.3|^8.0",
"aic/data-hub-foundation": "dev-laravel-8-support",
"aic/laravel-scout-elastic": "dev-master",
"cviebrock/laravel-elasticsearch": "^8.0",
"cviebrock/laravel-elasticsearch": "^9.0",
"fruitcake/laravel-cors": "^2.0",
"intervention/image": "^2.7",
"jsq/amazon-es-php": "dev-master",
Expand Down
63 changes: 36 additions & 27 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading