Package ch.entwine.weblounge.common.content

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


    feed.setLanguage(language.getIdentifier());
    feed.setPublishedDate(new Date());

    // TODO: Add more feed metadata, ask site

    SearchQuery query = new SearchQueryImpl(site);
    query.withVersion(Resource.LIVE);
    query.withTypes(Page.TYPE);
    query.withLimit(limit);
    query.sortByPublishingDate(Order.Descending);
    for (String subject : subjects) {
      query.withSubject(subject);
    }

    // Load the result and add feed entries
    SearchResult result = contentRepository.find(query);
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
View Full Code Here


    if (StringUtils.isNotBlank(imageId))
      uri = new ImageResourceURIImpl(site, null, imageId);
    if (uri == null && StringUtils.isNotBlank(imagePath))
      uri = new ImageResourceURIImpl(site, imagePath, null);
    if (uri == null && imageSubjects != null && imageSubjects.size() > 0) {
      SearchQuery query = new SearchQueryImpl(site);
      query.withVersion(Resource.LIVE);
      query.withTypes(ImageResource.TYPE);
      query.withSubjects(SearchQuery.Quantifier.All, imageSubjects.toArray(new String[imageSubjects.size()]));
      SearchResult result;
      try {
        result = repository.find(query);
      } catch (ContentRepositoryException e) {
        logger.warn("Error searching for image with given subjects ({}): {}", StringUtils.join(imageSubjects, ", "), e.getMessage());
View Full Code Here

    // TODO: Use AND?
    String text = StringUtils.join(args, " ");

    // Get hold of the content repository
    ContentRepository repository = site.getContentRepository();
    SearchQuery query = new SearchQueryImpl(site);
    query.withVersion(Resource.LIVE);
    query.withFulltext(text.toString());

    // Is it a page?
    Formatter formatter = null;
    try {
      SearchResult result = repository.find(query);
View Full Code Here

      return SKIP_BODY;
    }

    // First time search resources
    if (searchResult == null) {
      SearchQuery q = new SearchQueryImpl(site);
      if (includeTypes != null)
        q.withTypes(includeTypes.toArray(new String[includeTypes.size()]));

      if (excludeTypes != null)
        q.withoutTypes(excludeTypes.toArray(new String[excludeTypes.size()]));

      if (order != null)
        q.sortByCreationDate(order);

      if (resourceId != null) {
        for (String id : resourceId)
          q.withIdentifier(id);
      } else {
        if (resourceSubjects != null) {
          for (String subject : resourceSubjects) {
            q.withSubject(subject);
          }
        }
        if (resourceSeries != null) {
          for (String series : resourceSeries) {
            q.withSeries(series);
          }
        }
        if (creatorStartDate != null || creatorEndDate != null) {
          if (creatorStartDate == null)
            creatorStartDate = new Date(0);
          if (creatorEndDate == null)
            creatorEndDate = new Date();
          q.withCreationDateBetween(creatorStartDate);
          q.and(creatorEndDate);
        }
      }

      q.withLimit(limit);
      q.withOffset(offset);

      try {
        searchResult = repository.find(q);
      } catch (ContentRepositoryException e) {
        logger.error("Error searching for resources with given subjects.");
View Full Code Here

   * .
   */
  @Test
  public void testGetWithPath() throws Exception {
    String path = livePage.getURI().getPath();
    SearchQuery q = new SearchQueryImpl(site).withPathPrefix(path);
    assertEquals(2, idx.getByQuery(q).getItems().length);
    q.withText(path);
    assertEquals(1, idx.getByQuery(q).getItems().length);
  }
View Full Code Here

   * {@link ch.entwine.weblounge.search.impl.SearchIndexImpl#getByQuery(ch.entwine.weblounge.common.content.SearchQuery)}
   * .
   */
  @Test
  public void testGetWithSubject() throws Exception {
    SearchQuery q = new SearchQueryImpl(site).withFulltext(livePage.getSubjects()[0]);
    assertEquals(2, idx.getByQuery(q).getItems().length);
    q.withText(livePage.getSubjects()[0]);
    assertEquals(0, idx.getByQuery(q).getItems().length);
  }
View Full Code Here

   * {@link ch.entwine.weblounge.search.impl.SearchIndexImpl#getByQuery(ch.entwine.weblounge.common.content.SearchQuery)}
   * .
   */
  @Test
  public void testGetWithCoverage() throws Exception {
    SearchQuery q = new SearchQueryImpl(site).withFulltext(livePage.getCoverage());
    assertEquals(2, idx.getByQuery(q).getItems().length);
    q.withText(livePage.getCoverage());
    assertEquals(0, idx.getByQuery(q).getItems().length);
  }
View Full Code Here

   * .
   */
  @Test
  public void testGetWithSubjects() throws Exception {
    String subject = "subject";
    SearchQuery q = new SearchQueryImpl(site).withFulltext(subject);
    assertEquals(2, idx.getByQuery(q).getItems().length);
    q.withText(subject);
    assertEquals(0, idx.getByQuery(q).getItems().length);
  }
View Full Code Here

   * {@link ch.entwine.weblounge.search.impl.SearchIndexImpl#getByQuery(ch.entwine.weblounge.common.content.SearchQuery)}
   * .
   */
  @Test
  public void testGetWithProperty() throws Exception {
    SearchQuery q = new SearchQueryImpl(site).withFulltext(pagelet.getProperty("propertyid"));
    assertEquals(2, idx.getByQuery(q).getItems().length);
    q.withText(pagelet.getProperty("propertyid"));
    assertEquals(0, idx.getByQuery(q).getItems().length);
  }
View Full Code Here

   *           if searching fails
   */
  private void assertSearchResult(String searchText, boolean fuzzy,
      int expectedInFulltext, int expectedInText)
      throws ContentRepositoryException {
    SearchQuery q = new SearchQueryImpl(site).withFulltext(fuzzy, searchText);
    assertEquals(expectedInFulltext, idx.getByQuery(q).getItems().length);
    q = new SearchQueryImpl(site).withText(fuzzy, searchText);
    assertEquals(expectedInText, idx.getByQuery(q).getItems().length);

    // Lowercase match
    q = new SearchQueryImpl(site).withFulltext(true, searchText.toLowerCase());
    assertEquals(2, idx.getByQuery(q).getItems().length);

    // Partial matches
    for (String part : StringUtils.split(searchText)) {
      q = new SearchQueryImpl(site).withFulltext(true, part);
      assertTrue(idx.getByQuery(q).getItems().length >= expectedInFulltext);
      q.withText(true, part);
      assertTrue(idx.getByQuery(q).getItems().length >= expectedInText);
    }
  }
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.