use of org.opencastproject.search.api.SearchResult in project opencast by opencast.
the class SearchServiceImplTest method testEmptySearchIndex.
/**
* Test whether an empty search index will work.
*/
@Test
public void testEmptySearchIndex() {
SearchResult result = service.getByQuery(new SearchQuery().withId("foo"));
assertEquals(0, result.size());
}
use of org.opencastproject.search.api.SearchResult in project opencast by opencast.
the class SearchServiceImplTest method testAddSimpleMediaPackage.
/**
* Adds a simple media package that has a dublin core for the episode only.
*/
@Test
public void testAddSimpleMediaPackage() throws Exception {
MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
// Make sure our mocked ACL has the read and write permission
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, READ.toString(), true));
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
// Add the media package to the search index
Job job = service.add(mediaPackage);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
assertEquals("Job to add mediapckage did not finish", Job.Status.FINISHED, job.getStatus());
// Make sure it's properly indexed and returned
SearchQuery q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId("10.0000/1");
assertEquals(1, service.getByQuery(q).size());
q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
assertEquals(1, service.getByQuery(q).size());
// Test for various fields
q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId("10.0000/1");
SearchResult result = service.getByQuery(q);
assertEquals(1, result.getTotalSize());
SearchResultItem resultItem = result.getItems()[0];
assertNotNull(resultItem.getMediaPackage());
assertEquals(1, resultItem.getMediaPackage().getCatalogs().length);
}
use of org.opencastproject.search.api.SearchResult in project opencast by opencast.
the class SearchServiceImpl method deleteSynchronously.
/**
* Immediately removes the given mediapackage from the search service.
*
* @param mediaPackageId
* the mediapackage
* @return <code>true</code> if the mediapackage was deleted
* @throws SearchException
* if deletion failed
* @throws UnauthorizedException
* if the user did not have access to the media package
* @throws NotFoundException
* if the mediapackage did not exist
*/
public boolean deleteSynchronously(String mediaPackageId) throws SearchException, UnauthorizedException, NotFoundException {
SearchResult result;
try {
result = solrRequester.getForWrite(new SearchQuery().withId(mediaPackageId));
if (result.getItems().length == 0) {
logger.warn("Can not delete mediapackage {}, which is not available for the current user to delete from the search index.", mediaPackageId);
return false;
}
logger.info("Removing mediapackage {} from search index", mediaPackageId);
Date now = new Date();
try {
persistence.deleteMediaPackage(mediaPackageId, now);
logger.info("Removed mediapackage {} from search persistence", mediaPackageId);
} catch (NotFoundException e) {
// even if mp not found in persistence, it might still exist in search index.
logger.info("Could not find mediapackage with id {} in persistence, but will try remove it from index, anyway.", mediaPackageId);
} catch (SearchServiceDatabaseException e) {
logger.error("Could not delete media package with id {} from persistence storage", mediaPackageId);
throw new SearchException(e);
}
return indexManager.delete(mediaPackageId, now);
} catch (SolrServerException e) {
logger.info("Could not delete media package with id {} from search index", mediaPackageId);
throw new SearchException(e);
}
}
use of org.opencastproject.search.api.SearchResult in project opencast by opencast.
the class SeriesFeedService method getDescription.
/**
* {@inheritDoc}
*
* @see org.opencastproject.feed.impl.AbstractFeedGenerator#getDescription()
*/
@Override
public String getDescription() {
String dcAbstract = null;
SearchResult rs = seriesData.get();
if (rs != null) {
dcAbstract = rs.getItems()[0].getDcAbstract();
}
return dcAbstract == null ? super.getDescription() : dcAbstract;
}
use of org.opencastproject.search.api.SearchResult in project opencast by opencast.
the class AbstractFeedGenerator method createFeed.
/**
* {@inheritDoc}
*/
public final Feed createFeed(Feed.Type type, String[] query, int size, Organization organization) {
logger.debug("Started to create {} feed", type);
SearchResult result = null;
if (type == null)
throw new IllegalArgumentException("Feed type must not be null");
if (size <= 0) {
logger.trace("Using the feed's configured size of {}", this.size);
size = this.size;
}
// Check if the feed generator is correctly set up
if (uri == null)
throw new IllegalStateException("Feed uri (feed.uri) must be configured");
if (name == null)
throw new IllegalStateException("Feed name (feed.name) must be configured");
if (getHome(organization) == null)
throw new IllegalStateException("Feed url (feed.home) must be configured");
if (getLinkTemplate(organization) == null)
throw new IllegalStateException("Feed link template (feed.entry) must be configured");
// Have the concrete implementation load the feed data
result = loadFeedData(type, query, size, DEFAULT_OFFSET);
if (result == null) {
logger.debug("Cannot retrieve solr result for feed '{}' with query '{}'", type.toString(), query);
return null;
}
// Create the feed
Feed f = createFeed(type, getIdentifier(), new ContentImpl(getName()), new ContentImpl(getDescription()), getFeedLink(organization));
f.setEncoding(ENCODING);
// Set iTunes tags
ITunesFeedExtension iTunesFeed = new ITunesFeedExtension();
f.addModule(iTunesFeed);
if (cover != null)
f.setImage(new ImageImpl(cover, "Feed Image"));
// Check if a default format has been specified
// TODO: Parse flavor and set member variable rssTrackFlavor
// String rssFlavor = query.length > 1 ? query[query.length - 1] : null;
// Iterate over the feed data and create the entries
int itemCount = 0;
for (SearchResultItem resultItem : result.getItems()) {
try {
if (resultItem.getType().equals(SearchResultItemType.Series))
addSeries(f, query, resultItem, organization);
else
addEpisode(f, query, resultItem, organization);
} catch (Throwable t) {
logger.error("Error creating entry with id {} for feed {}", resultItem.getId(), this, t);
}
itemCount++;
if (itemCount >= size)
break;
}
return f;
}
Aggregations