Skip to content

Commit

Permalink
Merge pull request #268 from lichess-org/do-not-try-to-parse-when-fil…
Browse files Browse the repository at this point in the history
…tered-key-is-empty

Do not try to parse when filteredKey is empty
  • Loading branch information
lenguyenthanh authored Jul 17, 2024
2 parents f047dd3 + b87e990 commit b474363
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions modules/elastic/src/main/scala/Queryable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ object QueryParser:
def apply(q: String, filterKeys: Seq[String]): ParsedQuery =

val terms = spaceRegex.split(q.trim.toLowerCase).toList

terms.foldLeft(ParsedQuery(Nil, Map.empty)) { case (parsed, term) =>
filterKeys
.collectFirst {
case fk if term.startsWith(s"$fk:") =>
parsed.copy(
filters = parsed.filters + (fk -> term.drop(fk.size + 1))
)
}
.getOrElse(parsed.copy(terms = parsed.terms :+ term))
}
if filterKeys.isEmpty then ParsedQuery(terms, Map.empty)
else
terms.foldLeft(ParsedQuery(Nil, Map.empty)): (parsed, term) =>
filterKeys
.collectFirst:
case fk if term.startsWith(s"$fk:") =>
parsed.copy(filters = parsed.filters + (fk -> term.drop(fk.size + 1)))
.getOrElse(parsed.copy(terms = parsed.terms :+ term))

0 comments on commit b474363

Please sign in to comment.