Search in sources :

Example 1 with ElasticFeaturestoreHit

use of io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit in project hopsworks by logicalclocks.

the class ElasticFeaturestoreBuilder method setFeatureNameHighlights.

private void setFeatureNameHighlights(SearchHit hitAux, ElasticFeaturestoreDTO result, DatasetAccessController.DatasetAccessCtrl accessCtrl) throws ElasticException, GenericException {
    ElasticFeaturestoreHit hit = ElasticFeaturestoreHit.instance(hitAux);
    Map<String, HighlightField> highlightFields = hitAux.getHighlightFields();
    String featureNameField = FeaturestoreXAttrsConstants.getFeaturestoreElasticKey(FeaturestoreXAttrsConstants.FG_FEATURES, FeaturestoreXAttrsConstants.NAME);
    // <highlighted text, name, description>
    Function<Triplet<String, String, String>, Boolean> matcher = (state) -> {
        // check if highlighted name equals feature name
        return removeHighlightTags(state.getValue0()).equals(state.getValue1());
    };
    BiConsumer<ElasticFeaturestoreItemDTO.Highlights, String> highlighter = ElasticFeaturestoreItemDTO.Highlights::setName;
    setFeatureHighlights(highlightFields.get(featureNameField), hit, matcher, highlighter, result, accessCtrl);
}
Also used : HopsworksJAXBContext(io.hops.hopsworks.common.util.HopsworksJAXBContext) ProjectFacade(io.hops.hopsworks.common.dao.project.ProjectFacade) FeaturestoreXAttrsConstants(io.hops.hopsworks.common.featurestore.xattr.dto.FeaturestoreXAttrsConstants) Function(java.util.function.Function) Project(io.hops.hopsworks.persistence.entity.project.Project) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) TransactionAttributeType(javax.ejb.TransactionAttributeType) Triplet(org.javatuples.Triplet) Text(org.elasticsearch.common.text.Text) TransactionAttribute(javax.ejb.TransactionAttribute) Map(java.util.Map) ElasticException(io.hops.hopsworks.exceptions.ElasticException) SearchResponse(org.elasticsearch.action.search.SearchResponse) HighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField) BiConsumer(java.util.function.BiConsumer) EJB(javax.ejb.EJB) SearchHit(org.elasticsearch.search.SearchHit) Stateless(javax.ejb.Stateless) Set(java.util.Set) ElasticController(io.hops.hopsworks.common.elastic.ElasticController) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) ServiceException(io.hops.hopsworks.exceptions.ServiceException) ElasticFeaturestoreHit(io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit) GenericException(io.hops.hopsworks.exceptions.GenericException) FeaturestoreDocType(io.hops.hopsworks.common.elastic.FeaturestoreDocType) Users(io.hops.hopsworks.persistence.entity.user.Users) ElasticFeaturestoreHit(io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit) Triplet(org.javatuples.Triplet) HighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField)

Example 2 with ElasticFeaturestoreHit

use of io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit in project hopsworks by logicalclocks.

the class ElasticFeaturestoreBuilder method setFeatureDescriptionHighlights.

private void setFeatureDescriptionHighlights(SearchHit hitAux, ElasticFeaturestoreDTO result, DatasetAccessController.DatasetAccessCtrl accessCtrl) throws ElasticException, GenericException {
    ElasticFeaturestoreHit hit = ElasticFeaturestoreHit.instance(hitAux);
    Map<String, HighlightField> highlightFields = hitAux.getHighlightFields();
    String featureDescriptionField = FeaturestoreXAttrsConstants.getFeaturestoreElasticKey(FeaturestoreXAttrsConstants.FG_FEATURES, FeaturestoreXAttrsConstants.DESCRIPTION);
    // <highlighted text, name, description>
    Function<Triplet<String, String, String>, Boolean> matcher = (state) -> {
        // check if highlighted description equals feature description
        return removeHighlightTags(state.getValue0()).equals(state.getValue2());
    };
    BiConsumer<ElasticFeaturestoreItemDTO.Highlights, String> highlighter = ElasticFeaturestoreItemDTO.Highlights::setDescription;
    setFeatureHighlights(highlightFields.get(featureDescriptionField), hit, matcher, highlighter, result, accessCtrl);
}
Also used : HopsworksJAXBContext(io.hops.hopsworks.common.util.HopsworksJAXBContext) ProjectFacade(io.hops.hopsworks.common.dao.project.ProjectFacade) FeaturestoreXAttrsConstants(io.hops.hopsworks.common.featurestore.xattr.dto.FeaturestoreXAttrsConstants) Function(java.util.function.Function) Project(io.hops.hopsworks.persistence.entity.project.Project) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) TransactionAttributeType(javax.ejb.TransactionAttributeType) Triplet(org.javatuples.Triplet) Text(org.elasticsearch.common.text.Text) TransactionAttribute(javax.ejb.TransactionAttribute) Map(java.util.Map) ElasticException(io.hops.hopsworks.exceptions.ElasticException) SearchResponse(org.elasticsearch.action.search.SearchResponse) HighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField) BiConsumer(java.util.function.BiConsumer) EJB(javax.ejb.EJB) SearchHit(org.elasticsearch.search.SearchHit) Stateless(javax.ejb.Stateless) Set(java.util.Set) ElasticController(io.hops.hopsworks.common.elastic.ElasticController) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) ServiceException(io.hops.hopsworks.exceptions.ServiceException) ElasticFeaturestoreHit(io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit) GenericException(io.hops.hopsworks.exceptions.GenericException) FeaturestoreDocType(io.hops.hopsworks.common.elastic.FeaturestoreDocType) Users(io.hops.hopsworks.persistence.entity.user.Users) ElasticFeaturestoreHit(io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit) Triplet(org.javatuples.Triplet) HighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField)

Aggregations

ProjectFacade (io.hops.hopsworks.common.dao.project.ProjectFacade)2 ElasticController (io.hops.hopsworks.common.elastic.ElasticController)2 ElasticFeaturestoreHit (io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit)2 FeaturestoreDocType (io.hops.hopsworks.common.elastic.FeaturestoreDocType)2 FeaturestoreXAttrsConstants (io.hops.hopsworks.common.featurestore.xattr.dto.FeaturestoreXAttrsConstants)2 HopsworksJAXBContext (io.hops.hopsworks.common.util.HopsworksJAXBContext)2 ElasticException (io.hops.hopsworks.exceptions.ElasticException)2 GenericException (io.hops.hopsworks.exceptions.GenericException)2 ServiceException (io.hops.hopsworks.exceptions.ServiceException)2 Project (io.hops.hopsworks.persistence.entity.project.Project)2 Users (io.hops.hopsworks.persistence.entity.user.Users)2 RESTCodes (io.hops.hopsworks.restutils.RESTCodes)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Set (java.util.Set)2 BiConsumer (java.util.function.BiConsumer)2 Function (java.util.function.Function)2 Level (java.util.logging.Level)2 EJB (javax.ejb.EJB)2 Stateless (javax.ejb.Stateless)2