Skip to content

Commit c434622

Browse files
committed
Add Kdoc for relevance helper
1 parent 53c9e71 commit c434622

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/commonMain/kotlin/com/algolia/search/endpoint/EndpointSearch.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ public interface EndpointSearch {
123123
requestOptions: RequestOptions? = null
124124
): ResponseSearch
125125

126+
/**
127+
* Search iteratively through the search response [ResponseSearch.hits] field to find the first response hit tha
128+
* would match against the give [match] function.
129+
* If no object has been found within the first result set, the function
130+
* will perform a new search operation on the next page of results, if any,
131+
* until a matching object is found or the end of results, whichever
132+
* happens first.
133+
* [doNotPaginate] will stop the function at the end of the first page of search results even if no object does
134+
* match.
135+
*
136+
* @param match Predicate to match a given [ResponseSearch.Hit]
137+
* @param query The [Query] used to search.
138+
* @param doNotPaginate To prevent the iteration through pages of results.
139+
* @param requestOptions Configure request locally with [RequestOptions].
140+
*/
126141
tailrec suspend fun findFirstObject(
127142
match: (ResponseSearch.Hit) -> Boolean,
128143
query: Query = Query(),

src/commonMain/kotlin/com/algolia/search/model/response/ResponseSearch.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import com.algolia.search.model.settings.Settings
1111
import com.algolia.search.serialize.*
1212
import kotlinx.serialization.*
1313
import kotlinx.serialization.json.JsonElement
14-
import kotlinx.serialization.json.JsonLiteral
1514
import kotlinx.serialization.json.JsonObject
1615

1716

@@ -274,6 +273,10 @@ public data class ResponseSearch(
274273
public val hierarchicalFacets: Map<Attribute, List<Facet>>
275274
get() = hierarchicalFacetsOrNull!!
276275

276+
/**
277+
* Returns the position (0-based) within the [hits] result list of the record matching against the given [objectID].
278+
* If the [objectID] is not found, -1 is returned.
279+
*/
277280
public fun getObjectIDPosition(objectID: ObjectID): Int {
278281
return hits.indexOfFirst { it.json.getPrimitiveOrNull("objectID")?.content == objectID.raw }
279282
}

0 commit comments

Comments
 (0)