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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations