cozydev-pink / protosearch

prototype search library in pure scala
https://cozydev-pink.github.io/protosearch/
Apache License 2.0
9 stars 6 forks source link

Search schema #30

Closed valencik closed 1 year ago

valencik commented 1 year ago

This PR adds a minor new class SearchSchema

    val searchSchema = SearchSchema[Repo](
      ("name", _.name, analyzer),
      ("fullName", _.fullName, analyzer),
      ("description", _.description.getOrElse(""), analyzer),
      ("topics", _.topics.mkString(" "), analyzer),
    )

It allows search applications like RepoSearch to specify the mapping of field names to getters and analyzers only once. This is a pretty minor addition that I'd like to keep tweaking, but I figured I'd keep the PRs small and moving instead.

valencik commented 1 year ago

Had to revert the mapping style construction, as it only works nicely in Scala 3.

In Scala 2.13 we get:

too many arguments (found 2, expected 1) for method ->: (y: B): (String, B)
[error]     "title" -> (_.title, analyzer),

And if you throw more parens around the tuple you lose type inference:

missing parameter type for expanded function ((<x$2: error>) => x$2.title)
[error]     "title" -> ((_.title, analyzer)),