org.alfresco.repo.search.impl.parsers.FTSQueryParser Java Examples
The following examples show how to use
org.alfresco.repo.search.impl.parsers.FTSQueryParser.
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: AlfrescoSolrDataModel.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
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); return new ContextAwareQuery(luceneQuery, Boolean.TRUE.equals(isFilter) ? null : searchParameters); }
Example #2
Source File: AlfrescoSolrDataModel.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
public Solr4QueryParser getLuceneQueryParser(SearchParameters searchParameters, SolrQueryRequest req, FTSQueryParser.RerankPhase rerankPhase) { Analyzer analyzer = req.getSchema().getQueryAnalyzer(); Solr4QueryParser parser = new Solr4QueryParser(req, Version.LATEST, searchParameters.getDefaultFieldName(), analyzer, rerankPhase); parser.setNamespacePrefixResolver(namespaceDAO); parser.setDictionaryService(getDictionaryService(CMISStrictDictionaryService.DEFAULT)); parser.setTenantService(tenantService); parser.setSearchParameters(searchParameters); parser.setAllowLeadingWildcard(true); Properties props = new CoreDescriptorDecorator(req.getCore().getCoreDescriptor()).getProperties(); int topTermSpanRewriteLimit = Integer.parseInt(props.getProperty("alfresco.topTermSpanRewriteLimit", "1000")); parser.setTopTermSpanRewriteLimit(topTermSpanRewriteLimit); return parser; }
Example #3
Source File: Lucene4QueryBuilderContextSolrImpl.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
/** * Context for building lucene queries * * @param dictionaryService * @param namespacePrefixResolver * @param tenantService * @param searchParameters * @param defaultSearchMLAnalysisMode * @param req * @param model */ public Lucene4QueryBuilderContextSolrImpl(DictionaryService dictionaryService, NamespacePrefixResolver namespacePrefixResolver, TenantService tenantService, SearchParameters searchParameters, MLAnalysisMode defaultSearchMLAnalysisMode, SolrQueryRequest req, AlfrescoSolrDataModel model, FTSQueryParser.RerankPhase rerankPhase) { lqp = new Solr4QueryParser(req, Version.LATEST, searchParameters.getDefaultFieldName(), req.getSchema().getQueryAnalyzer(), rerankPhase); // lqp.setDefaultOperator(AbstractLuceneQueryParser.OR_OPERATOR); lqp.setDictionaryService(dictionaryService); lqp.setNamespacePrefixResolver(namespacePrefixResolver); lqp.setTenantService(tenantService); lqp.setSearchParameters(searchParameters); // lqp.setDefaultSearchMLAnalysisMode(defaultSearchMLAnalysisMode); // lqp.setIndexReader(indexReader); // lqp.setAllowLeadingWildcard(true); // this.namespacePrefixResolver = namespacePrefixResolver; Properties props = new CoreDescriptorDecorator(req.getCore().getCoreDescriptor()).getProperties(); int topTermSpanRewriteLimit = Integer.parseInt(props.getProperty("alfresco.topTermSpanRewriteLimit", "1000")); lqp.setTopTermSpanRewriteLimit(topTermSpanRewriteLimit); lqpa = new Lucene4QueryParserAdaptor(lqp); }
Example #4
Source File: AlfrescoLuceneQParserPlugin.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Query parse() throws SyntaxError { Pair<SearchParameters, Boolean> searchParametersAndFilter = getSearchParameters(); SearchParameters searchParameters = searchParametersAndFilter.getFirst(); Boolean isFilter = searchParametersAndFilter.getSecond(); Solr4QueryParser qp = AlfrescoSolrDataModel.getInstance().getLuceneQueryParser(searchParameters, req, FTSQueryParser.RerankPhase.SINGLE_PASS_WITH_AUTO_PHRASE); Query query; try { // escape / not in a string and not already escaped String escapedQ = escape(searchParameters.getQuery()); query = qp.parse(escapedQ); } catch (ParseException pe) { throw new SyntaxError(pe); } ContextAwareQuery contextAwareQuery = new ContextAwareQuery(query, Boolean.TRUE.equals(isFilter) ? null : searchParameters); if(log.isDebugEnabled()) { log.debug("Lucene QP query as lucene:\t "+contextAwareQuery); } return contextAwareQuery; }
Example #5
Source File: AbstractAlfrescoFtsQueryLanguage.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
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 #6
Source File: AlfrescoSolrDataModel.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
public LuceneQueryBuilderContext<Query, Sort, ParseException> getLuceneQueryBuilderContext(SearchParameters searchParameters, SolrQueryRequest req, String alternativeDictionary, FTSQueryParser.RerankPhase rerankPhase) { return new Lucene4QueryBuilderContextSolrImpl( getDictionaryService(alternativeDictionary), namespaceDAO, tenantService, searchParameters, MLAnalysisMode.EXACT_LANGUAGE, req, this, rerankPhase); }
Example #7
Source File: Solr4QueryParserTest.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void setUp() throws Exception { SolrQueryRequest req = Mockito.mock(SolrQueryRequest.class); parser = new Solr4QueryParser(req, Version.LATEST, "TEXT", null, FTSQueryParser.RerankPhase.SINGLE_PASS); parser.setSearchParameters(searchParameters); }
Example #8
Source File: AuthQueryIT.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** * Queries the index and asserts if the count matches documents returned. * @param queryString * @param count * @throws IOException * @throws org.apache.lucene.queryparser.classic.ParseException */ private void assertFTSQuery(String queryString, int count, String... name) throws IOException, ParseException { SolrServletRequest solrQueryRequest = null; RefCounted<SolrIndexSearcher>refCounted = null; try { solrQueryRequest = new SolrServletRequest(getCore(), null); refCounted = getCore().getSearcher(false, true, null); SolrIndexSearcher solrIndexSearcher = refCounted.get(); SearchParameters searchParameters = new SearchParameters(); searchParameters.setQuery(queryString); Query query = dataModel.getFTSQuery(new Pair<SearchParameters, Boolean>(searchParameters, Boolean.FALSE), solrQueryRequest, FTSQueryParser.RerankPhase.SINGLE_PASS); TopDocs docs = solrIndexSearcher.search(query, count * 2 + 10); Assert.assertEquals(count, docs.totalHits); } finally { refCounted.decref(); solrQueryRequest.close(); } }
Example #9
Source File: AlfrescoSolrDataModel.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
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); }
Example #10
Source File: AbstractAlfrescoSolrIT.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
protected void assertAQuery( String queryString, int count, Locale locale, String[] textAttributes, String[] allAttributes, String... name) { RefCounted<SolrIndexSearcher>refCounted = null; try (SolrServletRequest solrQueryRequest = new SolrServletRequest(getCore(), null)) { refCounted = getCore().getSearcher(); SolrIndexSearcher solrIndexSearcher = refCounted.get(); SearchParameters searchParameters = new SearchParameters(); searchParameters.setQuery(queryString); if (locale != null) { searchParameters.addLocale(locale); } if (textAttributes != null) { for (String textAttribute : textAttributes) { searchParameters.addTextAttribute(textAttribute); } } if (allAttributes != null) { for (String allAttribute : allAttributes) { searchParameters.addAllAttribute(allAttribute); } } Query query = dataModel.getLuceneQueryParser(searchParameters, solrQueryRequest, FTSQueryParser.RerankPhase.SINGLE_PASS).parse(queryString); LOG.debug("####### Query ######:"+query); TopDocs docs = solrIndexSearcher.search(query, count * 2 + 10); assertEquals(fixQueryString(queryString, name), count, docs.totalHits); } catch(Exception exception) { exception.printStackTrace(); throw new RuntimeException(exception); } finally { ofNullable(refCounted).ifPresent(RefCounted::decref); } }