/** * Suggest the terms that best match the user's input, in a specific sub-category of this vocabulary. * * @param input the text that the user entered * @param category the category of terms to search in, one of the {@link #getSupportedCategories() supported * categories} * @param maxResults the maximum number of terms to be returned * @param sort an optional sort parameter, in a format that depends on the actual engine that stores the vocabulary; * usually a property name followed by {@code asc} or {@code desc}; may be {@code null} * @param customFilter an optional custom filter query to further restrict which terms may be returned, in a format * that depends on the actual engine that stores the vocabulary; some vocabularies may not support a * filter query; may be {@code null} * @return a list of suggestions, possibly empty. * @since 1.4 */ default List<VocabularyTerm> search(String input, String category, int maxResults, String sort, String customFilter) { return search(input, maxResults, sort, customFilter); }
/** * Performs a search for {@code input query string} using the provided set of {@code categorizedVocabularies}, and * returns the specified {@code maxResults number of results}, sorted by score (in descending order). * * @param input the input query string * @param maxResults the maximum number of results to return * @param category the vocabulary category * @param categorizedVocabularies the {@link Vocabulary} objects to search {@code input} in * @return an list of {@link VocabularyTerm} objects to search in */ private List<VocabularyTerm> search(@Nonnull final String input, final int maxResults, @Nonnull final String category, @Nonnull final Set<Vocabulary> categorizedVocabularies) { final List<VocabularyTerm> results = new ArrayList<>(); for (final Vocabulary vocabulary : categorizedVocabularies) { results.addAll(vocabulary.search(input, category, maxResults, null, null)); } sortTermsByScore(results); final int resultsSize = results.size(); final int rows = maxResults <= resultsSize ? maxResults : resultsSize; return results.subList(0, rows); }
@Override public Response suggest(String vocabularyId, String input, @DefaultValue("10") int maxResults, String sort, String customFilter) { if (StringUtils.isEmpty(input) || StringUtils.isEmpty(vocabularyId)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); } List<VocabularyTerm> termSuggestions = vocabulary.search(input, maxResults, sort, customFilter); JSONObject rep = new JSONObject(); JSONArray trms = new JSONArray(); for (VocabularyTerm term : termSuggestions) { JSONObject trm = term.toJSON(); trm.put("links", this.autolinker.get().forSecondaryResource(VocabularyTermResource.class, this.uriInfo) .build()); trms.put(trm); } rep.put("rows", trms); rep.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); } }
List<VocabularyTerm> topSections = this.ontologyService.search(m); Set<String> topSectionsId = new LinkedHashSet<>(); for (VocabularyTerm section : topSections) {
List<VocabularyTerm> topSections = this.ontologyService.search(m); Set<String> topSectionsId = new LinkedHashSet<>(); for (VocabularyTerm section : topSections) {
@Override public VocabularyTerms suggest(String vocabularyId, String input, @DefaultValue("10") int maxResults, String sort, String customFilter) { if (StringUtils.isEmpty(input) || StringUtils.isEmpty(vocabularyId)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); } List<VocabularyTerm> termSuggestions = vocabulary.search(input, maxResults, sort, customFilter); List<VocabularyTermSummary> termReps = new ArrayList<>(); for (VocabularyTerm term : termSuggestions) { VocabularyTermSummary termRep = this.objectFactory.createVocabularyTermRepresentation(term); termRep.withLinks(this.autolinker.get().forSecondaryResource(VocabularyTermResource.class, this.uriInfo) .withActionableResources(VocabularyResource.class) .withExtraParameters("vocabulary-id", vocabularyId) .withExtraParameters("term-id", term.getId()) .build()); termReps.add(termRep); } VocabularyTerms result = new VocabularyTerms().withVocabularyTerms(termReps); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return result; } }