-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
899 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 42 additions & 3 deletions
45
...iasearch-common/src/main/java/com/algolia/search/inputs/query_rules/ConsequenceQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,46 @@ | ||
package com.algolia.search.inputs.query_rules; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.algolia.search.Defaults; | ||
import com.algolia.search.objects.Edit; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.ObjectCodec; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonDeserialize(using = ConsequenceQueryDeserializer.class) | ||
public abstract class ConsequenceQuery implements Serializable { | ||
} | ||
|
||
class ConsequenceQueryDeserializer extends JsonDeserializer<ConsequenceQuery> { | ||
@Override | ||
public ConsequenceQuery deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { | ||
ObjectCodec oc = jp.getCodec(); | ||
JsonNode node = oc.readTree(jp); | ||
ObjectMapper objectMapper = Defaults.DEFAULT_OBJECT_MAPPER; | ||
|
||
if(node.has("edits")){ | ||
ObjectReader reader = objectMapper.readerFor(new TypeReference<List<Edit>>() { | ||
}); | ||
List<Edit> list = reader.readValue(node.get("edits")); | ||
return new ConsequenceQueryObject().setEdits(list); | ||
} | ||
else if(node.has("remove")){ | ||
ObjectReader reader = objectMapper.readerFor(new TypeReference<List<String>>() { | ||
}); | ||
|
||
List<String> list = reader.readValue(node.get("remove")); | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public abstract class ConsequenceQuery implements Serializable {} | ||
return new ConsequenceQueryObject().setRemove(list); | ||
} | ||
else { | ||
return new ConsequenceQueryString(node.asText()); // not sure it's not even possible to save a rule like that | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ch-common/src/main/java/com/algolia/search/inputs/query_rules/ConsequenceQueryObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
package com.algolia.search.inputs.query_rules; | ||
|
||
import com.algolia.search.objects.Edit; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import java.util.List; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class ConsequenceQueryObject extends ConsequenceQuery { | ||
|
||
private List<String> remove; | ||
private List<Edit> edits; | ||
|
||
public ConsequenceQueryObject() {} | ||
|
||
@Deprecated | ||
public List<String> getRemove() { | ||
return remove; | ||
} | ||
|
||
/** | ||
* Old features use edits instead | ||
*/ | ||
@Deprecated | ||
public ConsequenceQueryObject setRemove(List<String> remove) { | ||
this.remove = remove; | ||
return this; | ||
} | ||
|
||
public List<Edit> getEdits() { | ||
return edits; | ||
} | ||
|
||
public ConsequenceQueryObject setEdits(List<Edit> edits) { | ||
this.edits = edits; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.