Java Code Examples for org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory

The following examples show how to use org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory. These examples are extracted from open source projects. 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
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;
}
 
Example 2
public void testMapLoneStar() throws Exception
{
    final String ftsExpression = "* AND * AND * AND * AND * AND * AND * AND * AND * AND * AND *";
    AlfrescoFunctionEvaluationContext functionContext = new AlfrescoFunctionEvaluationContext(null, null, NamespaceService.CONTENT_MODEL_1_0_URI);

    Map<String, String> templates = new HashMap<String, String>();
    String keywordsTemplate = "%(cm:name cm:title cm:description ia:whatEvent ia:descriptionEvent lnk:title lnk:description TEXT TAG)";
    String keywordsKey = "keywords";
    templates.put(keywordsKey, keywordsTemplate);

    final FTSParser.Mode mode = FTSParser.Mode.DEFAULT_DISJUNCTION;
    final Connective defaultFieldConnective = Connective.OR;

    class TestMock extends FTSQueryParser.TestNodeBuilder
    {
        private void test(CommonTree initialNode, CommonTree replacedNode)
        {
            if (initialNode.getType() == FTSParser.TERM &&
                    initialNode.getChildCount() == 1 &&
                    initialNode.getChild(0).getType() == FTSParser.STAR)
            {
                // input is the lone star
                Tree node = replacedNode;
                while (true)
                {
                    if (node.getChildCount() == 1)
                    {
                        node = node.getChild(0);
                        if (node.getType() == FTSParser.TERM)
                        {
                            assertEquals("Lone star should be mapped to " + FTSQueryParser.VALUE_REPLACELONESTAR, node.getChildCount(), 2);
                            Tree child1 = node.getChild(0);
                            assertEquals("Lone star should be mapped to " + FTSQueryParser.VALUE_REPLACELONESTAR, child1.getType(), FTSParser.ID);
                            assertEquals("Lone star should be mapped to " + FTSQueryParser.VALUE_REPLACELONESTAR, child1.getText(), "T");
                            Tree child2 = node.getChild(1);
                            assertEquals("Lone star should be mapped to " + FTSQueryParser.VALUE_REPLACELONESTAR, child2.getType(), FTSParser.FIELD_REF);
                            assertEquals("Lone star should be mapped to " + FTSQueryParser.VALUE_REPLACELONESTAR, child2.getChild(0).getText(), "ISNODE");
                            // checking done
                            break;
                        }
                    }
                    else
                    {
                        // wrong structure of the replaced node
                        fail("Lone star should be mapped to " + FTSQueryParser.VALUE_REPLACELONESTAR);
                    }
                }
            }
        }
        
        @Override
        protected CommonTree build(CommonTree fieldReferenceNode, CommonTree argNode, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext,
                Selector selector, Map<String, Column> columnMap, Map<String, CommonTree> templateTrees, String defaultField)
        {
            CommonTree testNode = super.build(fieldReferenceNode, argNode, factory, functionEvaluationContext, selector, columnMap, templateTrees, defaultField);
            test(argNode, testNode);
            return testNode;
        }
    }

    FTSQueryParser.setTestNodeBuilder(new TestMock());
    try
    {
        FTSQueryParser.buildFTS(ftsExpression, new LuceneQueryModelFactory(), functionContext, null, null,
                mode, defaultFieldConnective, templates, keywordsKey, FTSQueryParser.RerankPhase.SINGLE_PASS);
    }
    finally
    {
        // set default logic
        FTSQueryParser.setTestNodeBuilder(new FTSQueryParser.TestNodeBuilder());
    }
}
 
Example 3
public Query getFTSQuery(Pair<SearchParameters, Boolean> searchParametersAndFilter, SolrQueryRequest req, FTSQueryParser.RerankPhase rerankPhase) throws ParseException
{

    SearchParameters searchParameters = searchParametersAndFilter.getFirst();
    Boolean isFilter = searchParametersAndFilter.getSecond();

    QueryModelFactory factory = new LuceneQueryModelFactory<Query, Sort, SyntaxError>();
    AlfrescoFunctionEvaluationContext functionContext = new AlfrescoSolr4FunctionEvaluationContext(namespaceDAO, getDictionaryService(CMISStrictDictionaryService.DEFAULT), NamespaceService.CONTENT_MODEL_1_0_URI, req.getSchema());

    FTSParser.Mode mode;

    if (searchParameters.getDefaultFTSOperator() == org.alfresco.service.cmr.search.SearchParameters.Operator.AND)
    {
        mode = FTSParser.Mode.DEFAULT_CONJUNCTION;
    }
    else
    {
        mode = FTSParser.Mode.DEFAULT_DISJUNCTION;
    }

    Constraint constraint = FTSQueryParser.buildFTS(searchParameters.getQuery(), factory, functionContext, null, null, mode,
            searchParameters.getDefaultFTSOperator() == org.alfresco.service.cmr.search.SearchParameters.Operator.OR ? Connective.OR : Connective.AND,
            searchParameters.getQueryTemplates(), searchParameters.getDefaultFieldName(), rerankPhase);
    org.alfresco.repo.search.impl.querymodel.Query queryModelQuery = factory.createQuery(null, null, constraint, new ArrayList<>());

    @SuppressWarnings("unchecked")
    LuceneQueryBuilder<Query, Sort, ParseException> builder = (LuceneQueryBuilder<Query, Sort, ParseException>) queryModelQuery;

    LuceneQueryBuilderContext<Query, Sort, ParseException> luceneContext = getLuceneQueryBuilderContext(searchParameters, req, CMISStrictDictionaryService.DEFAULT, rerankPhase);

    Set<String> selectorGroup = null;
    if (queryModelQuery.getSource() != null)
    {
        List<Set<String>> selectorGroups = queryModelQuery.getSource().getSelectorGroups(functionContext);

        if (selectorGroups.size() == 0)
        {
            throw new UnsupportedOperationException("No selectors");
        }

        if (selectorGroups.size() > 1)
        {
            throw new UnsupportedOperationException("Advanced join is not supported");
        }

        selectorGroup = selectorGroups.get(0);
    }
    Query luceneQuery = builder.buildQuery(selectorGroup, luceneContext, functionContext);
    // query needs some search parameters fro correct caching ....

    return new ContextAwareQuery(luceneQuery, Boolean.TRUE.equals(isFilter) ? null : searchParameters);
}