Package ch.entwine.weblounge.common.content

Examples of ch.entwine.weblounge.common.content.SearchQuery


      return false;
    }

    // Make sure the resource is not being referenced elsewhere
    if (allRevisions || uri.getVersion() == Resource.LIVE) {
      SearchQuery searchByResource = new SearchQueryImpl(uri.getSite());
      searchByResource.withVersion(Resource.LIVE);
      searchByResource.withProperty("resourceid", uri.getIdentifier());
      if (searchIndex.getByQuery(searchByResource).getDocumentCount() > 0) {
        logger.debug("Resource '{}' is still being referenced", uri);
        throw new ReferentialIntegrityException(uri.getIdentifier());
      }
    }
View Full Code Here


    Set<ResourceURI> documentsToMove = new HashSet<ResourceURI>();
    documentsToMove.add(uri);

    // Also move children?
    if (moveChildren) {
      SearchQuery q = new SearchQueryImpl(site).withPreferredVersion(Resource.LIVE);
      q.withPathPrefix(originalPathPrefix);

      SearchResult result = searchIndex.getByQuery(q);
      if (result.getDocumentCount() == 0) {
        logger.warn("Trying to move non existing resource {}", uri);
        return;
View Full Code Here

   * {@link ch.entwine.weblounge.search.impl.SearchIndexImpl#getByQuery(ch.entwine.weblounge.common.content.SearchQuery)}
   * .
   */
  @Test
  public void testGetWithRecencyPriority() throws Exception {
    SearchQuery q = new SearchQueryImpl(site).withText(true, content);

    // Search without recency boosting
    SearchResultItem[] items = idx.getByQuery(q).getItems();
    assertEquals(2, items.length);
    assertEquals(livePageId, items[0].getId());
    assertEquals(otherLivePageId, items[1].getId());

    // Search with recency boosting
    q.withRececyPriority();
    items = idx.getByQuery(q).getItems();
    assertEquals(2, items.length);
    assertEquals(otherLivePageId, items[0].getId());
    assertEquals(livePageId, items[1].getId());
  }
View Full Code Here

    // List all versions of the resource
    List<Resource<?>> resources = new ArrayList<Resource<?>>();
    Site site = uri.getSite();
    String id = uri.getIdentifier();
    SearchQuery q = new SearchQueryImpl(site).withIdentifier(id);
    for (SearchResultItem existingResource : getByQuery(q).getItems()) {
      List<ResourceMetadata<?>> resourceMetadata = ((ResourceSearchResultItem) existingResource).getMetadata();
      resources.add(serializer.toResource(site, resourceMetadata));
    }
View Full Code Here

      }
    }

    logger.debug("Updating path {} in search index to ", uri.getPath(), path);

    SearchQuery q = new SearchQueryImpl(uri.getSite()).withVersion(uri.getVersion()).withIdentifier(uri.getIdentifier());
    SearchResultItem[] searchResult = getByQuery(q).getItems();
    if (searchResult.length != 1) {
      logger.warn("Resource to be moved not found: {}", uri);
      return false;
    }
View Full Code Here

      @QueryParam("offset") @DefaultValue("0") int offset,
      @QueryParam("details") @DefaultValue("false") boolean details) {

    // Create search query
    Site site = getSite(request);
    SearchQuery q = new SearchQueryImpl(site);

    q.withTypes(Page.TYPE);
    if (version != -1)
      q.withVersion(version);

    if (preferredVersion != -1)
      q.withPreferredVersion(preferredVersion);

    // Path
    if (StringUtils.isNotBlank(path))
      q.withPath(path);

    // Subjects
    if (StringUtils.isNotBlank(subjectstring)) {
      StringTokenizer subjects = new StringTokenizer(subjectstring, ",");
      while (subjects.hasMoreTokens())
        q.withSubject(subjects.nextToken());
    }

    // Search terms
    if (StringUtils.isNotBlank(searchterms))
      q.withText(true, searchterms);

    Calendar today = Calendar.getInstance();
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);
    Calendar yesterday = Calendar.getInstance();
    yesterday.add(Calendar.DATE, -1);
    yesterday.set(Calendar.HOUR_OF_DAY, 0);
    yesterday.set(Calendar.MINUTE, 0);
    yesterday.set(Calendar.SECOND, 0);
    yesterday.set(Calendar.MILLISECOND, 0);
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.add(Calendar.DATE, 1);
    tomorrow.set(Calendar.HOUR_OF_DAY, 0);
    tomorrow.set(Calendar.MINUTE, 0);
    tomorrow.set(Calendar.SECOND, 0);
    tomorrow.set(Calendar.MILLISECOND, 0);

    // Filter query
    if (StringUtils.isNotBlank(filter)) {
      if ("/".equals(filter)) {
        q.withPath("/");
      } else if (filter.contains("state:work")) {
        q.withVersion(Resource.WORK);
        q.withPreferredVersion(-1);
      } else if (filter.contains("state:live")) {
        q.withVersion(Resource.LIVE);
        q.withPreferredVersion(-1);
      } else if (filter.contains("state:locked")) {
        q.withLockOwner();
      }

      // by user
      else if (filter.startsWith("locked:") && filter.length() > "locked:".length()) {
        String lockOwner = StringUtils.trim(filter.substring("locked:".length()));
        if ("me".equals(lockOwner))
          q.withLockOwner(securityService.getUser());
        else
          q.withLockOwner(new UserImpl(lockOwner));
      } else if (filter.startsWith("creator:") && filter.length() > "creator:".length()) {
        String creator = StringUtils.trim(filter.substring("creator:".length()));
        if ("me".equals(creator))
          q.withCreator(securityService.getUser());
        else
          q.withCreator(new UserImpl(creator));
      } else if (filter.startsWith("modifier:") && filter.length() > "modifier:".length()) {
        String modifier = StringUtils.trim(filter.substring("modifier:".length()));
        if ("me".equals(modifier))
          q.withModifier(securityService.getUser());
        else
          q.withModifier(new UserImpl(modifier));
      } else if (filter.startsWith("publisher:") && filter.length() > "publisher:".length()) {
        String publisher = StringUtils.trim(filter.substring("publisher:".length()));
        if ("me".equals(publisher))
          q.withPublisher(securityService.getUser());
        else
          q.withPublisher(new UserImpl(publisher));
      }

      // by date

      else if (filter.startsWith("created:") && filter.length() > "created:".length()) {
        String created = StringUtils.trim(filter.substring("created:".length()));
        if ("today".equals(created))
          q.withCreationDateBetween(today.getTime()).and(tomorrow.getTime());
        else if ("yesterday".equals(created))
          q.withCreationDateBetween(yesterday.getTime()).and(today.getTime());
        else
          q.withCreationDate(tomorrow.getTime());
      } else if (filter.startsWith("modified:") && filter.length() > "modified:".length()) {
        String modified = StringUtils.trim(filter.substring("modified:".length()));
        if ("today".equals(modified))
          q.withModificationDateBetween(today.getTime()).and(tomorrow.getTime());
        else if ("yesterday".equals(modified))
          q.withModificationDateBetween(yesterday.getTime()).and(today.getTime());
        else
          q.withCreationDate(tomorrow.getTime());
      } else if (filter.startsWith("publisher:") && filter.length() > "publisher:".length()) {
        String published = StringUtils.trim(filter.substring("published:".length()));
        if ("today".equals(published))
          q.withPublishingDateBetween(today.getTime()).and(tomorrow.getTime());
        else if ("yesterday".equals(published))
          q.withPublishingDateBetween(yesterday.getTime()).and(today.getTime());
        else
          q.withCreationDate(tomorrow.getTime());
      }

      // by id
      else if (filter.contains("id:")) {
        String[] searchTerms = StringUtils.split(filter);
        for (String searchTerm : searchTerms) {
          if (searchTerm.startsWith("id:") && filter.length() > "id:".length()) {
            q.withIdentifier(StringUtils.trim(searchTerm.substring("id:".length())));
          }
        }
      }

      // simple filter
      else if (filter.contains("/")) {
        q.withPathPrefix(filter);
      } else {
        q.withFulltext(true, filter);
      }

    }

    // Limit and Offset
    q.withLimit(limit);
    q.withOffset(offset);

    // Sort order
    if (StringUtils.equalsIgnoreCase("modified-asc", sort)) {
      q.sortByModificationDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("modified-desc", sort)) {
      q.sortByModificationDate(Order.Descending);
    } else if (StringUtils.equalsIgnoreCase("created-asc", sort)) {
      q.sortByCreationDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("created-desc", sort)) {
      q.sortByCreationDate(Order.Descending);
    } else if (StringUtils.equalsIgnoreCase("published-asc", sort)) {
      q.sortByPublishingDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("published-desc", sort)) {
      q.sortByPublishingDate(Order.Descending);
    }

    // Load the result
    String result = loadResultSet(q, details);
View Full Code Here

      @QueryParam("offset") @DefaultValue("0") int offset,
      @QueryParam("details") @DefaultValue("false") boolean details) {

    // Create search query
    Site site = getSite(request);
    SearchQuery q = new SearchQueryImpl(site);
    q.withVersion(Resource.WORK);

    // Only take resources that have not been modified
    q.withoutPublication();

    // Type
    q.withTypes(Page.TYPE);

    // Filter query
    if (StringUtils.isNotBlank(filter))
      q.withFilter(filter);

    // Limit and Offset
    q.withLimit(limit);
    q.withOffset(offset);

    // Sort order
    if (StringUtils.equalsIgnoreCase("modified-asc", sort)) {
      q.sortByModificationDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("modified-desc", sort)) {
      q.sortByModificationDate(Order.Descending);
    } else if (StringUtils.equalsIgnoreCase("created-asc", sort)) {
      q.sortByCreationDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("created-desc", sort)) {
      q.sortByCreationDate(Order.Descending);
    } else if (StringUtils.equalsIgnoreCase("published-asc", sort)) {
      q.sortByPublishingDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("published-desc", sort)) {
      q.sortByPublishingDate(Order.Descending);
    }

    // Load the result
    String result = loadResultSet(q, details);
View Full Code Here

    Site site = getSite(request);
    ContentRepository repository = getContentRepository(site, false);
    if (repository == null)
      throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);

    SearchQuery q = null;
    StringBuffer result = new StringBuffer();

    result.append("<index");
    result.append(" state=\"").append(repository.isIndexing() ? "indexing" : "normal").append("\"");
    result.append(" readonly=\"").append(repository.isReadOnly() ? "true" : "false").append("\"");
View Full Code Here

      @QueryParam("limit") @DefaultValue("10") int limit,
      @QueryParam("offset") @DefaultValue("0") int offset) {

    // Create search query
    Site site = getSite(request);
    SearchQuery q = new SearchQueryImpl(site);
    q.withVersion(Resource.LIVE);

    // Type
    q.withoutTypes(Page.TYPE);
    if (StringUtils.isNotBlank(type))
      q.withTypes(type);

    // Path
    if (StringUtils.isNotBlank(path))
      q.withPath(path);

    // Subjects
    if (StringUtils.isNotBlank(subjectstring)) {
      StringTokenizer subjects = new StringTokenizer(subjectstring, ",");
      while (subjects.hasMoreTokens())
        q.withSubject(subjects.nextToken());
    }

    // Search terms
    if (StringUtils.isNotBlank(searchterms))
      q.withText(true, searchterms);

    Calendar today = Calendar.getInstance();
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);
    Calendar yesterday = Calendar.getInstance();
    yesterday.add(Calendar.DATE, -1);
    yesterday.set(Calendar.HOUR_OF_DAY, 0);
    yesterday.set(Calendar.MINUTE, 0);
    yesterday.set(Calendar.SECOND, 0);
    yesterday.set(Calendar.MILLISECOND, 0);
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.add(Calendar.DATE, 1);
    tomorrow.set(Calendar.HOUR_OF_DAY, 0);
    tomorrow.set(Calendar.MINUTE, 0);
    tomorrow.set(Calendar.SECOND, 0);
    tomorrow.set(Calendar.MILLISECOND, 0);

    // Filter query
    if (StringUtils.isNotBlank(filter)) {
      if ("/".equals(filter)) {
        q.withPath("/");
      }

      // by user
      else if (filter.startsWith("creator:") && filter.length() > "creator:".length()) {
        String creator = StringUtils.trim(filter.substring("creator:".length()));
        if ("me".equals(creator))
          q.withCreator(securityService.getUser());
        else
          q.withCreator(new UserImpl(creator));
      } else if (filter.startsWith("modifier:") && filter.length() > "modifier:".length()) {
        String modifier = StringUtils.trim(filter.substring("modifier:".length()));
        if ("me".equals(modifier))
          q.withModifier(securityService.getUser());
        else
          q.withModifier(new UserImpl(modifier));
      } else if (filter.startsWith("publisher:") && filter.length() > "publisher:".length()) {
        String publisher = StringUtils.trim(filter.substring("publisher:".length()));
        if ("me".equals(publisher))
          q.withPublisher(securityService.getUser());
        else
          q.withPublisher(new UserImpl(publisher));
      }

      // by date

      else if (filter.startsWith("created:") && filter.length() > "created:".length()) {
        String created = StringUtils.trim(filter.substring("created:".length()));
        if ("today".equals(created))
          q.withCreationDateBetween(today.getTime()).and(tomorrow.getTime());
        else if ("yesterday".equals(created))
          q.withCreationDateBetween(yesterday.getTime()).and(today.getTime());
        else
          q.withCreationDate(tomorrow.getTime());
      } else if (filter.startsWith("modified:") && filter.length() > "modified:".length()) {
        String modified = StringUtils.trim(filter.substring("modified:".length()));
        if ("today".equals(modified))
          q.withModificationDateBetween(today.getTime()).and(tomorrow.getTime());
        else if ("yesterday".equals(modified))
          q.withModificationDateBetween(yesterday.getTime()).and(today.getTime());
        else
          q.withCreationDate(tomorrow.getTime());
      } else if (filter.startsWith("publisher:") && filter.length() > "publisher:".length()) {
        String published = StringUtils.trim(filter.substring("published:".length()));
        if ("today".equals(published))
          q.withPublishingDateBetween(today.getTime()).and(tomorrow.getTime());
        else if ("yesterday".equals(published))
          q.withPublishingDateBetween(yesterday.getTime()).and(today.getTime());
        else
          q.withCreationDate(tomorrow.getTime());
      }

      // by id
      else if (filter.contains("id:")) {
        String[] searchTerms = StringUtils.split(filter);
        for (String searchTerm : searchTerms) {
          if (searchTerm.startsWith("id:") && filter.length() > "id:".length()) {
            q.withIdentifier(StringUtils.trim(searchTerm.substring("id:".length())));
          }
        }
      }

      // simple filter
      else {
        q.withFulltext(true, filter);
      }
    }

    // Limit and Offset
    q.withLimit(limit);
    q.withOffset(offset);

    // Sort order
    if (StringUtils.equalsIgnoreCase("modified-asc", sort)) {
      q.sortByModificationDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("modified-desc", sort)) {
      q.sortByModificationDate(Order.Descending);
    } else if (StringUtils.equalsIgnoreCase("created-asc", sort)) {
      q.sortByCreationDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("created-desc", sort)) {
      q.sortByCreationDate(Order.Descending);
    } else if (StringUtils.equalsIgnoreCase("published-asc", sort)) {
      q.sortByPublishingDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("published-desc", sort)) {
      q.sortByPublishingDate(Order.Descending);
    }

    // Load the result
    String result = loadResultSet(q);
View Full Code Here

      @QueryParam("limit") @DefaultValue("10") int limit,
      @QueryParam("offset") @DefaultValue("0") int offset) {

    // Create search query
    Site site = getSite(request);
    SearchQuery q = new SearchQueryImpl(site);
    q.withVersion(Resource.LIVE);

    // Only take resources that have not been modified
    q.withoutModification();

    // Type
    q.withoutTypes(Page.TYPE);
    if (StringUtils.isNotBlank(type))
      q.withTypes(type);

    // Filter query
    if (StringUtils.isNotBlank(filter))
      q.withFilter(filter);

    // Limit and Offset
    q.withLimit(limit);
    q.withOffset(offset);

    // Sort order
    if (StringUtils.equalsIgnoreCase("modified-asc", sort)) {
      q.sortByModificationDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("modified-desc", sort)) {
      q.sortByModificationDate(Order.Descending);
    } else if (StringUtils.equalsIgnoreCase("created-asc", sort)) {
      q.sortByCreationDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("created-desc", sort)) {
      q.sortByCreationDate(Order.Descending);
    } else if (StringUtils.equalsIgnoreCase("published-asc", sort)) {
      q.sortByPublishingDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("published-desc", sort)) {
      q.sortByPublishingDate(Order.Descending);
    }

    // Load the result
    String result = loadResultSet(q);
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.content.SearchQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.