Search in sources :

Example 81 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.

the class SiteServiceImpl method findSites.

/*
     * (non-Javadoc)
     * @see org.alfresco.service.cmr.site.SiteService#findSites(java.lang.String, int)
     */
@Override
public List<SiteInfo> findSites(String filter, int size) {
    List<SiteInfo> result;
    NodeRef siteRoot = getSiteRoot();
    if (siteRoot == null) {
        result = Collections.emptyList();
    } else {
        // get the sites that match the specified names
        StringBuilder query = new StringBuilder(128);
        query.append("+TYPE:\"").append(SiteModel.TYPE_SITE).append('"');
        final boolean filterIsPresent = filter != null && filter.length() > 0;
        if (filterIsPresent) {
            query.append(" AND (");
            String escNameFilter = SearchLanguageConversion.escapeLuceneQuery(filter.replace('"', ' '));
            String[] tokenizedFilter = SearchLanguageConversion.tokenizeString(escNameFilter);
            // cm:name
            query.append(" cm:name:\" ");
            for (int i = 0; i < tokenizedFilter.length; i++) {
                if (// Not first element
                i != 0) {
                    query.append("?");
                }
                query.append(tokenizedFilter[i].toLowerCase());
            }
            query.append("*\"");
            // cm:title
            query.append(" OR ").append(" cm:title: (");
            for (int i = 0; i < tokenizedFilter.length; i++) {
                if (// Not first element
                i != 0) {
                    query.append(" AND ");
                }
                query.append("\"" + tokenizedFilter[i] + "*\" ");
            }
            query.append(")");
            query.append(" OR cm:description:\"" + escNameFilter + "\"");
            query.append(")");
        }
        SearchParameters sp = new SearchParameters();
        sp.addStore(siteRoot.getStoreRef());
        sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
        sp.setQuery(query.toString());
        if (size > 0) {
            sp.setLimit(size);
            sp.setLimitBy(LimitBy.FINAL_SIZE);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Search parameters are: " + sp);
        }
        ResultSet results = null;
        try {
            results = this.searchService.query(sp);
            result = new ArrayList<SiteInfo>(results.length());
            for (NodeRef site : results.getNodeRefs()) {
                result.add(createSiteInfo(site));
            }
        } catch (LuceneQueryParserException lqpe) {
            // Log the error but suppress is from the user
            logger.error("LuceneQueryParserException with findSites()", lqpe);
            result = Collections.emptyList();
        } finally {
            if (results != null)
                results.close();
        }
    }
    return result;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) ResultSet(org.alfresco.service.cmr.search.ResultSet) FilterTypeString(org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Example 82 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.

the class HiddenAspect method checkHidden.

/**
 * Searches for nodes in the given store that should be hidden (i.e. match the hidden pattern)
 * and hides them if they are not already hidden.
 *
 * @param storeRef StoreRef
 */
public void checkHidden(StoreRef storeRef) {
    for (HiddenFileInfo filter : filters) {
        String pattern = filter.getFilter();
        ResultSet rs = searchForName(storeRef, pattern);
        for (NodeRef nodeRef : rs.getNodeRefs()) {
            if (!hasHiddenAspect(nodeRef)) {
                hideNode(nodeRef, filter.getVisibilityMask(), true, true, false);
            }
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 83 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.

the class SolrSQLHttpClient method postSolrQuery.

protected ResultSet postSolrQuery(HttpClient httpClient, String url, JSONObject body, SolrJsonProcessor<?> jsonProcessor) throws IOException, JSONException {
    JSONObject json = postQuery(httpClient, url, body);
    JSONResult results = jsonProcessor.getResult(json);
    LOGGER.debug("Sent : {}", url);
    LOGGER.debug("with: {}", body);
    LOGGER.debug("Got: {} in {} ms", results.getNumberFound(), results.getQueryTime());
    return (ResultSet) results;
}
Also used : JSONObject(org.json.JSONObject) JSONResult(org.alfresco.repo.search.impl.lucene.JSONResult) ResultSet(org.alfresco.service.cmr.search.ResultSet) StatsResultSet(org.alfresco.service.cmr.search.StatsResultSet)

Example 84 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.

the class SolrSearchService method like.

@Override
public boolean like(NodeRef nodeRef, QName propertyQName, String sqlLikePattern, boolean includeFTS) throws InvalidNodeRefException {
    if (propertyQName == null) {
        throw new IllegalArgumentException("Property QName is mandatory for the like expression");
    }
    StringBuilder sb = new StringBuilder(sqlLikePattern.length() * 3);
    if (includeFTS) {
        // convert the SQL-like pattern into a Lucene-compatible string
        String pattern = SearchLanguageConversion.convertXPathLikeToLucene(sqlLikePattern.toLowerCase());
        // build Lucene search string specific to the node
        sb = new StringBuilder();
        sb.append("+ID:\"").append(nodeRef.toString()).append("\" +(");
        // FTS or attribute matches
        if (includeFTS) {
            sb.append("TEXT:(").append(pattern).append(") ");
        }
        if (propertyQName != null) {
            sb.append(" @").append(SearchLanguageConversion.escapeLuceneQuery(QName.createQName(propertyQName.getNamespaceURI(), ISO9075.encode(propertyQName.getLocalName())).toString())).append(":(").append(pattern).append(")");
        }
        sb.append(")");
        ResultSet resultSet = null;
        try {
            resultSet = this.query(nodeRef.getStoreRef(), "lucene", sb.toString());
            boolean answer = resultSet.length() > 0;
            return answer;
        } finally {
            if (resultSet != null) {
                resultSet.close();
            }
        }
    } else {
        // convert the SQL-like pattern into a Lucene-compatible string
        String pattern = SearchLanguageConversion.convertXPathLikeToRegex(sqlLikePattern.toLowerCase());
        Serializable property = nodeService.getProperty(nodeRef, propertyQName);
        if (property == null) {
            return false;
        } else {
            String propertyString = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, propertyQName));
            return propertyString.toLowerCase().matches(pattern);
        }
    }
}
Also used : Serializable(java.io.Serializable) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 85 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.

the class SolrSearchService method contains.

@Override
public boolean contains(NodeRef nodeRef, QName propertyQName, String googleLikePattern, Operator defaultOperator) throws InvalidNodeRefException {
    ResultSet resultSet = null;
    try {
        // build Lucene search string specific to the node
        StringBuilder sb = new StringBuilder();
        sb.append("+ID:\"").append(nodeRef.toString()).append("\" +(TEXT:(").append(googleLikePattern.toLowerCase()).append(") ");
        if (propertyQName != null) {
            sb.append(" OR @").append(SearchLanguageConversion.escapeLuceneQuery(QName.createQName(propertyQName.getNamespaceURI(), ISO9075.encode(propertyQName.getLocalName())).toString()));
            sb.append(":(").append(googleLikePattern.toLowerCase()).append(")");
        } else {
            for (QName key : nodeService.getProperties(nodeRef).keySet()) {
                sb.append(" OR @").append(SearchLanguageConversion.escapeLuceneQuery(QName.createQName(key.getNamespaceURI(), ISO9075.encode(key.getLocalName())).toString()));
                sb.append(":(").append(googleLikePattern.toLowerCase()).append(")");
            }
        }
        sb.append(")");
        SearchParameters sp = new SearchParameters();
        sp.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp.setQuery(sb.toString());
        sp.setDefaultOperator(defaultOperator);
        sp.addStore(nodeRef.getStoreRef());
        resultSet = this.query(sp);
        boolean answer = resultSet.length() > 0;
        return answer;
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }
    }
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) QName(org.alfresco.service.namespace.QName) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Aggregations

ResultSet (org.alfresco.service.cmr.search.ResultSet)112 NodeRef (org.alfresco.service.cmr.repository.NodeRef)57 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)49 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)22 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)20 Test (org.junit.Test)20 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)17 QName (org.alfresco.service.namespace.QName)16 StoreRef (org.alfresco.service.cmr.repository.StoreRef)14 ResultSetRow (org.alfresco.service.cmr.search.ResultSetRow)14 HashSet (java.util.HashSet)13 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)13 SearchService (org.alfresco.service.cmr.search.SearchService)13 NodeService (org.alfresco.service.cmr.repository.NodeService)12 IOException (java.io.IOException)11 List (java.util.List)11 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)11 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)10 PagingLuceneResultSet (org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet)10