All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.nemerosa.ontrack.kdsl.spec.search.SearchOntrackExtensions.kt Maven / Gradle / Ivy

There is a newer version: 4.4.5
Show newest version
package net.nemerosa.ontrack.kdsl.spec.search

import net.nemerosa.ontrack.kdsl.connector.graphql.paginate
import net.nemerosa.ontrack.kdsl.connector.graphql.schema.SearchQuery
import net.nemerosa.ontrack.kdsl.connector.graphqlConnector
import net.nemerosa.ontrack.kdsl.connector.support.PaginatedList
import net.nemerosa.ontrack.kdsl.connector.support.emptyPaginatedList
import net.nemerosa.ontrack.kdsl.spec.Ontrack

fun Ontrack.search(token: String): PaginatedList =
    graphqlConnector.query(
        SearchQuery(token, 40)
    )?.paginate(
        pageInfo = { it.search()?.pageInfo()?.fragments()?.pageInfoContent() },
        pageItems = { it.search()?.pageItems() }
    )?.map {
        SearchResult(
            title = it.title() ?: "",
            description = it.description() ?: "",
            accuracy = it.accuracy() ?: 0.0,
            type = SearchResultType(
                feature = it.type()?.feature()?.id() ?: "",
                id = it.type()?.id() ?: "",
                name = it.type()?.name() ?: "",
                description = it.type()?.description() ?: "",
            ),
        )
    } ?: emptyPaginatedList()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy