diff --git a/interweb-core/src/main/java/de/l3s/interweb/core/Results.java b/interweb-core/src/main/java/de/l3s/interweb/core/Results.java index d201603d..5d461184 100644 --- a/interweb-core/src/main/java/de/l3s/interweb/core/Results.java +++ b/interweb-core/src/main/java/de/l3s/interweb/core/Results.java @@ -6,7 +6,9 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +@JsonPropertyOrder({ "elapsed_time", "query", "results" }) @JsonInclude(JsonInclude.Include.NON_NULL) public class Results { /** @@ -14,6 +16,13 @@ public class Results { */ @JsonProperty("elapsed_time") private long elapsedTime; + + /** + * The query that was used to generate the results. + */ + @JsonProperty("query") + private Query query; + /** * The list of results from different connectors. */ @@ -27,6 +36,14 @@ public Results(Collection results) { add(results); } + public Query getQuery() { + return query; + } + + public void setQuery(Query query) { + this.query = query; + } + public long getElapsedTime() { return elapsedTime; } diff --git a/interweb-core/src/main/java/de/l3s/interweb/core/search/SearchItem.java b/interweb-core/src/main/java/de/l3s/interweb/core/search/SearchItem.java index cb6a0f03..fb5fdebf 100644 --- a/interweb-core/src/main/java/de/l3s/interweb/core/search/SearchItem.java +++ b/interweb-core/src/main/java/de/l3s/interweb/core/search/SearchItem.java @@ -10,9 +10,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import de.l3s.interweb.core.util.StringUtils; +@JsonPropertyOrder({ "rank", "id", "type", "url", "title", "description", "author", "author_url" }) @RegisterForReflection public class SearchItem implements Serializable { @Serial diff --git a/interweb-core/src/main/java/de/l3s/interweb/core/search/SearchQuery.java b/interweb-core/src/main/java/de/l3s/interweb/core/search/SearchQuery.java index a2ce740f..e1e884aa 100644 --- a/interweb-core/src/main/java/de/l3s/interweb/core/search/SearchQuery.java +++ b/interweb-core/src/main/java/de/l3s/interweb/core/search/SearchQuery.java @@ -12,10 +12,12 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import de.l3s.interweb.core.Query; @RegisterForReflection +@JsonPropertyOrder({ "id", "query", "services", "content_types", "extras", "date_from", "date_to", "page", "per_page", "lang", "sort", "timeout" }) @JsonIgnoreProperties(ignoreUnknown = false) public class SearchQuery extends Query { private String id; @@ -141,6 +143,7 @@ public void setPerPage(final Integer perPage) { this.perPage = perPage; } + @JsonIgnore public int getOffset() { if (page == null || perPage == null) { return 0; @@ -196,13 +199,12 @@ public boolean equals(final Object o) { && Objects.equals(extras, query1.extras); } - @Override public int hashCode() { - return Objects.hash(query, dateFrom, dateTo, language, getServices(), contentTypes, extras, page, perPage, sort); + return Objects.hash(query, dateFrom, dateTo, language, contentTypes, extras, page, perPage, sort, getServices()); } public int hashCodeWithoutPage() { - return Objects.hash(query, dateFrom, dateTo, language, getServices(), contentTypes, extras, perPage, sort); + return Objects.hash(query, dateFrom, dateTo, language, contentTypes, extras, perPage, sort, getServices()); } } diff --git a/interweb-server/src/main/java/de/l3s/interweb/server/chat/ChatResource.java b/interweb-server/src/main/java/de/l3s/interweb/server/chat/ChatResource.java index 50c536ff..657cceb2 100644 --- a/interweb-server/src/main/java/de/l3s/interweb/server/chat/ChatResource.java +++ b/interweb-server/src/main/java/de/l3s/interweb/server/chat/ChatResource.java @@ -51,8 +51,8 @@ public Uni completions(@Valid CompletionQuery query) { return getOrCreateChat(query).flatMap(chat -> { long start = System.currentTimeMillis(); return chatService.completions(query).call(results -> { - results.setElapsedTime(System.currentTimeMillis() - start); results.setChatId(chat.id); + results.setElapsedTime(System.currentTimeMillis() - start); return persistMessages(chat, query.getMessages(), results); }); }); diff --git a/interweb-server/src/main/java/de/l3s/interweb/server/describe/DescribeResource.java b/interweb-server/src/main/java/de/l3s/interweb/server/describe/DescribeResource.java index dd3ee2d0..189862e7 100644 --- a/interweb-server/src/main/java/de/l3s/interweb/server/describe/DescribeResource.java +++ b/interweb-server/src/main/java/de/l3s/interweb/server/describe/DescribeResource.java @@ -11,6 +11,7 @@ import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; +import io.quarkus.cache.CacheResult; import io.quarkus.security.Authenticated; import io.smallrye.mutiny.Uni; import org.jboss.resteasy.reactive.RestQuery; @@ -42,6 +43,7 @@ public Uni describe(@RestQuery String link, @POST @Authenticated + @CacheResult(cacheName = "describe") public Uni describe(@Valid DescribeQuery query) { describeService.validateServices(query.getServices()); if (StringUtils.isEmpty(query.getLink()) && (StringUtils.isEmpty(query.getId()) || query.getServices().isEmpty())) { diff --git a/interweb-server/src/main/java/de/l3s/interweb/server/search/SearchResource.java b/interweb-server/src/main/java/de/l3s/interweb/server/search/SearchResource.java index 927f5460..342553eb 100644 --- a/interweb-server/src/main/java/de/l3s/interweb/server/search/SearchResource.java +++ b/interweb-server/src/main/java/de/l3s/interweb/server/search/SearchResource.java @@ -3,6 +3,7 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import jakarta.inject.Inject; import jakarta.validation.Valid; @@ -15,6 +16,7 @@ import jakarta.ws.rs.Path; import jakarta.ws.rs.core.Context; +import io.quarkus.cache.CacheResult; import io.quarkus.security.Authenticated; import io.quarkus.security.identity.SecurityIdentity; import io.smallrye.mutiny.Uni; @@ -63,9 +65,13 @@ public Uni search(@Parameter(description = "The search query", ex @POST @Authenticated + @CacheResult(cacheName = "search") public Uni search(@NotNull @Valid SearchQuery query) { + query.setId(UUID.randomUUID().toString()); + long start = System.currentTimeMillis(); return searchService.search(query).map(results -> { + results.setQuery(query); results.setElapsedTime(System.currentTimeMillis() - start); return results; }); diff --git a/interweb-server/src/main/java/de/l3s/interweb/server/suggest/SuggestResource.java b/interweb-server/src/main/java/de/l3s/interweb/server/suggest/SuggestResource.java index 4b4dd870..4fed6d57 100644 --- a/interweb-server/src/main/java/de/l3s/interweb/server/suggest/SuggestResource.java +++ b/interweb-server/src/main/java/de/l3s/interweb/server/suggest/SuggestResource.java @@ -12,6 +12,7 @@ import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; +import io.quarkus.cache.CacheResult; import io.quarkus.security.Authenticated; import io.smallrye.mutiny.Uni; import org.jboss.resteasy.reactive.RestQuery; @@ -45,10 +46,12 @@ public Uni suggest(@NotEmpty @RestQuery String q, @POST @Authenticated + @CacheResult(cacheName = "suggest") public Uni suggest(@Valid SuggestQuery query) { long start = System.currentTimeMillis(); suggestService.validateServices(query.getServices()); return suggestService.suggest(query).map(results -> { + results.setQuery(query); results.setElapsedTime(System.currentTimeMillis() - start); return results; });