-
Notifications
You must be signed in to change notification settings - Fork 74
Open
Description
Description
The rules search endpoint in case of a single condition being present returns a condition field:
$ curl --request POST \
--url https://APP_ID.algolia.net/1/indexes/INDEX/rules/search \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-algolia-api-key: API_KEY' \
--header 'x-algolia-application-id: APP_ID' \
--data '{"query":""}'
{"hits":[{"_metadata":{"lastUpdate":1599137775},"condition":{"pattern":"some name","anchoring":"is"},"consequence":{"params":{"filters":"name:'some other name'"}},"description":"","enabled":true,"objectID":"123","_highlightResult":{"condition":{"pattern":{"value":"some name","matchLevel":"none","matchedWords":[]}},"consequence":{"params":{"filters":{"value":"name:'some other name'","matchLevel":"none","matchedWords":[]}}},"description":{"value":"","matchLevel":"none","matchedWords":[]}}}],"nbHits":1,"page":0,"nbPages":1}The Rule class always expects a conditions array:
| :conditions => :"Array<Condition>", |
This makes us retrieve conditionless rules in cases where there is a single condition.
We can monkeypatch it with:
module AlgoliaSearchRuleAttributesFix
def self.prepended(base)
base.singleton_class.prepend ClassMethods
end
module ClassMethods
def build_from_hash(attributes)
attributes = attributes.transform_keys(&:to_sym)
if attributes.key?(:condition)
(attributes[:conditions] ||= []) << attributes.delete(:condition)
end
super attributes
end
end
end
Algolia::Search::Rule.prepend AlgoliaSearchRuleAttributesFixBut the fix would be to make the api consistent in case of a single or multiple conditions
Client
Search
Version
3.34.4
Relevant log output
Metadata
Metadata
Assignees
Labels
No labels