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

feat: facets ordering #631

Merged
merged 3 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion src/main/scala/algolia/objects/IndexSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,7 @@ case class IndexSettings(
ignorePlurals: Option[IgnorePlurals] = None,
disableTypoToleranceOnAttributes: Option[Seq[String]] = None,
disableTypoToleranceOnWords: Option[Seq[String]] = None,
separatorsToIndex: Option[String] = None
separatorsToIndex: Option[String] = None,
/* Facets ordering */
renderingContent: Option[RenderingContent] = None
)
88 changes: 88 additions & 0 deletions src/main/scala/algolia/objects/RenderingContent.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Algolia
* http://www.algolia.com/
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package algolia.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.
*/
case class RenderingContent(
facetOrdering: Option[FacetOrdering] = None
)

/**
* Facets and facets values ordering rules container.
*/
case class FacetOrdering(
facets: FacetsOrder,
values: Map[String, FacetValuesOrder]
)

/**
* Define or override the way facet attributes are displayed.
*/
case class FacetsOrder(
order: Seq[String]
)

/**
* Facet values ordering rule container.
*/
case class FacetValuesOrder(
order: Seq[String] = Seq.empty,
sortRemainingBy: SortRule = SortRule.count
aallam marked this conversation as resolved.
Show resolved Hide resolved
)

/**
* Rule defining the sort order of facet values.
*/
sealed trait SortRule {
val value: String
}

object SortRule {

/**
* Alphabetical (ascending)
*/
case object alpha extends SortRule {
override val value: String = "alpha"
}

/**
* Facet count (descending)
*/
case object count extends SortRule {
override val value: String = "count"
}

/**
* Hidden (show only pinned values)
*/
case object hidden extends SortRule {
override val value: String = "hidden"
}
}
3 changes: 2 additions & 1 deletion src/main/scala/algolia/objects/Rule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ case class Consequence(
filterPromotes: Option[Boolean] = None,
promote: Option[Iterable[ConsequencePromote]] = None,
hide: Option[Iterable[ConsequenceHide]] = None,
userData: Option[Map[String, Any]] = None
userData: Option[Map[String, Any]] = None,
renderingContent: Option[RenderingContent] = None
)

case class ConsequencePromote(objectID: String, position: Int)
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/algolia/responses/SearchResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

package algolia.responses

import algolia.objects.{AbstractSynonym, Rule}
import algolia.objects.{AbstractSynonym, RenderingContent, Rule}
import org.json4s._

private[algolia] trait SearchHits[A] {
Expand Down Expand Up @@ -59,7 +59,9 @@ case class SearchResult(
processed: Option[Boolean],
index: Option[String],
// advanced
explain: Option[Explain]
explain: Option[Explain],
// Facets ordering
renderingContent: Option[RenderingContent]
) {

implicit val formats: Formats = org.json4s.DefaultFormats
Expand Down