Search in sources :

Example 11 with SearchResult

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());
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) SearchResult(org.opencastproject.search.api.SearchResult) Test(org.junit.Test)

Example 12 with SearchResult

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);
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) MediaPackage(org.opencastproject.mediapackage.MediaPackage) SearchResultItem(org.opencastproject.search.api.SearchResultItem) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) SearchResult(org.opencastproject.search.api.SearchResult) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) Test(org.junit.Test)

Example 13 with SearchResult

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);
    }
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) SearchServiceDatabaseException(org.opencastproject.search.impl.persistence.SearchServiceDatabaseException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) NotFoundException(org.opencastproject.util.NotFoundException) SearchException(org.opencastproject.search.api.SearchException) SearchResult(org.opencastproject.search.api.SearchResult) Date(java.util.Date)

Example 14 with SearchResult

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;
}
Also used : SearchResult(org.opencastproject.search.api.SearchResult)

Example 15 with SearchResult

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;
}
Also used : SearchResultItem(org.opencastproject.search.api.SearchResultItem) SearchResult(org.opencastproject.search.api.SearchResult) Feed(org.opencastproject.feed.api.Feed)

Aggregations

SearchResult (org.opencastproject.search.api.SearchResult)15 SearchQuery (org.opencastproject.search.api.SearchQuery)10 MediaPackage (org.opencastproject.mediapackage.MediaPackage)9 Test (org.junit.Test)6 Job (org.opencastproject.job.api.Job)5 JobBarrier (org.opencastproject.job.api.JobBarrier)4 URI (java.net.URI)3 SearchResultItem (org.opencastproject.search.api.SearchResultItem)3 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)3 ArrayList (java.util.ArrayList)2 SearchException (org.opencastproject.search.api.SearchException)2 User (org.opencastproject.security.api.User)2 NotFoundException (org.opencastproject.util.NotFoundException)2 IOException (java.io.IOException)1 URL (java.net.URL)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 HttpResponse (org.apache.http.HttpResponse)1 NameValuePair (org.apache.http.NameValuePair)1