Package ch.entwine.weblounge.common.impl.content

Examples of ch.entwine.weblounge.common.impl.content.SearchResultImpl


    try {
      if (q.getVersion() == Resource.WORK && q.getPath() != null) {
        ResourceURI uri = new PageURIImpl(q.getSite(), q.getPath(), q.getVersion());
        pageByPath = (Page) repository.get(uri);
        int count = pageByPath != null ? 1 : 0;
        result = new SearchResultImpl(q, count, count);
      } else {
        result = repository.find(q);
      }
    } catch (ContentRepositoryException e) {
      throw new WebApplicationException(e);
View Full Code Here


      }

      // Create and configure the query result
      long hits = response.getHits().getTotalHits();
      long size = response.getHits().getHits().length;
      SearchResultImpl result = new SearchResultImpl(query, hits, size);
      result.setSearchTime(response.getTookInMillis());

      // Walk through response and create new items with title, creator, etc:
      for (SearchHit doc : response.getHits()) {

        // Get the resource serializer
        String type = doc.getType();
        ResourceSerializer<?, ?> serializer = resourceSerializer.getSerializerByType(type);
        if (serializer == null) {
          logger.warn("Skipping search result due to missing serializer of type {}", type);
          size--;
          continue;
        }

        // Wrap the search result metadata
        List<ResourceMetadata<?>> metadata = new ArrayList<ResourceMetadata<?>>(doc.getFields().size());
        for (SearchHitField field : doc.getFields().values()) {
          String name = field.getName();
          ResourceMetadata<Object> m = new ResourceMetadataImpl<Object>(name);
          // TODO: Add values with more care (localized, correct type etc.)
          if (field.getValues().size() > 1) {
            for (Object v : field.getValues()) {
              m.addValue(v);
            }
          } else {
            m.addValue(field.getValue());
          }
          metadata.add(m);
        }

        // Get the score for this item
        float score = doc.getScore();

        // Have the serializer in charge create a type-specific search result
        // item
        try {
          SearchResultItem item = serializer.toSearchResultItem(query.getSite(), score, metadata);
          result.addResultItem(item);
        } catch (Throwable t) {
          logger.warn("Error during search result serialization: '{}'. Skipping this search result.", t.getMessage());
          size--;
          continue;
        }
      }

      result.setDocumentCount(size);
      return result;

    } catch (Throwable t) {
      throw new ContentRepositoryException("Error querying index", t);
    }
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.impl.content.SearchResultImpl

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.