use of org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilder 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;
}
use of org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilder in project SearchServices by Alfresco.
the class AlfrescoSolrDataModel method getCMISQuery.
/**
* @param mode CMISQueryMode
* @param searchParametersAndFilter Pair<SearchParameters, Boolean>
* @param req SolrQueryRequest
* @param queryModelQuery Query
* @param cmisVersion CmisVersion
* @param alternativeDictionary String
* @return Query
* @throws ParseException
*/
public Query getCMISQuery(CMISQueryMode mode, Pair<SearchParameters, Boolean> searchParametersAndFilter, SolrQueryRequest req, org.alfresco.repo.search.impl.querymodel.Query queryModelQuery, CmisVersion cmisVersion, String alternativeDictionary) throws ParseException {
SearchParameters searchParameters = searchParametersAndFilter.getFirst();
Boolean isFilter = searchParametersAndFilter.getSecond();
CmisFunctionEvaluationContext functionContext = getCMISFunctionEvaluationContext(mode, cmisVersion, alternativeDictionary);
Set<String> selectorGroup = queryModelQuery.getSource().getSelectorGroups(functionContext).get(0);
LuceneQueryBuilderContext<Query, Sort, ParseException> luceneContext = getLuceneQueryBuilderContext(searchParameters, req, alternativeDictionary, FTSQueryParser.RerankPhase.SINGLE_PASS);
@SuppressWarnings("unchecked") LuceneQueryBuilder<Query, Sort, ParseException> builder = (LuceneQueryBuilder<Query, Sort, ParseException>) queryModelQuery;
org.apache.lucene.search.Query luceneQuery = builder.buildQuery(selectorGroup, luceneContext, functionContext);
ContextAwareQuery contextAwareQuery = new ContextAwareQuery(luceneQuery, Boolean.TRUE.equals(isFilter) ? null : searchParameters);
return contextAwareQuery;
}
Aggregations