|
| 1 | +/* |
| 2 | + * Copyright © 2015 Integrated Knowledge Management (support@ikm.dev) |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package dev.ikm.tinkar.common.service; |
| 17 | + |
| 18 | +import java.util.List; |
| 19 | +import java.util.UUID; |
| 20 | + |
| 21 | +/** |
| 22 | + * Search contract for backends that can return rich, grouped/semantic results and |
| 23 | + * hydrate a full concept graph on demand, in addition to the flat {@link SearchService} |
| 24 | + * contract. |
| 25 | + * |
| 26 | + * <p>Discovered like any other lifecycle-managed service: |
| 27 | + * <pre>{@code |
| 28 | + * Optional<RemoteConceptSearchService> remote = ServiceLifecycleManager.get() |
| 29 | + * .getRunningService(RemoteConceptSearchService.class); |
| 30 | + * if (remote.isPresent()) { |
| 31 | + * // use remote.get().searchGrouped(...) / .searchFlat(...) |
| 32 | + * } else { |
| 33 | + * // fall back to local search |
| 34 | + * } |
| 35 | + * }</pre> |
| 36 | + * Presence of the service in the returned {@code Optional} is itself the activity signal — |
| 37 | + * there is no separate {@code isActive()} check. |
| 38 | + */ |
| 39 | +public interface RemoteConceptSearchService { |
| 40 | + |
| 41 | + /** |
| 42 | + * Sort options mirroring common UI sort controls. |
| 43 | + */ |
| 44 | + enum SortOption { |
| 45 | + TOP_COMPONENT, |
| 46 | + TOP_COMPONENT_ALPHA, |
| 47 | + SEMANTIC, |
| 48 | + SEMANTIC_ALPHA |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * A single semantic match within a {@link GroupedResult}. |
| 53 | + * |
| 54 | + * @param highlightedText matched text with {@code <B>…</B>} markup |
| 55 | + * @param plainText plain text without HTML markup |
| 56 | + * @param score relevance score |
| 57 | + */ |
| 58 | + record MatchingSemantic(String highlightedText, String plainText, float score) {} |
| 59 | + |
| 60 | + /** |
| 61 | + * A top-level (grouped) search result — one per matching concept. |
| 62 | + * |
| 63 | + * @param publicId stable UUIDs identifying the concept |
| 64 | + * @param fullyQualifiedName FQN of the concept |
| 65 | + * @param active whether the concept is currently active |
| 66 | + * @param topScore highest relevance score among child semantics |
| 67 | + * @param matchingSemantics child semantic matches |
| 68 | + */ |
| 69 | + record GroupedResult( |
| 70 | + List<String> publicId, |
| 71 | + String fullyQualifiedName, |
| 72 | + boolean active, |
| 73 | + float topScore, |
| 74 | + List<MatchingSemantic> matchingSemantics) {} |
| 75 | + |
| 76 | + /** |
| 77 | + * A flat semantic search result (SEMANTIC sort modes) — one per matched semantic. |
| 78 | + * |
| 79 | + * @param publicId stable UUIDs identifying the concept |
| 80 | + * @param fullyQualifiedName FQN of the concept |
| 81 | + * @param highlightedText matched text with {@code <B>…</B>} markup |
| 82 | + * @param active whether the concept is currently active |
| 83 | + * @param score relevance score |
| 84 | + */ |
| 85 | + record SemanticResult( |
| 86 | + List<String> publicId, |
| 87 | + String fullyQualifiedName, |
| 88 | + String highlightedText, |
| 89 | + boolean active, |
| 90 | + float score) {} |
| 91 | + |
| 92 | + /** |
| 93 | + * Performs a search returning grouped results (TOP_COMPONENT modes). |
| 94 | + */ |
| 95 | + List<GroupedResult> searchGrouped(String query, int maxResults, SortOption sortOption); |
| 96 | + |
| 97 | + /** |
| 98 | + * Performs a search returning flat semantic results (SEMANTIC modes). |
| 99 | + */ |
| 100 | + List<SemanticResult> searchFlat(String query, int maxResults, SortOption sortOption); |
| 101 | + |
| 102 | + /** |
| 103 | + * Fetches the full entity graph for a concept from the remote backend and loads it |
| 104 | + * into the local entity store, so subsequent local lookups (name, parents, axioms) |
| 105 | + * resolve without another round trip. |
| 106 | + * |
| 107 | + * @param publicIds the concept's public UUIDs (from a search result) |
| 108 | + * @return the local NID assigned to the concept after loading |
| 109 | + */ |
| 110 | + int loadConceptWithSemantics(List<UUID> publicIds); |
| 111 | +} |
0 commit comments