-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add entity-type facets to search results (#47)
- allow to specify facet queries in solr-client - use it to provide a simple result count per entity-type in current search
- Loading branch information
Showing
24 changed files
with
616 additions
and
60 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
49 changes: 49 additions & 0 deletions
49
modules/search-api/src/main/scala/io/renku/search/api/data/FacetData.scala
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.search.api.data | ||
|
||
import io.renku.search.model.EntityType | ||
import io.bullet.borer.Decoder | ||
import io.bullet.borer.derivation.MapBasedCodecs | ||
import sttp.tapir.Schema | ||
import io.bullet.borer.Encoder | ||
import io.renku.search.api.tapir.SchemaSyntax.* | ||
|
||
final case class FacetData( | ||
entityType: Map[EntityType, Int] | ||
) | ||
|
||
object FacetData: | ||
val empty: FacetData = FacetData(Map.empty) | ||
|
||
given Decoder[FacetData] = MapBasedCodecs.deriveDecoder | ||
given Encoder[FacetData] = MapBasedCodecs.deriveEncoder | ||
given Schema[FacetData] = { | ||
given Schema[Map[EntityType, Int]] = Schema.schemaForMap(_.name) | ||
Schema | ||
.derived[FacetData] | ||
.jsonExample( | ||
FacetData( | ||
Map( | ||
EntityType.Project -> 15, | ||
EntityType.User -> 3 | ||
) | ||
) | ||
) | ||
} |
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ import io.bullet.borer.* | |
import io.bullet.borer.NullOptions.given | ||
import io.bullet.borer.derivation.MapBasedCodecs.{deriveAllCodecs, deriveCodec} | ||
import io.renku.search.model.* | ||
import io.renku.search.api.tapir.SchemaSyntax.* | ||
import sttp.tapir.Schema.SName | ||
import sttp.tapir.SchemaType.{SCoproduct, SDateTime, SProductField, SRef} | ||
import sttp.tapir.generic.Configuration | ||
|
@@ -54,20 +55,18 @@ object Project: | |
private given Schema[projects.CreationDate] = Schema(SDateTime()) | ||
given Schema[Project] = Schema | ||
.derived[Project] | ||
.encodedExample( | ||
Json.encode { | ||
Project( | ||
projects.Id("01HRA7AZ2Q234CDQWGA052F8MK"), | ||
projects.Name("renku"), | ||
projects.Slug("renku"), | ||
Seq(projects.Repository("https://github.com/renku")), | ||
projects.Visibility.Public, | ||
Some(projects.Description("Renku project")), | ||
UserId(users.Id("1CAF4C73F50D4514A041C9EDDB025A36")), | ||
projects.CreationDate(Instant.now), | ||
Some(1.0) | ||
).asInstanceOf[SearchEntity] | ||
}.toUtf8String | ||
.jsonExample( | ||
Project( | ||
projects.Id("01HRA7AZ2Q234CDQWGA052F8MK"), | ||
projects.Name("renku"), | ||
projects.Slug("renku"), | ||
Seq(projects.Repository("https://github.com/renku")), | ||
projects.Visibility.Public, | ||
Some(projects.Description("Renku project")), | ||
UserId(users.Id("1CAF4C73F50D4514A041C9EDDB025A36")), | ||
projects.CreationDate(Instant.now), | ||
Some(1.0) | ||
): SearchEntity | ||
) | ||
|
||
final case class UserId(id: users.Id) | ||
|
@@ -77,9 +76,7 @@ object UserId: | |
private given Schema[users.Id] = Schema.string[users.Id] | ||
given Schema[UserId] = Schema | ||
.derived[UserId] | ||
.encodedExample( | ||
Json.encode(UserId(users.Id("01HRA7AZ2Q234CDQWGA052F8MK"))).toUtf8String | ||
) | ||
.jsonExample(UserId(users.Id("01HRA7AZ2Q234CDQWGA052F8MK"))) | ||
|
||
final case class User( | ||
id: users.Id, | ||
|
@@ -96,16 +93,14 @@ object User: | |
private given Schema[users.Email] = Schema.string[users.Email] | ||
given Schema[User] = Schema | ||
.derived[User] | ||
.encodedExample( | ||
Json.encode { | ||
User( | ||
users.Id("1CAF4C73F50D4514A041C9EDDB025A36"), | ||
Some(users.FirstName("Albert")), | ||
Some(users.LastName("Einstein")), | ||
Some(users.Email("[email protected]")), | ||
Some(2.1) | ||
).asInstanceOf[SearchEntity] | ||
}.toUtf8String | ||
.jsonExample( | ||
User( | ||
users.Id("1CAF4C73F50D4514A041C9EDDB025A36"), | ||
Some(users.FirstName("Albert")), | ||
Some(users.LastName("Einstein")), | ||
Some(users.Email("[email protected]")), | ||
Some(2.1) | ||
): SearchEntity | ||
) | ||
|
||
object SearchEntity: | ||
|
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
31 changes: 31 additions & 0 deletions
31
modules/search-api/src/main/scala/io/renku/search/api/tapir/SchemaSyntax.scala
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.search.api.tapir | ||
|
||
import io.bullet.borer.Encoder | ||
import io.bullet.borer.Json | ||
import sttp.tapir.Schema | ||
|
||
trait SchemaSyntax: | ||
|
||
extension [T](self: Schema[T]) | ||
def jsonExample[TT >: T](value: TT)(using Encoder[TT]): Schema[T] = | ||
self.encodedExample(Json.encode(value).toUtf8String) | ||
|
||
object SchemaSyntax extends SchemaSyntax |
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
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
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
42 changes: 42 additions & 0 deletions
42
modules/solr-client/src/main/scala/io/renku/solr/client/facet/Facet.scala
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.solr.client.facet | ||
|
||
import io.renku.solr.client.schema.FieldName | ||
import cats.data.NonEmptyList | ||
|
||
enum Facet: | ||
// https://solr.apache.org/guide/solr/latest/query-guide/json-facet-api.html#terms-facet | ||
case Terms( | ||
name: FieldName, | ||
field: FieldName, | ||
limit: Option[Int] = None, | ||
minCount: Option[Int] = None, | ||
method: Option[FacetAlgorithm] = None, | ||
missing: Boolean = false, | ||
numBuckets: Boolean = false, | ||
allBuckets: Boolean = false | ||
) | ||
|
||
// https://solr.apache.org/guide/solr/latest/query-guide/json-facet-api.html#range-facet | ||
case ArbitraryRange( | ||
name: FieldName, | ||
field: FieldName, | ||
ranges: NonEmptyList[FacetRange] | ||
) |
Oops, something went wrong.