Java Code Examples for org.alfresco.service.cmr.search.SearchParameters#getQuery()

The following examples show how to use org.alfresco.service.cmr.search.SearchParameters#getQuery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgnoreConstraint.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private SearchParameters applyFTSDecorations(SearchParameters searchParameters, NamespacePrefixResolver nspResolver)
{
    SearchParameters constrainedParameters = searchParameters.copy();
    String theQuery = constrainedParameters.getQuery();
    theQuery = "(" + theQuery + ")";

    if (ignoreAspectQNames != null)
    {
        for (QName ignoredAspect : ignoreAspectQNames)
        {
            theQuery = theQuery + " and " + "!ASPECT:'" + ignoredAspect.toPrefixString(nspResolver) + "'";
        }
    }

    if (ignoreTypeNames != null)
    {
        for (QName ignoredType : ignoreTypeNames)
        {
            theQuery = theQuery + " and " + "!TYPE:'" + ignoredType.toPrefixString(nspResolver) + "'";
        }
    }

    constrainedParameters.setQuery(theQuery);

    return constrainedParameters;
}
 
Example 2
Source File: AbstractAlfrescoFtsQueryLanguage.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ResultSet executeQuery(SearchParameters searchParameters)
{
    String ftsExpression = searchParameters.getQuery();
    QueryModelFactory factory = queryEngine.getQueryModelFactory();
    AlfrescoFunctionEvaluationContext context = new AlfrescoFunctionEvaluationContext(
            namespaceService, dictionaryService,
            searchParameters.getNamespace());

    QueryOptions options = QueryOptions.create(searchParameters);

    FTSParser.Mode mode;

    if(options.getDefaultFTSConnective() == Connective.AND)
    {
        mode = FTSParser.Mode.DEFAULT_CONJUNCTION;
    }
    else
    {
        mode = FTSParser.Mode.DEFAULT_DISJUNCTION;
    }
        
    Constraint constraint = FTSQueryParser.buildFTS(ftsExpression, factory, context, null, null, mode, options.getDefaultFTSFieldConnective(),
            searchParameters.getQueryTemplates(), options.getDefaultFieldName(), FTSQueryParser.RerankPhase.SINGLE_PASS);
    org.alfresco.repo.search.impl.querymodel.Query query = factory.createQuery(null, null, constraint, buildOrderings(factory, searchParameters));

    QueryEngineResults results = queryEngine.executeQuery(query, options, context);
    ResultSet resultSet = results.getResults().values().iterator().next();
    return resultSet;
}
 
Example 3
Source File: SolrXPathQueryLanguage.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ResultSet executeQuery(SearchParameters searchParameters)
{
    String query = "PATH:\""+searchParameters.getQuery()+"\"";
    SearchParameters sp = searchParameters.copy();
    sp.setLanguage(SearchService.LANGUAGE_SOLR_FTS_ALFRESCO);
    sp.setQuery(query);
    return solrQueryLanguage.executeQuery(sp);
}
 
Example 4
Source File: SolrSearchService.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ResultSet query(SearchParameters searchParameters)
{
    if(searchParameters.getStores().size() == 0)
    {
        throw new IllegalStateException("At least one store must be defined to search");
    }
    
    String parameterisedQueryString;
    if (searchParameters.getQueryParameterDefinitions().size() > 0)
    {
        Map<QName, QueryParameterDefinition> map = new HashMap<QName, QueryParameterDefinition>();

        for (QueryParameterDefinition qpd : searchParameters.getQueryParameterDefinitions())
        {
            map.put(qpd.getQName(), qpd);
        }

        parameterisedQueryString = parameterise(searchParameters.getQuery(), map, null, namespacePrefixResolver);
    }
    else
    {
        parameterisedQueryString = searchParameters.getQuery();
    }
    // TODO: add another property so the set query is not changed ...
    // May be good to return the query as run ??
    searchParameters.setQuery(parameterisedQueryString);

    LuceneQueryLanguageSPI language = queryLanguages.get(searchParameters.getLanguage().toLowerCase());
    if (language != null)
    {
        return language.executeQuery(searchParameters);
    }
    else
    {
        throw new SearcherException("Unknown query language: " + searchParameters.getLanguage());
    }
}
 
Example 5
Source File: NamePatternPropertyValueConstraint.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected SearchParameters applyFTS(SearchParameters searchParameters)
{
    String filePattern;
    StringBuffer luceneReserved = new StringBuffer();
    for(int i=0;i<value.toString().length();i++){
        if(SearchLanguageConversion.DEF_LUCENE.isReserved(value.toString().charAt(i))){
            luceneReserved.append(value.toString().charAt(i));
        }
    }
    String luceneReservedStr=luceneReserved.toString();
    String pattern =org.alfresco.util.ISO9075.encode(value.toString());
    for (int i = 0; i < luceneReservedStr.length(); i++)
    {
        pattern = pattern.replace(org.alfresco.util.ISO9075.encode(luceneReservedStr.substring(i,i + 1)),
                                  luceneReservedStr.substring(i,i + 1));
    }
    filePattern=SearchLanguageConversion.escapeForLucene(pattern);

    SearchParameters constrainedParameters = searchParameters.copy();
    String theQuery = constrainedParameters.getQuery();

    StringBuilder sb = new StringBuilder();
    sb.append("(" + theQuery + ")");
    sb.append(" and (");
    sb.append("TEXT:(").append(filePattern).append(") ");
    sb.append("or (");
    sb.append(" =").append(property.toPrefixString(this.nspResolver));
    sb.append(":").append(filePattern);
    sb.append(" ) ");
    sb.append(")");
    theQuery = sb.toString();
    constrainedParameters.setQuery(theQuery);

    return constrainedParameters;
}
 
Example 6
Source File: FilesFoldersConstraint.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected SearchParameters applyDecorations(ActualEnvironment environment, SearchParameters searchParameters,
            VirtualQuery query)
{
    String queryString = searchParameters.getQuery();
    String language = searchParameters.getLanguage();
    String filteredQuery = filter(language,
                                  queryString,
                                  files,
                                  folders);
    SearchParameters searchParametersCopy = searchParameters.copy();
    searchParametersCopy.setQuery(filteredQuery);
    return searchParametersCopy;
}
 
Example 7
Source File: PropertyValueConstraint.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected SearchParameters applyFTS(SearchParameters searchParameters)
{
    SearchParameters constrainedParameters = searchParameters.copy();
    String theQuery = constrainedParameters.getQuery();

    // TODO: introduce and use operator

    theQuery = "(" + theQuery + ")" + " and " + "( " + "=" + property.toPrefixString(this.nspResolver) + ":"
                +"\""+value.toString() + "\" )";

    constrainedParameters.setQuery(theQuery);

    return constrainedParameters;
}
 
Example 8
Source File: QueryOptions.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static QueryOptions create(SearchParameters searchParameters)
{
    QueryOptions options = new QueryOptions(searchParameters.getQuery(), null);
    options.setIncludeInTransactionData(!searchParameters.excludeDataInTheCurrentTransaction());
    options.setDefaultFTSConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR : Connective.AND);
    options.setDefaultFTSFieldConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR : Connective.AND);
    options.setSkipCount(searchParameters.getSkipCount());
    options.setMaxPermissionChecks(searchParameters.getMaxPermissionChecks());
    options.setMaxPermissionCheckTimeMillis(searchParameters.getMaxPermissionCheckTimeMillis());
    options.setDefaultFieldName(searchParameters.getDefaultFieldName());
    if (searchParameters.getLimitBy() == LimitBy.FINAL_SIZE)
    {
        options.setMaxItems(searchParameters.getLimit());
    }
    else
    {
        options.setMaxItems(searchParameters.getMaxItems());
    }
    options.setMlAnalaysisMode(searchParameters.getMlAnalaysisMode());
    options.setLocales(searchParameters.getLocales());
    options.setStores(searchParameters.getStores());
    options.setQueryParameterDefinitions(searchParameters.getQueryParameterDefinitions());
    ///options.setQuery(query); Done on construction.
    options.setUseInMemorySort(searchParameters.getUseInMemorySort());
    options.setMaxRawResultSetSizeForInMemorySort(searchParameters.getMaxRawResultSetSizeForInMemorySort());
    options.setBulkFetchEnabled(searchParameters.isBulkFetchEnabled());
    options.setExcludeTenantFilter(searchParameters.getExcludeTenantFilter());
    options.setQueryConsistency(searchParameters.getQueryConsistency());
    options.setSinceTxId(searchParameters.getSinceTxId());
    for(String name : searchParameters.getQueryTemplates().keySet())
    {
    	String template = searchParameters.getQueryTemplates().get(name);
    	options.addQueryTemplate(name, template);
    }
    return options;
}
 
Example 9
Source File: CMISQueryOptions.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static CMISQueryOptions create(SearchParameters searchParameters)
{
    String sql = searchParameters.getQuery();

    CMISQueryOptions options = new CMISQueryOptions(sql, searchParameters.getStores().get(0));
    options.setIncludeInTransactionData(!searchParameters.excludeDataInTheCurrentTransaction());
    options.setDefaultFTSConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR : Connective.AND);
    options.setDefaultFTSFieldConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR : Connective.AND);
    options.setSkipCount(searchParameters.getSkipCount());
    options.setMaxPermissionChecks(searchParameters.getMaxPermissionChecks());
    options.setMaxPermissionCheckTimeMillis(searchParameters.getMaxPermissionCheckTimeMillis());
    if (searchParameters.getLimitBy() == LimitBy.FINAL_SIZE)
    {
        options.setMaxItems(searchParameters.getLimit());
    }
    else
    {
        options.setMaxItems(searchParameters.getMaxItems());
    }
    options.setMlAnalaysisMode(searchParameters.getMlAnalaysisMode());
    options.setLocales(searchParameters.getLocales());
    options.setStores(searchParameters.getStores());
    options.setUseInMemorySort(searchParameters.getUseInMemorySort());
    options.setMaxRawResultSetSizeForInMemorySort(searchParameters.getMaxRawResultSetSizeForInMemorySort());
    //options.setQuery(); Done on conbstruction
    //options.setQueryMode(); Should set afterwards
    options.setQueryParameterDefinitions(searchParameters.getQueryParameterDefinitions());
    options.setDefaultFieldName(searchParameters.getDefaultFieldName());
    options.setBulkFetchEnabled(searchParameters.isBulkFetchEnabled());
    options.setExcludeTenantFilter(searchParameters.getExcludeTenantFilter());
    options.setSinceTxId(searchParameters.getSinceTxId());
    for(String name : searchParameters.getQueryTemplates().keySet())
    {
    	String template = searchParameters.getQueryTemplates().get(name);
    	options.addQueryTemplate(name, template);
    }
    return options;
}
 
Example 10
Source File: AlfrescoSolrDataModel.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public org.alfresco.repo.search.impl.querymodel.Query parseCMISQueryToAlfrescoAbstractQuery(CMISQueryMode mode, SearchParameters searchParameters,
                                                                                            SolrQueryRequest req, String alternativeDictionary, CmisVersion cmisVersion)
{
    // convert search parameters to cmis query options
    // TODO: how to handle store ref
    CMISQueryOptions options = new CMISQueryOptions(searchParameters.getQuery(), StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS);
    options.setDefaultFieldName(searchParameters.getDefaultFieldName());
    // TODO: options.setDefaultFTSConnective()
    // TODO: options.setDefaultFTSFieldConnective()
    options.setIncludeInTransactionData(!searchParameters.excludeDataInTheCurrentTransaction());
    options.setLocales(searchParameters.getLocales());
    options.setMlAnalaysisMode(searchParameters.getMlAnalaysisMode());
    options.setQueryParameterDefinitions(searchParameters.getQueryParameterDefinitions());
    for(String name : searchParameters.getQueryTemplates().keySet())
    {
        String template = searchParameters.getQueryTemplates().get(name);
        options.addQueryTemplate(name, template);
    }

    // parse cmis syntax
    CapabilityJoin joinSupport = (mode == CMISQueryMode.CMS_STRICT) ? CapabilityJoin.NONE : CapabilityJoin.INNERANDOUTER;
    CmisFunctionEvaluationContext functionContext = getCMISFunctionEvaluationContext(mode, cmisVersion, alternativeDictionary);

    CMISDictionaryService cmisDictionary = getCMISDictionary(alternativeDictionary, cmisVersion);

    CMISQueryParser parser = new CMISQueryParser(options, cmisDictionary, joinSupport);
    org.alfresco.repo.search.impl.querymodel.Query queryModelQuery = parser.parse(new LuceneQueryModelFactory<Query, Sort, SyntaxError>(), functionContext);

    if (queryModelQuery.getSource() != null)
    {
        List<Set<String>> selectorGroups = queryModelQuery.getSource().getSelectorGroups(functionContext);
        if (selectorGroups.size() == 0)
        {
            throw new UnsupportedOperationException("No selectors");
        }
    }
    return queryModelQuery;
}