Java Code Examples for org.apache.solr.request.SolrQueryRequest#getSchema()
The following examples show how to use
org.apache.solr.request.SolrQueryRequest#getSchema() .
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: QueryParserPlugin.java From FXDesktopSearch with Apache License 2.0 | 6 votes |
@Override public QParser createParser( final String aQueryString, final SolrParams aLocalParams, final SolrParams aParams, final SolrQueryRequest aRequest) { return new QParser(aQueryString, aLocalParams, aParams, aRequest) { @Override public Query parse() throws SyntaxError { final var theSchema = aRequest.getSchema(); final var theParser = new QueryParser(theSchema.getQueryAnalyzer()); try { final var theQuery = theParser.parse(aQueryString, IndexFields.CONTENT); return theQuery; } catch (final Exception e) { throw new SyntaxError(e); } } }; }
Example 2
Source File: ClassificationUpdateProcessorFactory.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) { String trainingFilterQueryString = (params.get(KNN_FILTER_QUERY)); try { if (trainingFilterQueryString != null && !trainingFilterQueryString.isEmpty()) { Query trainingFilterQuery = this.parseFilterQuery(trainingFilterQueryString, params, req); classificationParams.setTrainingFilterQuery(trainingFilterQuery); } } catch (SyntaxError | RuntimeException syntaxError) { throw new SolrException (SolrException.ErrorCode.SERVER_ERROR, "Classification UpdateProcessor Training Filter Query: '" + trainingFilterQueryString + "' is not supported", syntaxError); } IndexSchema schema = req.getSchema(); IndexReader indexReader = req.getSearcher().getIndexReader(); return new ClassificationUpdateProcessor(classificationParams, next, indexReader, schema); }
Example 3
Source File: CursorMarkTest.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testNextCursorMark() throws IOException { final Collection<String> allFieldNames = getAllFieldNames(); final SolrQueryRequest req = req(); final IndexSchema schema = req.getSchema(); final String randomSortString = CursorPagingTest.buildRandomSort(allFieldNames); final SortSpec ss = SortSpecParsing.parseSortSpec(randomSortString, req); final CursorMark previous = new CursorMark(schema, ss); previous.parseSerializedTotem(CURSOR_MARK_START); List<Object> nextValues = Arrays.<Object>asList(buildRandomSortObjects(ss)); final CursorMark next = previous.createNext(nextValues); assertEquals("next values not correct", nextValues, next.getSortValues()); assertEquals("next SortSpec not correct", ss, next.getSortSpec()); try { // append to our random sort string so we know it has wrong num clauses final SortSpec otherSort = SortSpecParsing.parseSortSpec(randomSortString+",id asc", req); CursorMark trash = previous.createNext(Arrays.<Object>asList (buildRandomSortObjects(otherSort))); fail("didn't fail on next with incorrect num of sortvalues"); } catch (AssertionError e) { // NOOP: we're happy } }
Example 4
Source File: UnifiedSolrHighlighter.java From lucene-solr with Apache License 2.0 | 6 votes |
public SolrExtendedUnifiedHighlighter(SolrQueryRequest req) { super(req.getSearcher(), req.getSchema().getIndexAnalyzer()); this.params = req.getParams(); this.schema = req.getSchema(); this.setMaxLength( params.getInt(HighlightParams.MAX_CHARS, DEFAULT_MAX_CHARS)); this.setCacheFieldValCharsThreshold( params.getInt(HighlightParams.CACHE_FIELD_VAL_CHARS_THRESHOLD, DEFAULT_CACHE_CHARS_THRESHOLD)); final RTimerTree timerTree; if (req.getRequestTimer() != null) { //It may be null if not used in a search context. timerTree = req.getRequestTimer(); } else { timerTree = new RTimerTree(); // since null checks are annoying } loadFieldValuesTimer = timerTree.sub("loadFieldValues"); // we assume a new timer, state of STARTED loadFieldValuesTimer.pause(); // state of PAUSED now with about zero time. Will fail if state isn't STARTED. }
Example 5
Source File: AnalyzingQuerqyParserFactory.java From querqy with Apache License 2.0 | 5 votes |
@Override public QuerqyParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { IndexSchema schema = req.getSchema(); Analyzer rewriteAnalyzer = schema.getFieldTypeByName( queryParsingFieldType).getQueryAnalyzer(); Analyzer synonymAnalyzer = (synonymsfieldType != null) ? schema.getFieldTypeByName(synonymsfieldType) .getQueryAnalyzer() : null; return new AnalyzingQuerqyParser(rewriteAnalyzer, synonymAnalyzer); }
Example 6
Source File: LanguageIdentifierUpdateProcessor.java From lucene-solr with Apache License 2.0 | 5 votes |
public LanguageIdentifierUpdateProcessor(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) { super(next); schema = req.getSchema(); initParams(req.getParams()); }
Example 7
Source File: TextResponseWriter.java From lucene-solr with Apache License 2.0 | 5 votes |
public TextResponseWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) { this.writer = writer == null ? null: FastWriter.wrap(writer); this.schema = req.getSchema(); this.req = req; this.rsp = rsp; String indent = req.getParams().get("indent"); if (null == indent || !("off".equals(indent) || "false".equals(indent))){ doIndent=true; } returnFields = rsp.getReturnFields(); if (req.getParams().getBool(CommonParams.OMIT_HEADER, false)) rsp.removeResponseHeader(); }
Example 8
Source File: CursorMarkTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testRoundTripParsing() throws IOException { // for any valid SortSpec, and any legal values, we should be able to round // trip serialize the totem and get the same values back. final Collection<String> allFieldNames = getAllFieldNames(); final SolrQueryRequest req = req(); final IndexSchema schema = req.getSchema(); final int numRandomSorts = atLeast(50); final int numRandomValIters = atLeast(10); for (int i = 0; i < numRandomSorts; i++) { final SortSpec ss = SortSpecParsing.parseSortSpec (CursorPagingTest.buildRandomSort(allFieldNames), req); final CursorMark totemIn = new CursorMark(schema, ss); final CursorMark totemOut = new CursorMark(schema, ss); // trivial case: regardless of sort, "*" should be valid and roundtrippable totemIn.parseSerializedTotem(CURSOR_MARK_START); assertEquals(CURSOR_MARK_START, totemIn.getSerializedTotem()); // values should be null (and still roundtrippable) assertNull(totemIn.getSortValues()); totemOut.setSortValues(null); assertEquals(CURSOR_MARK_START, totemOut.getSerializedTotem()); for (int j = 0; j < numRandomValIters; j++) { final Object[] inValues = buildRandomSortObjects(ss); totemIn.setSortValues(Arrays.<Object>asList(inValues)); totemOut.parseSerializedTotem(totemIn.getSerializedTotem()); final List<Object> out = totemOut.getSortValues(); assertNotNull(out); final Object[] outValues = out.toArray(); assertArrayEquals(inValues, outValues); } } }
Example 9
Source File: FieldAnalysisRequestHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings({"rawtypes"}) protected NamedList doAnalysis(SolrQueryRequest req) throws Exception { FieldAnalysisRequest analysisRequest = resolveAnalysisRequest(req); IndexSchema indexSchema = req.getSchema(); return handleAnalysisRequest(analysisRequest, indexSchema); }
Example 10
Source File: SimpleQParserPlugin.java From lucene-solr with Apache License 2.0 | 4 votes |
public SimpleQParser (String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { super(qstr, localParams, params, req); // Some of the parameters may come in through localParams, so combine them with params. SolrParams defaultParams = SolrParams.wrapDefaults(localParams, params); // This will be used to specify what fields and boosts will be used by SimpleQueryParser. Map<String, Float> queryFields = SolrPluginUtils.parseFieldBoosts(defaultParams.get(SimpleParams.QF)); if (queryFields.isEmpty()) { // It qf is not specified setup up the queryFields map to use the defaultField. String defaultField = defaultParams.get(CommonParams.DF); if (defaultField == null) { // A query cannot be run without having a field or set of fields to run against. throw new IllegalStateException("Neither " + SimpleParams.QF + " nor " + CommonParams.DF + " are present."); } queryFields.put(defaultField, 1.0F); } else { for (Map.Entry<String, Float> queryField : queryFields.entrySet()) { if (queryField.getValue() == null) { // Some fields may be specified without a boost, so default the boost to 1.0 since a null value // will not be accepted by SimpleQueryParser. queryField.setValue(1.0F); } } } // Setup the operations that are enabled for the query. int enabledOps = 0; String opParam = defaultParams.get(SimpleParams.QO); if (opParam == null) { // All operations will be enabled. enabledOps = -1; } else { // Parse the specified enabled operations to be used by the query. String[] operations = opParam.split(","); for (String operation : operations) { Integer enabledOp = OPERATORS.get(operation.trim().toUpperCase(Locale.ROOT)); if (enabledOp != null) { enabledOps |= enabledOp; } } } // Create a SimpleQueryParser using the analyzer from the schema. final IndexSchema schema = req.getSchema(); parser = new SolrSimpleQueryParser(req.getSchema().getQueryAnalyzer(), queryFields, enabledOps, this, schema); // Set the default operator to be either 'AND' or 'OR' for the query. QueryParser.Operator defaultOp = QueryParsing.parseOP(defaultParams.get(QueryParsing.OP)); if (defaultOp == QueryParser.Operator.AND) { parser.setDefaultOperator(BooleanClause.Occur.MUST); } }
Example 11
Source File: SchemaHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
private void handleGET(SolrQueryRequest req, SolrQueryResponse rsp) { try { String path = (String) req.getContext().get("path"); switch (path) { case "/schema": rsp.add(IndexSchema.SCHEMA, req.getSchema().getNamedPropertyValues()); break; case "/schema/version": rsp.add(IndexSchema.VERSION, req.getSchema().getVersion()); break; case "/schema/uniquekey": rsp.add(IndexSchema.UNIQUE_KEY, req.getSchema().getUniqueKeyField().getName()); break; case "/schema/similarity": rsp.add(IndexSchema.SIMILARITY, req.getSchema().getSimilarityFactory().getNamedPropertyValues()); break; case "/schema/name": { final String schemaName = req.getSchema().getSchemaName(); if (null == schemaName) { String message = "Schema has no name"; throw new SolrException(SolrException.ErrorCode.NOT_FOUND, message); } rsp.add(IndexSchema.NAME, schemaName); break; } case "/schema/zkversion": { int refreshIfBelowVersion = req.getParams().getInt("refreshIfBelowVersion"); int zkVersion = -1; IndexSchema schema = req.getSchema(); if (schema instanceof ManagedIndexSchema) { ManagedIndexSchema managed = (ManagedIndexSchema) schema; zkVersion = managed.getSchemaZkVersion(); if (refreshIfBelowVersion != -1 && zkVersion < refreshIfBelowVersion) { log.info("REFRESHING SCHEMA (refreshIfBelowVersion={}, currentVersion={}) before returning version!" , refreshIfBelowVersion, zkVersion); ZkSolrResourceLoader zkSolrResourceLoader = (ZkSolrResourceLoader) req.getCore().getResourceLoader(); ZkIndexSchemaReader zkIndexSchemaReader = zkSolrResourceLoader.getZkIndexSchemaReader(); managed = zkIndexSchemaReader.refreshSchemaFromZk(refreshIfBelowVersion); zkVersion = managed.getSchemaZkVersion(); } } rsp.add("zkversion", zkVersion); break; } default: { List<String> parts = StrUtils.splitSmart(path, '/', true); if (parts.size() > 1 && level2.containsKey(parts.get(1))) { String realName = parts.get(1); String fieldName = IndexSchema.nameMapping.get(realName); String pathParam = level2.get(realName); if (parts.size() > 2) { req.setParams(SolrParams.wrapDefaults(new MapSolrParams(singletonMap(pathParam, parts.get(2))), req.getParams())); } @SuppressWarnings({"rawtypes"}) Map propertyValues = req.getSchema().getNamedPropertyValues(realName, req.getParams()); Object o = propertyValues.get(fieldName); if(parts.size()> 2) { String name = parts.get(2); if (o instanceof List) { @SuppressWarnings({"rawtypes"}) List list = (List) o; for (Object obj : list) { if (obj instanceof SimpleOrderedMap) { @SuppressWarnings({"rawtypes"}) SimpleOrderedMap simpleOrderedMap = (SimpleOrderedMap) obj; if(name.equals(simpleOrderedMap.get("name"))) { rsp.add(fieldName.substring(0, realName.length() - 1), simpleOrderedMap); return; } } } } throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "No such path " + path); } else { rsp.add(fieldName, o); } return; } throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "No such path " + path); } } } catch (Exception e) { rsp.setException(e); } }
Example 12
Source File: ExtendedDismaxQParser.java From lucene-solr with Apache License 2.0 | 4 votes |
public ExtendedDismaxConfiguration(SolrParams localParams, SolrParams params, SolrQueryRequest req) { solrParams = SolrParams.wrapDefaults(localParams, params); schema = req.getSchema(); minShouldMatch = DisMaxQParser.parseMinShouldMatch(schema, solrParams); // req.getSearcher() here causes searcher refcount imbalance userFields = new UserFields(U.parseFieldBoosts(solrParams.getParams(DMP.UF))); try { queryFields = DisMaxQParser.parseQueryFields(schema, solrParams); // req.getSearcher() here causes searcher refcount imbalance } catch (SyntaxError e) { throw new RuntimeException(e); } // Phrase slop array int pslop[] = new int[4]; pslop[0] = solrParams.getInt(DisMaxParams.PS, 0); pslop[2] = solrParams.getInt(DisMaxParams.PS2, pslop[0]); pslop[3] = solrParams.getInt(DisMaxParams.PS3, pslop[0]); List<FieldParams> phraseFields = U.parseFieldBoostsAndSlop(solrParams.getParams(DMP.PF),0,pslop[0]); List<FieldParams> phraseFields2 = U.parseFieldBoostsAndSlop(solrParams.getParams(DMP.PF2),2,pslop[2]); List<FieldParams> phraseFields3 = U.parseFieldBoostsAndSlop(solrParams.getParams(DMP.PF3),3,pslop[3]); allPhraseFields = new ArrayList<>(phraseFields.size() + phraseFields2.size() + phraseFields3.size()); allPhraseFields.addAll(phraseFields); allPhraseFields.addAll(phraseFields2); allPhraseFields.addAll(phraseFields3); tiebreaker = solrParams.getFloat(DisMaxParams.TIE, 0.0f); qslop = solrParams.getInt(DisMaxParams.QS, 0); stopwords = solrParams.getBool(DMP.STOPWORDS, true); mmAutoRelax = solrParams.getBool(DMP.MM_AUTORELAX, false); altQ = solrParams.get( DisMaxParams.ALTQ ); lowercaseOperators = solrParams.getBool(DMP.LOWERCASE_OPS, false); /* * * Boosting Query * * */ boostParams = solrParams.getParams(DisMaxParams.BQ); boostFuncs = solrParams.getParams(DisMaxParams.BF); multBoosts = solrParams.getParams(DMP.MULT_BOOST); splitOnWhitespace = solrParams.getBool(QueryParsing.SPLIT_ON_WHITESPACE, SolrQueryParser.DEFAULT_SPLIT_ON_WHITESPACE); }
Example 13
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 14
Source File: PreAnalyzedUpdateProcessorFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) { return new PreAnalyzedUpdateProcessor(getSelector(), next, req.getSchema(), parser); }
Example 15
Source File: AtomicUpdateDocumentMerger.java From lucene-solr with Apache License 2.0 | 4 votes |
public AtomicUpdateDocumentMerger(SolrQueryRequest queryReq) { schema = queryReq.getSchema(); idField = schema.getUniqueKeyField(); }
Example 16
Source File: AlfrescoSolrDataModel.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
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; solrSortField = mapAlfrescoField(fieldUse, position, fieldNameAndEnding, luceneField, propertyDef); return solrSortField; }
Example 17
Source File: AlfrescoSolrDataModel.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
/** * * return the stored field associated to potentialProperty parameter */ public String mapStoredProperty(String potentialProperty, SolrQueryRequest req) { if(potentialProperty.equals("asc") || potentialProperty.equals("desc") || potentialProperty.equals("_docid_")) { return potentialProperty; } if(potentialProperty.equalsIgnoreCase("score") || potentialProperty.equalsIgnoreCase("SEARCH_SCORE")) { return "score"; } 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)); } } if (propertyDef == null || propertyDef.getName() == null) { return mapNonPropertyFields(luceneField); } if (isDateOrDatetime(propertyDef.getDataType()) && isDerivedDateField(fieldNameAndEnding.getSecond())) { return getDateDerivedField(propertyDef.getName(), fieldNameAndEnding.getSecond()); } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)) { return getStoredTextField(propertyDef.getName(), fieldNameAndEnding.getSecond()); } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT)) { return getStoredMLTextField(propertyDef.getName(), fieldNameAndEnding.getSecond()); } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT)) { return getStoredContentField(propertyDef.getName(), fieldNameAndEnding.getSecond()); } else { return mapAlfrescoField(FieldUse.FTS, 0, fieldNameAndEnding, luceneField, propertyDef) + fieldNameAndEnding.getSecond(); } }