예제 #1
0
  public AbstractPageList<ResultNode> searchPageContents(
      SessionProvider sessionProvider,
      QueryCriteria queryCriteria,
      int pageSize,
      boolean isSearchContent)
      throws Exception {
    ManageableRepository currentRepository = repositoryService.getCurrentRepository();
    Session session = sessionProvider.getSession("portal-system", currentRepository);
    QueryManager queryManager = session.getWorkspace().getQueryManager();
    long startTime = System.currentTimeMillis();
    Query query = createSearchPageQuery(queryCriteria, queryManager);
    String suggestion = getSpellSuggestion(queryCriteria.getKeyword(), currentRepository);
    if (LOG.isDebugEnabled()) {
      LOG.debug("execute query: " + query.getStatement().toLowerCase());
    }
    AbstractPageList<ResultNode> pageList =
        PageListFactory.createPageList(
            query.getStatement(),
            session.getWorkspace().getName(),
            query.getLanguage(),
            true,
            new PageNodeFilter(),
            new PageDataCreator(),
            pageSize,
            0);

    long queryTime = System.currentTimeMillis() - startTime;
    pageList.setQueryTime(queryTime);
    pageList.setSpellSuggestion(suggestion);
    return pageList;
  }
예제 #2
0
  @Override
  public List<ModelResource> search(String queryExpression) {
    if (queryExpression == null || queryExpression.isEmpty()) {
      queryExpression = "*";
    }

    try {
      List<ModelResource> modelResources = new ArrayList<>();
      QueryManager queryManager = session.getWorkspace().getQueryManager();
      Query query =
          queryManager.createQuery(
              queryExpression, org.modeshape.jcr.api.query.Query.FULL_TEXT_SEARCH);
      logger.debug("Searching repository with expression " + query.getStatement());
      QueryResult result = query.execute();
      RowIterator rowIterator = result.getRows();

      while (rowIterator.hasNext()) {
        Row row = rowIterator.nextRow();
        Node currentNode = row.getNode();
        if (currentNode.hasProperty("vorto:type") && !isMappingNode(currentNode)) {
          modelResources.add(createModelResource(currentNode));
        }
      }

      return modelResources;
    } catch (RepositoryException e) {
      throw new RuntimeException("Could not create query manager", e);
    }
  }
예제 #3
0
 /**
  * Tests it the statement returned by {@link Query#getStatement()} is equal to the one passed in
  * createQuery().
  */
 public void testGetStatement() throws RepositoryException {
   String statement = "/" + jcrRoot + "/foo";
   Query q = session.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
   assertEquals(
       "Statement returned by Query.getStatement() is not equal to the initial statement.",
       statement,
       q.getStatement());
 }
예제 #4
0
 /**
  * @return return the JCR path of the mop:page nodes that have gtn:name (page's title) containing
  *     the given specified <code>keyword</code>
  * @throws Exception
  */
 private List<String> searchPageByTitle(String siteName, String keyword) throws Exception {
   SessionProvider sessionProvider = WCMCoreUtils.getSystemSessionProvider();
   ManageableRepository currentRepository = repositoryService.getCurrentRepository();
   Session session = sessionProvider.getSession("portal-system", currentRepository);
   QueryManager queryManager = session.getWorkspace().getQueryManager();
   QueryCriteria queryCriteria = new QueryCriteria();
   queryCriteria.setSiteName(siteName);
   queryCriteria.setKeyword(keyword);
   queryCriteria.setSearchWebpage(true);
   Query query = createSearchPageByTitleQuery(queryCriteria, queryManager);
   if (LOG.isDebugEnabled()) {
     LOG.debug("execute query: " + query.getStatement().toLowerCase());
   }
   List<String> pageList =
       PageListFactory.createPageList(
           query.getStatement(),
           session.getWorkspace().getName(),
           query.getLanguage(),
           true,
           new PageTitleDataCreator());
   return pageList;
 }
예제 #5
0
  /*
   * (non-Javadoc)
   * @see
   * org.exoplatform.services.wcm.search.SiteSearchService#searchSiteContents
   * (org.exoplatform.services.wcm.search.QueryCriteria,
   * org.exoplatform.services.jcr.ext.common.SessionProvider, int)
   */
  public AbstractPageList<ResultNode> searchSiteContents(
      SessionProvider sessionProvider,
      QueryCriteria queryCriteria,
      int pageSize,
      boolean isSearchContent)
      throws Exception {
    ManageableRepository currentRepository = repositoryService.getCurrentRepository();
    NodeLocation location = configurationService.getLivePortalsLocation();
    Session session = sessionProvider.getSession(location.getWorkspace(), currentRepository);
    if (queryCriteria.isSearchWebpage()) {
      session = sessionProvider.getSession("portal-system", WCMCoreUtils.getRepository());
    }
    QueryManager queryManager = session.getWorkspace().getQueryManager();
    long startTime = System.currentTimeMillis();
    Query query = createQuery(queryCriteria, queryManager);
    String suggestion = getSpellSuggestion(queryCriteria.getKeyword(), currentRepository);
    AbstractPageList<ResultNode> pageList = null;
    if (LOG.isDebugEnabled()) {
      LOG.debug("execute query: " + query.getStatement().toLowerCase());
    }
    pageList =
        PageListFactory.createPageList(
            query.getStatement(),
            session.getWorkspace().getName(),
            query.getLanguage(),
            IdentityConstants.SYSTEM.equals(session.getUserID()),
            new NodeFilter(isSearchContent, queryCriteria),
            new DataCreator(),
            pageSize,
            0,
            queryCriteria);

    long queryTime = System.currentTimeMillis() - startTime;
    pageList.setQueryTime(queryTime);
    pageList.setSpellSuggestion(suggestion);
    return pageList;
  }
  /** {@inheritDoc} */
  public List<RepositoryFile> getDeletedFiles(
      final Session session,
      final PentahoJcrConstants pentahoJcrConstants,
      final String origParentFolderPath,
      final String filter)
      throws RepositoryException {
    Node trashNode = getOrCreateTrashInternalFolderNode(session, pentahoJcrConstants);

    // query Trash Structure 2
    QueryObjectModelFactory fac = session.getWorkspace().getQueryManager().getQOMFactory();
    final String selectorName = "selector"; // $NON-NLS-1$

    // selector
    final Selector selector = fac.selector("nt:base", selectorName); // $NON-NLS-1$
    // constraint1
    Constraint origParentFolderPathConstraint =
        fac.comparison(
            fac.propertyValue(selectorName, pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH()),
            QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
            fac.literal(session.getValueFactory().createValue(origParentFolderPath)));
    // constraint2
    Constraint origNameConstraint = null;
    if (StringUtils.hasLength(filter)) {
      String convertedFilter = filter.replace('*', '%');
      origNameConstraint =
          fac.comparison(
              fac.propertyValue(selectorName, pentahoJcrConstants.getPHO_ORIGNAME()),
              QueryObjectModelConstants.JCR_OPERATOR_LIKE,
              fac.literal(session.getValueFactory().createValue(convertedFilter)));
    }
    // constraint3
    Constraint descendantNodeConstraint = fac.descendantNode(selectorName, trashNode.getPath());
    // AND together constraints
    Constraint allConstraints = fac.and(descendantNodeConstraint, origParentFolderPathConstraint);
    if (StringUtils.hasLength(filter)) {
      allConstraints = fac.and(allConstraints, origNameConstraint);
    }
    Query query = fac.createQuery(selector, allConstraints, null, null);
    QueryResult result =
        session
            .getWorkspace()
            .getQueryManager()
            .createQuery(query.getStatement(), Query.JCR_JQOM)
            .execute();

    NodeIterator nodeIter = result.getNodes();
    List<RepositoryFile> deletedFiles = new ArrayList<RepositoryFile>();

    while (nodeIter.hasNext()) {
      Node trashFileIdNode = nodeIter.nextNode();
      if (trashFileIdNode.hasNodes()) {
        // since the nodes returned by the query are the trash file ID nodes, need to
        // getNodes().nextNode() to get
        // first
        // (and only) child
        deletedFiles.add(
            nodeToDeletedFile(session, pentahoJcrConstants, trashFileIdNode.getNodes().nextNode()));
      } else {
        throw new RuntimeException(
            Messages.getInstance()
                .getString("DefaultDeleteHelper.ERROR_0002_NOT_CLEAN")); // $NON-NLS-1$
      }
    }

    // now we need to handle legacy trash since legacy trashed files don't have origParentFolderPath
    // property

    Set<RepositoryFile> mergedDeletedFiles = new HashSet<RepositoryFile>();
    mergedDeletedFiles.addAll(deletedFiles);
    mergedDeletedFiles.addAll(
        legacyGetDeletedFiles(
            session,
            pentahoJcrConstants,
            pathConversionHelper.relToAbs(origParentFolderPath),
            filter));

    List<RepositoryFile> mergedList = new ArrayList<RepositoryFile>(mergedDeletedFiles);
    Collections.sort(mergedList);
    return mergedList;
  }