Search in sources :

Example 1 with SearchMetadataCollection

use of org.opencastproject.matterhorn.search.impl.SearchMetadataCollection in project opencast by opencast.

the class SeriesIndexUtils method toSearchMetadata.

/**
 * Creates search metadata from a series such that the event can be stored in the search index.
 *
 * @param series
 *          the series
 * @return the set of metadata
 */
public static SearchMetadataCollection toSearchMetadata(Series series) {
    SearchMetadataCollection metadata = new SearchMetadataCollection(series.getIdentifier().concat(series.getOrganization()), Series.DOCUMENT_TYPE);
    metadata.addField(SeriesIndexSchema.UID, series.getIdentifier(), true);
    metadata.addField(SeriesIndexSchema.ORGANIZATION, series.getOrganization(), false);
    metadata.addField(SeriesIndexSchema.OBJECT, series.toXML(), false);
    metadata.addField(SeriesIndexSchema.TITLE, series.getTitle(), true);
    if (StringUtils.trimToNull(series.getDescription()) != null) {
        metadata.addField(SeriesIndexSchema.DESCRIPTION, series.getDescription(), true);
    }
    if (StringUtils.trimToNull(series.getSubject()) != null) {
        metadata.addField(SeriesIndexSchema.SUBJECT, series.getSubject(), true);
    }
    if (StringUtils.trimToNull(series.getLanguage()) != null) {
        metadata.addField(SeriesIndexSchema.LANGUAGE, series.getLanguage(), true);
    }
    if (StringUtils.trimToNull(series.getCreator()) != null) {
        metadata.addField(SeriesIndexSchema.CREATOR, series.getCreator(), true);
    }
    if (StringUtils.trimToNull(series.getLicense()) != null) {
        metadata.addField(SeriesIndexSchema.LICENSE, series.getLicense(), true);
    }
    if (StringUtils.trimToNull(series.getManagedAcl()) != null) {
        metadata.addField(SeriesIndexSchema.MANAGED_ACL, series.getManagedAcl(), true);
    }
    if (series.getCreatedDateTime() != null) {
        metadata.addField(SeriesIndexSchema.CREATED_DATE_TIME, DateTimeSupport.toUTC(series.getCreatedDateTime().getTime()), true);
    }
    if (series.getOrganizers() != null) {
        metadata.addField(SeriesIndexSchema.ORGANIZERS, series.getOrganizers().toArray(), true);
    }
    if (series.getContributors() != null) {
        metadata.addField(SeriesIndexSchema.CONTRIBUTORS, series.getContributors().toArray(), true);
    }
    if (series.getPublishers() != null) {
        metadata.addField(SeriesIndexSchema.PUBLISHERS, series.getPublishers().toArray(), true);
    }
    if (series.getRightsHolder() != null) {
        metadata.addField(SeriesIndexSchema.RIGHTS_HOLDER, series.getRightsHolder(), true);
    }
    if (StringUtils.trimToNull(series.getAccessPolicy()) != null) {
        metadata.addField(SeriesIndexSchema.ACCESS_POLICY, series.getAccessPolicy(), true);
        addAuthorization(metadata, series.getAccessPolicy());
    }
    metadata.addField(SeriesIndexSchema.OPT_OUT, series.isOptedOut(), false);
    if (series.getTheme() != null) {
        metadata.addField(SeriesIndexSchema.THEME, series.getTheme(), false);
    }
    return metadata;
}
Also used : SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection)

Example 2 with SearchMetadataCollection

use of org.opencastproject.matterhorn.search.impl.SearchMetadataCollection in project opencast by opencast.

the class AbstractSearchIndex method addOrUpdate.

/**
 * Add or update a series in the search index.
 *
 * @param series
 * @throws SearchIndexException
 */
public void addOrUpdate(Series series) throws SearchIndexException {
    logger.debug("Adding resource {} to search index", series);
    // if (!preparedIndices.contains(resource.getURI().getSite().getIdentifier())) {
    // try {
    // createIndex(resource.getURI().getSite());
    // } catch (IOException e) {
    // throw new SearchIndexException(e);
    // }
    // }
    // Add the resource to the index
    SearchMetadataCollection inputDocument = SeriesIndexUtils.toSearchMetadata(series);
    List<SearchMetadata<?>> resourceMetadata = inputDocument.getMetadata();
    ElasticsearchDocument doc = new ElasticsearchDocument(inputDocument.getIdentifier(), inputDocument.getDocumentType(), resourceMetadata);
    try {
        update(doc);
    } catch (Throwable t) {
        throw new SearchIndexException("Cannot write resource " + series + " to index", t);
    }
}
Also used : SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SearchMetadata(org.opencastproject.matterhorn.search.SearchMetadata) ElasticsearchDocument(org.opencastproject.matterhorn.search.impl.ElasticsearchDocument)

Example 3 with SearchMetadataCollection

use of org.opencastproject.matterhorn.search.impl.SearchMetadataCollection in project opencast by opencast.

the class AbstractSearchIndex method getByQuery.

/**
 * @param query
 *          The query to use to retrieve the themes that match the query
 * @return {@link SearchResult} collection of {@link Theme} from a query.
 * @throws SearchIndexException
 *           Thrown if there is an error getting the results.
 */
public SearchResult<Theme> getByQuery(ThemeSearchQuery query) throws SearchIndexException {
    logger.debug("Searching index using theme query '{}'", query);
    // Create the request builder
    SearchRequestBuilder requestBuilder = getSearchRequestBuilder(query, new ThemeQueryBuilder(query));
    try {
        return executeQuery(query, requestBuilder, new Fn<SearchMetadataCollection, Theme>() {

            @Override
            public Theme apply(SearchMetadataCollection metadata) {
                try {
                    return ThemeIndexUtils.toTheme(metadata);
                } catch (IOException e) {
                    return chuck(e);
                }
            }
        });
    } catch (Throwable t) {
        throw new SearchIndexException("Error querying theme index", t);
    }
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ThemeQueryBuilder(org.opencastproject.index.service.impl.index.theme.ThemeQueryBuilder) Theme(org.opencastproject.index.service.impl.index.theme.Theme) IOException(java.io.IOException)

Example 4 with SearchMetadataCollection

use of org.opencastproject.matterhorn.search.impl.SearchMetadataCollection in project opencast by opencast.

the class AbstractSearchIndex method addOrUpdate.

/**
 * Adds or updates the theme in the search index.
 *
 * @param theme
 *          The theme to add
 * @throws SearchIndexException
 *           Thrown if unable to add or update the theme.
 */
public void addOrUpdate(Theme theme) throws SearchIndexException {
    logger.debug("Adding resource {} to search index", theme);
    // if (!preparedIndices.contains(resource.getURI().getSite().getIdentifier())) {
    // try {
    // createIndex(resource.getURI().getSite());
    // } catch (IOException e) {
    // throw new SearchIndexException(e);
    // }
    // }
    // Add the resource to the index
    SearchMetadataCollection inputDocument = ThemeIndexUtils.toSearchMetadata(theme);
    List<SearchMetadata<?>> resourceMetadata = inputDocument.getMetadata();
    ElasticsearchDocument doc = new ElasticsearchDocument(inputDocument.getIdentifier(), inputDocument.getDocumentType(), resourceMetadata);
    try {
        update(doc);
    } catch (Throwable t) {
        throw new SearchIndexException("Cannot write resource " + theme + " to index", t);
    }
}
Also used : SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SearchMetadata(org.opencastproject.matterhorn.search.SearchMetadata) ElasticsearchDocument(org.opencastproject.matterhorn.search.impl.ElasticsearchDocument)

Example 5 with SearchMetadataCollection

use of org.opencastproject.matterhorn.search.impl.SearchMetadataCollection in project opencast by opencast.

the class AbstractSearchIndex method getByQuery.

/**
 * @param query
 *          The query to use to retrieve the groups that match the query
 * @return {@link SearchResult} collection of {@link Group} from a query.
 * @throws SearchIndexException
 *           Thrown if there is an error getting the results.
 */
public SearchResult<Group> getByQuery(GroupSearchQuery query) throws SearchIndexException {
    logger.debug("Searching index using group query '{}'", query);
    // Create the request builder
    SearchRequestBuilder requestBuilder = getSearchRequestBuilder(query, new GroupQueryBuilder(query));
    try {
        return executeQuery(query, requestBuilder, new Fn<SearchMetadataCollection, Group>() {

            @Override
            public Group apply(SearchMetadataCollection metadata) {
                try {
                    return GroupIndexUtils.toGroup(metadata);
                } catch (IOException e) {
                    return chuck(e);
                }
            }
        });
    } catch (Throwable t) {
        throw new SearchIndexException("Error querying series index", t);
    }
}
Also used : Group(org.opencastproject.index.service.impl.index.group.Group) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) IOException(java.io.IOException) GroupQueryBuilder(org.opencastproject.index.service.impl.index.group.GroupQueryBuilder)

Aggregations

SearchMetadataCollection (org.opencastproject.matterhorn.search.impl.SearchMetadataCollection)13 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)9 IOException (java.io.IOException)4 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)4 SearchMetadata (org.opencastproject.matterhorn.search.SearchMetadata)4 ElasticsearchDocument (org.opencastproject.matterhorn.search.impl.ElasticsearchDocument)4 HashMap (java.util.HashMap)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 SearchHit (org.elasticsearch.search.SearchHit)1 SearchHitField (org.elasticsearch.search.SearchHitField)1 Event (org.opencastproject.index.service.impl.index.event.Event)1 EventQueryBuilder (org.opencastproject.index.service.impl.index.event.EventQueryBuilder)1 Group (org.opencastproject.index.service.impl.index.group.Group)1 GroupQueryBuilder (org.opencastproject.index.service.impl.index.group.GroupQueryBuilder)1 Series (org.opencastproject.index.service.impl.index.series.Series)1 SeriesQueryBuilder (org.opencastproject.index.service.impl.index.series.SeriesQueryBuilder)1 Theme (org.opencastproject.index.service.impl.index.theme.Theme)1 ThemeQueryBuilder (org.opencastproject.index.service.impl.index.theme.ThemeQueryBuilder)1 SearchMetadataImpl (org.opencastproject.matterhorn.search.impl.SearchMetadataImpl)1 SearchResultImpl (org.opencastproject.matterhorn.search.impl.SearchResultImpl)1