All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hp.autonomy.searchcomponents.hod.search.HodRelatedConceptsService Maven / Gradle / Ivy

/*
 * Copyright 2015 Hewlett-Packard Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

package com.hp.autonomy.searchcomponents.hod.search;

import com.hp.autonomy.hod.client.api.resource.ResourceIdentifier;
import com.hp.autonomy.hod.client.api.textindex.query.search.Entity;
import com.hp.autonomy.hod.client.api.textindex.query.search.FindRelatedConceptsRequestBuilder;
import com.hp.autonomy.hod.client.api.textindex.query.search.FindRelatedConceptsService;
import com.hp.autonomy.hod.client.error.HodErrorException;
import com.hp.autonomy.hod.sso.HodAuthenticationPrincipal;
import com.hp.autonomy.searchcomponents.core.authentication.AuthenticationInformationRetriever;
import com.hp.autonomy.searchcomponents.core.caching.CacheNames;
import com.hp.autonomy.searchcomponents.core.search.QueryRestrictions;
import com.hp.autonomy.searchcomponents.core.search.RelatedConceptsRequest;
import com.hp.autonomy.searchcomponents.core.search.RelatedConceptsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class HodRelatedConceptsService implements RelatedConceptsService {
    private final FindRelatedConceptsService findRelatedConceptsService;
    private final AuthenticationInformationRetriever authenticationRetriever;

    @Autowired
    public HodRelatedConceptsService(
            final FindRelatedConceptsService findRelatedConceptsService,
            final AuthenticationInformationRetriever authenticationRetriever) {
        this.findRelatedConceptsService = findRelatedConceptsService;
        this.authenticationRetriever = authenticationRetriever;
    }

    @Override
    @Cacheable(CacheNames.RELATED_CONCEPTS)
    public List findRelatedConcepts(final RelatedConceptsRequest relatedConceptsRequest) throws HodErrorException {

        final QueryRestrictions queryRestrictions = relatedConceptsRequest.getQueryRestrictions();
        final FindRelatedConceptsRequestBuilder params = new FindRelatedConceptsRequestBuilder()
                .setIndexes(queryRestrictions.getDatabases())
                .setFieldText(queryRestrictions.getFieldText())
                .setMinScore(queryRestrictions.getMinScore())
                .setMaxResults(relatedConceptsRequest.getMaxResults())
                .setSecurityInfo(authenticationRetriever.getPrincipal().getSecurityInfo());

        return findRelatedConceptsService.findRelatedConceptsWithText(queryRestrictions.getQueryText(), params);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy