Skip to content

Commit

Permalink
feat(dynamic facets): facet ordering support (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
aallam authored Jul 20, 2021
1 parent ddbec57 commit 53dc256
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.algolia.search.models.indexing;

import com.algolia.search.models.rules.RenderingContent;
import com.algolia.search.util.AlgoliaUtils;
import com.fasterxml.jackson.annotation.JsonSetter;
import java.io.Serializable;
Expand Down Expand Up @@ -31,6 +32,7 @@ public class SearchResult<T> implements Serializable {
private Boolean exhaustiveNbHits;
private Integer appliedRelevancyStrictness;
private Integer nbSortedHits;
private RenderingContent renderingContent;

public Explain getExplain() {
return explain;
Expand Down Expand Up @@ -131,6 +133,15 @@ public SearchResult<T> setQueryAfterRemoval(String queryAfterRemoval) {
return this;
}

public RenderingContent getRenderingContent() {
return renderingContent;
}

public SearchResult<T> setRenderingContent(RenderingContent renderingContent) {
this.renderingContent = renderingContent;
return this;
}

private Long offset;
private Long length;
private String parsedQuery;
Expand Down Expand Up @@ -384,6 +395,9 @@ public String toString() {
+ '\''
+ ", nbSortedHits="
+ nbSortedHits
+ '\''
+ ", renderingContent="
+ renderingContent
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ public ConsequenceParams setAutomaticOptionalFacetFilters(
return this;
}

public RenderingContent getRenderingContent() {
return renderingContent;
}

public ConsequenceParams setRenderingContent(RenderingContent renderingContent) {
this.renderingContent = renderingContent;
return this;
}

private RenderingContent renderingContent;
private ConsequenceQuery query;

@JsonDeserialize(using = AutomaticFacetFilterDeserializer.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.algolia.search.models.rules;

import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.util.Map;
import java.util.Objects;

/** Facets and facets values ordering rules container. */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FacetOrdering implements Serializable {
private FacetsOrder facets;
private Map<String, FacetValuesOrder> values;

public FacetOrdering() {}

public FacetOrdering(FacetsOrder facets, Map<String, FacetValuesOrder> values) {
this.facets = facets;
this.values = values;
}

public FacetsOrder getFacets() {
return facets;
}

public FacetOrdering setFacets(FacetsOrder facets) {
this.facets = facets;
return this;
}

public Map<String, FacetValuesOrder> getValues() {
return values;
}

public FacetOrdering setValues(Map<String, FacetValuesOrder> values) {
this.values = values;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof FacetOrdering)) return false;
FacetOrdering that = (FacetOrdering) o;
return Objects.equals(facets, that.facets) && Objects.equals(values, that.values);
}

@Override
public int hashCode() {
return Objects.hash(facets, values);
}

@Override
public String toString() {
return "FacetOrdering{" + "facets=" + facets + ", values=" + values + '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.algolia.search.models.rules;

import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/** Facet values ordering rule container. */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FacetValuesOrder implements Serializable {
private List<String> order;
private String sortRemainingBy;

public FacetValuesOrder() {}

public FacetValuesOrder(List<String> order, String sortRemainingBy) {
this.order = order;
this.sortRemainingBy = sortRemainingBy;
}

public List<String> getOrder() {
return order;
}

public FacetValuesOrder setOrder(List<String> order) {
this.order = order;
return this;
}

public String getSortRemainingBy() {
return sortRemainingBy;
}

public FacetValuesOrder setSortRemainingBy(String sortRemainingBy) {
this.sortRemainingBy = sortRemainingBy;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof FacetValuesOrder)) return false;
FacetValuesOrder that = (FacetValuesOrder) o;
return Objects.equals(order, that.order)
&& Objects.equals(sortRemainingBy, that.sortRemainingBy);
}

@Override
public int hashCode() {
return Objects.hash(order, sortRemainingBy);
}

@Override
public String toString() {
return "FacetValuesOrder{"
+ "order="
+ order
+ ", sortRemainingBy='"
+ sortRemainingBy
+ '\''
+ '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.algolia.search.models.rules;

import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/** Define or override the way facet attributes are displayed. */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FacetsOrder implements Serializable {
private List<String> order;

public FacetsOrder() {}

public FacetsOrder(List<String> order) {
this.order = order;
}

public List<String> getOrder() {
return order;
}

public FacetsOrder setOrder(List<String> order) {
this.order = order;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof FacetsOrder)) return false;
FacetsOrder that = (FacetsOrder) o;
return Objects.equals(order, that.order);
}

@Override
public int hashCode() {
return Objects.hash(order);
}

@Override
public String toString() {
return "FacetsOrder{" + "order=" + order + '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.algolia.search.models.rules;

import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.util.Objects;

/**
* Content defining how the search interface should be rendered. This is set via the settings for a
* default value and can be overridden via rules.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RenderingContent implements Serializable {
private FacetOrdering facetOrdering;

public RenderingContent() {}

public RenderingContent(FacetOrdering facetOrdering) {
this.facetOrdering = facetOrdering;
}

public FacetOrdering getFacetOrdering() {
return facetOrdering;
}

public RenderingContent setFacetOrdering(FacetOrdering facetOrdering) {
this.facetOrdering = facetOrdering;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof RenderingContent)) return false;
RenderingContent that = (RenderingContent) o;
return Objects.equals(facetOrdering, that.facetOrdering);
}

@Override
public int hashCode() {
return Objects.hash(facetOrdering);
}

@Override
public String toString() {
return "RenderingContent{" + "facetOrdering=" + facetOrdering + '}';
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package com.algolia.search.models.settings;

import com.fasterxml.jackson.annotation.*;
import com.algolia.search.models.rules.RenderingContent;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -104,6 +111,9 @@ public class IndexSettings implements Serializable {
/* Virtual Indices */
protected Integer relevancyStrictness;

/* Facets Ordering */
private RenderingContent renderingContent;

public List<String> getAttributesForFaceting() {
return attributesForFaceting;
}
Expand Down Expand Up @@ -712,6 +722,15 @@ public IndexSettings setRelevancyStrictness(Integer relevancyStrictness) {
return this;
}

public RenderingContent getRenderingContent() {
return renderingContent;
}

public IndexSettings setRenderingContent(RenderingContent renderingContent) {
this.renderingContent = renderingContent;
return this;
}

@Override
public String toString() {
return "IndexSettings{"
Expand Down Expand Up @@ -826,6 +845,9 @@ public String toString() {
+ '\''
+ ", decompoundQuery="
+ decompoundQuery
+ '\''
+ ", renderingContent="
+ renderingContent
+ '}';
}
}

0 comments on commit 53dc256

Please sign in to comment.