Skip to content

Commit a32af41

Browse files
authored
feat: facets ordering (#631)
1 parent c8d3755 commit a32af41

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed

src/main/scala/algolia/objects/IndexSettings.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,7 @@ case class IndexSettings(
9999
ignorePlurals: Option[IgnorePlurals] = None,
100100
disableTypoToleranceOnAttributes: Option[Seq[String]] = None,
101101
disableTypoToleranceOnWords: Option[Seq[String]] = None,
102-
separatorsToIndex: Option[String] = None
102+
separatorsToIndex: Option[String] = None,
103+
/* Facets ordering */
104+
renderingContent: Option[RenderingContent] = None
103105
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016 Algolia
5+
* http://www.algolia.com/
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
package algolia.objects
27+
28+
/**
29+
* Content defining how the search interface should be rendered. This is set via the settings for a default value
30+
* and can be overridden via rules.
31+
*/
32+
case class RenderingContent(
33+
facetOrdering: Option[FacetOrdering] = None
34+
)
35+
36+
/**
37+
* Facets and facets values ordering rules container.
38+
*/
39+
case class FacetOrdering(
40+
facets: FacetsOrder,
41+
values: Map[String, FacetValuesOrder]
42+
)
43+
44+
/**
45+
* Define or override the way facet attributes are displayed.
46+
*/
47+
case class FacetsOrder(
48+
order: Seq[String]
49+
)
50+
51+
/**
52+
* Facet values ordering rule container.
53+
*/
54+
case class FacetValuesOrder(
55+
order: Seq[String],
56+
sortRemainingBy: Option[SortRule] = None
57+
)
58+
59+
/**
60+
* Rule defining the sort order of facet values.
61+
*/
62+
sealed trait SortRule {
63+
val value: String
64+
}
65+
66+
object SortRule {
67+
68+
/**
69+
* Alphabetical (ascending)
70+
*/
71+
case object alpha extends SortRule {
72+
override val value: String = "alpha"
73+
}
74+
75+
/**
76+
* Facet count (descending)
77+
*/
78+
case object count extends SortRule {
79+
override val value: String = "count"
80+
}
81+
82+
/**
83+
* Hidden (show only pinned values)
84+
*/
85+
case object hidden extends SortRule {
86+
override val value: String = "hidden"
87+
}
88+
}

src/main/scala/algolia/objects/Rule.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ case class Consequence(
4848
filterPromotes: Option[Boolean] = None,
4949
promote: Option[Iterable[ConsequencePromote]] = None,
5050
hide: Option[Iterable[ConsequenceHide]] = None,
51-
userData: Option[Map[String, Any]] = None
51+
userData: Option[Map[String, Any]] = None,
52+
renderingContent: Option[RenderingContent] = None
5253
)
5354

5455
case class ConsequencePromote(objectID: String, position: Int)

src/main/scala/algolia/responses/SearchResult.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
package algolia.responses
2727

28-
import algolia.objects.{AbstractSynonym, Rule}
28+
import algolia.objects.{AbstractSynonym, RenderingContent, Rule}
2929
import org.json4s._
3030

3131
private[algolia] trait SearchHits[A] {
@@ -59,7 +59,9 @@ case class SearchResult(
5959
processed: Option[Boolean],
6060
index: Option[String],
6161
// advanced
62-
explain: Option[Explain]
62+
explain: Option[Explain],
63+
// Facets ordering
64+
renderingContent: Option[RenderingContent]
6365
) {
6466

6567
implicit val formats: Formats = org.json4s.DefaultFormats

0 commit comments

Comments
 (0)