-
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.
WIP: query parsing, first draft done
- Loading branch information
Showing
7 changed files
with
125 additions
and
64 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
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
55 changes: 55 additions & 0 deletions
55
modules/search-query/src/main/scala/io/renku/search/query/parse/QueryUtil.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,55 @@ | ||
/* | ||
* 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.query.parse | ||
|
||
import io.renku.search.query.Query | ||
import io.renku.search.query.Query.Segment | ||
|
||
private[query] object QueryUtil { | ||
|
||
def collapse(q: Query): Query = | ||
Query(collapseTextSegments(q.segments)) | ||
|
||
private def collapseTextSegments(segs: List[Segment]): List[Segment] = { | ||
@annotation.tailrec | ||
def loop( | ||
in: List[Segment], | ||
curr: Option[Segment.Text], | ||
result: List[Segment] | ||
): List[Segment] = | ||
in match | ||
case first :: rest => | ||
(first, curr) match | ||
case (t1: Segment.Text, Some(tc)) => | ||
loop(rest, Some(tc ++ t1), result) | ||
|
||
case (e: Segment.Text, None) => | ||
loop(rest, Some(e), result) | ||
|
||
case (f: Segment.Field, Some(tc)) => | ||
loop(rest, None, f :: tc :: result) | ||
|
||
case (f: Segment.Field, None) => | ||
loop(rest, None, f :: result) | ||
|
||
case Nil => (curr.toList ::: result).reverse | ||
|
||
loop(segs, None, Nil) | ||
} | ||
} |
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