Search in sources :

Example 1 with AlfrescoFunctionEvaluationContext

use of org.alfresco.repo.search.impl.parsers.AlfrescoFunctionEvaluationContext in project SearchServices by Alfresco.

the class AlfrescoSolrDataModel method getFTSQuery.

/**
 * @param searchParametersAndFilter Pair<SearchParameters, Boolean>
 * @param req SolrQueryRequest
 * @return Query
 * @throws ParseException
 */
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<Ordering>());
    @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 ....
    ContextAwareQuery contextAwareQuery = new ContextAwareQuery(luceneQuery, Boolean.TRUE.equals(isFilter) ? null : searchParameters);
    return contextAwareQuery;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Query(org.apache.lucene.search.Query) Constraint(org.alfresco.repo.search.impl.querymodel.Constraint) FTSParser(org.alfresco.repo.search.impl.parsers.FTSParser) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) LuceneQueryModelFactory(org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory) LuceneQueryBuilder(org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilder) Ordering(org.alfresco.repo.search.impl.querymodel.Ordering) Sort(org.apache.lucene.search.Sort) AlfrescoFunctionEvaluationContext(org.alfresco.repo.search.impl.parsers.AlfrescoFunctionEvaluationContext) ParseException(org.apache.lucene.queryparser.classic.ParseException) LuceneQueryModelFactory(org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory) QueryModelFactory(org.alfresco.repo.search.impl.querymodel.QueryModelFactory)

Example 2 with AlfrescoFunctionEvaluationContext

use of org.alfresco.repo.search.impl.parsers.AlfrescoFunctionEvaluationContext in project SearchServices by Alfresco.

the class AlfrescoSolrDataModel method mapProperty.

public String mapProperty(String potentialProperty, FieldUse fieldUse, SolrQueryRequest req, int position) {
    if (potentialProperty.equals("asc") || potentialProperty.equals("desc") || potentialProperty.equals("_docid_")) {
        return potentialProperty;
    }
    if (potentialProperty.equalsIgnoreCase("score") || potentialProperty.equalsIgnoreCase("SEARCH_SCORE")) {
        return "score";
    }
    if (req.getSchema().getFieldOrNull(potentialProperty) != null) {
        return mapNonPropertyFields(potentialProperty);
    }
    AlfrescoFunctionEvaluationContext functionContext = new AlfrescoSolr4FunctionEvaluationContext(getNamespaceDAO(), getDictionaryService(CMISStrictDictionaryService.DEFAULT), NamespaceService.CONTENT_MODEL_1_0_URI, req.getSchema());
    Pair<String, String> fieldNameAndEnding = QueryParserUtils.extractFieldNameAndEnding(potentialProperty);
    String luceneField = functionContext.getLuceneFieldName(fieldNameAndEnding.getFirst());
    PropertyDefinition propertyDef = getPropertyDefinition(fieldNameAndEnding.getFirst());
    // Retry scan using luceneField.
    if (propertyDef == null) {
        if (luceneField.contains("@")) {
            int index = luceneField.lastIndexOf("@");
            propertyDef = getPropertyDefinition(luceneField.substring(index + 1));
        }
    }
    String solrSortField = null;
    if (propertyDef != null) {
        IndexedField fields = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), getTextField(fieldNameAndEnding.getSecond()), fieldUse);
        if (fields.getFields().size() > 0) {
            if (fields.getFields().size() > position) {
                solrSortField = fields.getFields().get(position).getField();
            } else {
                solrSortField = fields.getFields().get(0).getField();
            }
        } else {
            solrSortField = mapNonPropertyFields(luceneField);
        }
    } else {
        solrSortField = mapNonPropertyFields(luceneField);
    }
    return solrSortField;
}
Also used : AlfrescoFunctionEvaluationContext(org.alfresco.repo.search.impl.parsers.AlfrescoFunctionEvaluationContext) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) Constraint(org.alfresco.repo.search.impl.querymodel.Constraint)

Aggregations

AlfrescoFunctionEvaluationContext (org.alfresco.repo.search.impl.parsers.AlfrescoFunctionEvaluationContext)2 Constraint (org.alfresco.repo.search.impl.querymodel.Constraint)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 FTSParser (org.alfresco.repo.search.impl.parsers.FTSParser)1 Ordering (org.alfresco.repo.search.impl.querymodel.Ordering)1 QueryModelFactory (org.alfresco.repo.search.impl.querymodel.QueryModelFactory)1 LuceneQueryBuilder (org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilder)1 LuceneQueryModelFactory (org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory)1 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)1 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 Query (org.apache.lucene.search.Query)1 Sort (org.apache.lucene.search.Sort)1