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

Avoid notices when fields/weights are not as expected #1530

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion includes/classes/Feature/Search/Weighting.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ public function recursively_inject_weights_to_fields( &$fieldset, $weights ) {
}

if ( is_array( $fieldset ) && isset( $fieldset['fields'] ) ) {
if ( ! is_array( $fieldset['fields'] ) ) {
$fieldset['fields'] = [];
}
// Add any fields to the search that aren't already in there (weighting handled in next step)
foreach ( $weights as $field => $settings ) {
if ( ! in_array( $field, $fieldset['fields'], true ) ) {
Expand Down Expand Up @@ -386,7 +389,7 @@ public function recursively_inject_weights_to_fields( &$fieldset, $weights ) {
// else: Leave anything that isn't explicitly disabled alone. Could have been added by search_fields, and if it is not present in the UI, we shouldn't touch it here

// If fieldset has fuzziness enabled and fuzziness is disabled for this field, unset the field
if ( isset( $fieldset['fuzziness'] ) && $fieldset['fuzziness'] && isset( $weights[ $field ]['fuzziness'] ) && false === $weights[ $field ]['fuzziness'] ) {
if ( isset( $fieldset['fuzziness'] ) && $fieldset['fuzziness'] && isset( $weights[ $field ] ) && isset( $weights[ $field ]['fuzziness'] ) && false === $weights[ $field ]['fuzziness'] ) {
unset( $fieldset['fields'][ $key ] );
}
}
Expand Down