in src/main/scala/ophan/google/indexing/observatory/GoogleSearchService.scala [45:72]
def contentAvailabilityInGoogleIndex(uri: URI, site: Site): Future[CheckReport] = Future {
blocking {
val baseUrl = s"https://discoveryengine.googleapis.com/v1/projects/$projectId/locations/$location/dataStores/${site.datastoreId}/servingConfigs/default_config:searchLite"
val requestBody = ujson.Obj(
"query" -> GoogleSearchService.reliableSearchTermFor(uri),
"pageSize" -> 10
)
val request = HttpRequest.newBuilder()
.uri(URI.create(s"$baseUrl?key=$apiKey"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(requestBody.toString()))
.build()
val attemptExecute = Try {
val response = httpClient.send(request, java.net.http.HttpResponse.BodyHandlers.ofString())
val searchResponse = read[SearchResponse](response.body())
println(s"searchResponse for $uri $searchResponse")
searchResponse.results.exists(result => GoogleSearchService.resultMatches(uri, result))
}
if (attemptExecute.isSuccess)
logger.debug(s"Successful request for ${site.url}")
CheckReport(Instant.now, accessGoogleIndex = attemptExecute)
}
}