Java Code Examples for org.apache.solr.common.util.NamedList#getAll()
The following examples show how to use
org.apache.solr.common.util.NamedList#getAll() .
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: ResponseDataGenerator.java From ambari-logsearch with Apache License 2.0 | 6 votes |
public GraphDataListResponse generateSimpleGraphResponse(QueryResponse response, String hierarchy) { GraphDataListResponse graphInfo = new GraphDataListResponse(); if (response == null) { return graphInfo; } List<List<PivotField>> hirarchicalPivotField = new ArrayList<>(); List<GraphData> dataList = new ArrayList<>(); NamedList<List<PivotField>> namedList = response.getFacetPivot(); if (namedList != null) { hirarchicalPivotField = namedList.getAll(hierarchy); } if (!hirarchicalPivotField.isEmpty()) { dataList = buidGraphData(hirarchicalPivotField.get(0)); } if (!dataList.isEmpty()) { graphInfo.setGraphData(dataList); } return graphInfo; }
Example 2
Source File: PrometheusExporterSettings.java From lucene-solr with Apache License 2.0 | 6 votes |
public static PrometheusExporterSettings from(Node settings) { @SuppressWarnings({"rawtypes"}) NamedList config = DOMUtil.childNodesToNamedList(settings); Builder builder = builder(); @SuppressWarnings({"unchecked", "rawtypes"}) List<NamedList> httpClientSettings = config.getAll("httpClients"); for (@SuppressWarnings({"rawtypes"})NamedList entry : httpClientSettings) { Integer connectionTimeout = (Integer) entry.get("connectionTimeout"); if (connectionTimeout != null) { builder.withConnectionHttpTimeout(connectionTimeout); } Integer readTimeout = (Integer) entry.get("readTimeout"); if (readTimeout != null) { builder.witReadHttpTimeout(readTimeout); } } return builder.build(); }
Example 3
Source File: SolrDocumentSearch.java From BioSolr with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private List<Object> findFacetTree(QueryResponse response, String field) { NamedList<Object> baseResponse = response.getResponse(); NamedList<Object> facetTrees = (NamedList<Object>) baseResponse.findRecursive("facet_counts", "facet_trees"); return facetTrees == null ? null : facetTrees.getAll(field); }
Example 4
Source File: ResponseDataGenerator.java From ambari-logsearch with Apache License 2.0 | 5 votes |
public NodeListResponse generateOneLevelServiceNodeTree(QueryResponse queryResponse, String componentLevelHirachy) { NodeListResponse response = new NodeListResponse(); List<NodeData> datatList = new ArrayList<>(); List<List<PivotField>> listPivotField = new ArrayList<>(); NamedList<List<PivotField>> namedList = queryResponse.getFacetPivot(); if (namedList != null) { listPivotField = namedList.getAll(componentLevelHirachy); } List<PivotField> secondHirarchicalPivotFields = null; if (listPivotField == null || listPivotField.isEmpty()) { return response; } else { secondHirarchicalPivotFields = listPivotField.get(0); } for (PivotField singlePivotField : secondHirarchicalPivotFields) { if (singlePivotField != null) { NodeData comp = new NodeData(); comp.setName("" + singlePivotField.getValue()); List<PivotField> levelList = singlePivotField.getPivot(); List<NameValueData> levelCountList = new ArrayList<>(); comp.setLogLevelCount(levelCountList); if (levelList != null) { for (PivotField levelPivot : levelList) { NameValueData level = new NameValueData(); level.setName(("" + levelPivot.getValue()).toUpperCase()); level.setValue("" + levelPivot.getCount()); levelCountList.add(level); } } datatList.add(comp); } } response.setvNodeList(datatList); return response; }
Example 5
Source File: ClusteringTest.java From solr-spatial-clustering with Apache License 2.0 | 5 votes |
private static int getTotalSize(NamedList<NamedList<?>> clusters) { int result = 0; for (NamedList<?> eachCluster : clusters.getAll("pin")) { result += ((Number) eachCluster.get("size")).intValue(); } return result; }
Example 6
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testWithCursorMark() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true"); params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10"); params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true"); params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "2"); params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "1"); params.add(CommonParams.Q, "lowerfilt:(+fauth)"); params.add(CommonParams.SORT, "id asc"); params.add(CursorMarkParams.CURSOR_MARK_PARAM, CursorMarkParams.CURSOR_MARK_START); SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationList = (NamedList) spellCheck.get("collations"); List<?> collations = (List<?>) collationList.getAll("collation"); assertTrue(collations.size() == 1); }
Example 7
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testZeroTries() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true"); params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10"); params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true"); params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "0"); params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "2"); params.add(CommonParams.Q, "lowerfilt:(+fauth)"); SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationList = (NamedList) spellCheck.get("collations"); List<?> collations = (List<?>) collationList.getAll("collation"); assertTrue(collations.size() == 2); }
Example 8
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testCollateWithGrouping() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellingParams.SPELLCHECK_BUILD, "true"); params.add(SpellingParams.SPELLCHECK_COUNT, "10"); params.add(SpellingParams.SPELLCHECK_COLLATE, "true"); params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "5"); params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1"); params.add(CommonParams.Q, "lowerfilt:(+fauth)"); params.add(GroupParams.GROUP, "true"); params.add(GroupParams.GROUP_FIELD, "id"); //Because a FilterQuery is applied which removes doc id#1 from possible hits, we would //not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1. SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationHolder = (NamedList) spellCheck.get("collations"); List<String> collations = collationHolder.getAll("collation"); assertTrue(collations.size() == 1); }
Example 9
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testCollateWithFilter() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellingParams.SPELLCHECK_BUILD, "true"); params.add(SpellingParams.SPELLCHECK_COUNT, "10"); params.add(SpellingParams.SPELLCHECK_COLLATE, "true"); params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "10"); params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "10"); params.add(CommonParams.Q, "lowerfilt:(+fauth +home +loane)"); params.add(CommonParams.FQ, "NOT(id:1)"); //Because a FilterQuery is applied which removes doc id#1 from possible hits, we would //not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1. SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationHolder = (NamedList) spellCheck.get("collations"); List<String> collations = collationHolder.getAll("collation"); assertTrue(collations.size() > 0); for(String collation : collations) { assertTrue(!collation.equals("lowerfilt:(+faith +hope +loaves)")); } }
Example 10
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testCollationWithRangeQuery() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellingParams.SPELLCHECK_BUILD, "true"); params.add(SpellingParams.SPELLCHECK_COUNT, "10"); params.add(SpellingParams.SPELLCHECK_COLLATE, "true"); params.add(SpellingParams.SPELLCHECK_ALTERNATIVE_TERM_COUNT, "10"); params.add(CommonParams.Q, "id:[1 TO 10] AND lowerfilt:lovw"); { SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationHolder = (NamedList) spellCheck.get("collations"); List<String> collations = collationHolder.getAll("collation"); assertTrue(collations.size()==1); String collation = collations.iterator().next(); System.out.println(collation); assertTrue("Incorrect collation: " + collation,"id:[1 TO 10] AND lowerfilt:love".equals(collation)); } }
Example 11
Source File: V2ApiIntegrationTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testSingleWarning() throws Exception { @SuppressWarnings({"rawtypes"}) NamedList resp = cluster.getSolrClient().request( new V2Request.Builder("/c/"+COLL_NAME+"/_introspect").build()); @SuppressWarnings({"rawtypes"}) List warnings = resp.getAll("WARNING"); assertEquals(1, warnings.size()); }
Example 12
Source File: CdcrRequestHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void init(@SuppressWarnings({"rawtypes"})NamedList args) { super.init(args); if (args != null) { // Configuration of the Update Log Synchronizer Object updateLogSynchonizerParam = args.get(CdcrParams.UPDATE_LOG_SYNCHRONIZER_PARAM); if (updateLogSynchonizerParam != null && updateLogSynchonizerParam instanceof NamedList) { updateLogSynchronizerConfiguration = ((NamedList) updateLogSynchonizerParam).toSolrParams(); } // Configuration of the Replicator Object replicatorParam = args.get(CdcrParams.REPLICATOR_PARAM); if (replicatorParam != null && replicatorParam instanceof NamedList) { replicatorConfiguration = ((NamedList) replicatorParam).toSolrParams(); } // Configuration of the Buffer Object bufferParam = args.get(CdcrParams.BUFFER_PARAM); if (bufferParam != null && bufferParam instanceof NamedList) { bufferConfiguration = ((NamedList) bufferParam).toSolrParams(); } // Configuration of the Replicas replicasConfiguration = new HashMap<>(); @SuppressWarnings({"rawtypes"}) List replicas = args.getAll(CdcrParams.REPLICA_PARAM); for (Object replica : replicas) { if (replica != null && replica instanceof NamedList) { SolrParams params = ((NamedList) replica).toSolrParams(); if (!replicasConfiguration.containsKey(params.get(CdcrParams.SOURCE_COLLECTION_PARAM))) { replicasConfiguration.put(params.get(CdcrParams.SOURCE_COLLECTION_PARAM), new ArrayList<>()); } replicasConfiguration.get(params.get(CdcrParams.SOURCE_COLLECTION_PARAM)).add(params); } } } }
Example 13
Source File: DumpRequestHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings({"unchecked"}) public void init(@SuppressWarnings({"rawtypes"})NamedList args) { super.init(args); if(args !=null) { @SuppressWarnings({"rawtypes"}) NamedList nl = (NamedList) args.get(PluginInfo.DEFAULTS); if(nl!=null) subpaths = nl.getAll("subpath"); } }
Example 14
Source File: FieldMutatingUpdateProcessorFactory.java From lucene-solr with Apache License 2.0 | 5 votes |
public static Collection<SelectorParams> parseSelectorExclusionParams( @SuppressWarnings({"rawtypes"})NamedList args) { Collection<SelectorParams> exclusions = new ArrayList<>(); @SuppressWarnings({"unchecked"}) List<Object> excList = args.getAll("exclude"); for (Object excObj : excList) { if (null == excObj) { throw new SolrException (SolrException.ErrorCode.SERVER_ERROR, "'exclude' init param can not be null"); } if (! (excObj instanceof NamedList) ) { throw new SolrException (SolrException.ErrorCode.SERVER_ERROR, "'exclude' init param must be <lst/>"); } @SuppressWarnings({"rawtypes"}) NamedList exc = (NamedList) excObj; exclusions.add(parseSelectorParams(exc)); if (0 < exc.size()) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unexpected 'exclude' init sub-param(s): '" + args.getName(0) + "'"); } // call once per instance args.remove("exclude"); } return exclusions; }
Example 15
Source File: AddSchemaFieldsUpdateProcessorFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
private static List<TypeMapping> parseTypeMappings(@SuppressWarnings({"rawtypes"})NamedList args) { List<TypeMapping> typeMappings = new ArrayList<>(); @SuppressWarnings({"unchecked"}) List<Object> typeMappingsParams = args.getAll(TYPE_MAPPING_PARAM); for (Object typeMappingObj : typeMappingsParams) { if (null == typeMappingObj) { throw new SolrException(SERVER_ERROR, "'" + TYPE_MAPPING_PARAM + "' init param cannot be null"); } if ( ! (typeMappingObj instanceof NamedList) ) { throw new SolrException(SERVER_ERROR, "'" + TYPE_MAPPING_PARAM + "' init param must be a <lst>"); } @SuppressWarnings({"rawtypes"}) NamedList typeMappingNamedList = (NamedList)typeMappingObj; Object fieldTypeObj = typeMappingNamedList.remove(FIELD_TYPE_PARAM); if (null == fieldTypeObj) { throw new SolrException(SERVER_ERROR, "Each '" + TYPE_MAPPING_PARAM + "' <lst/> must contain a '" + FIELD_TYPE_PARAM + "' <str>"); } if ( ! (fieldTypeObj instanceof CharSequence)) { throw new SolrException(SERVER_ERROR, "'" + FIELD_TYPE_PARAM + "' init param must be a <str>"); } if (null != typeMappingNamedList.get(FIELD_TYPE_PARAM)) { throw new SolrException(SERVER_ERROR, "Each '" + TYPE_MAPPING_PARAM + "' <lst/> may contain only one '" + FIELD_TYPE_PARAM + "' <str>"); } String fieldType = fieldTypeObj.toString(); @SuppressWarnings({"unchecked"}) Collection<String> valueClasses = typeMappingNamedList.removeConfigArgs(VALUE_CLASS_PARAM); if (valueClasses.isEmpty()) { throw new SolrException(SERVER_ERROR, "Each '" + TYPE_MAPPING_PARAM + "' <lst/> must contain at least one '" + VALUE_CLASS_PARAM + "' <str>"); } // isDefault (optional) Boolean isDefault = false; Object isDefaultObj = typeMappingNamedList.remove(IS_DEFAULT_PARAM); if (null != isDefaultObj) { if ( ! (isDefaultObj instanceof Boolean)) { throw new SolrException(SERVER_ERROR, "'" + IS_DEFAULT_PARAM + "' init param must be a <bool>"); } if (null != typeMappingNamedList.get(IS_DEFAULT_PARAM)) { throw new SolrException(SERVER_ERROR, "Each '" + COPY_FIELD_PARAM + "' <lst/> may contain only one '" + IS_DEFAULT_PARAM + "' <bool>"); } isDefault = Boolean.parseBoolean(isDefaultObj.toString()); } Collection<CopyFieldDef> copyFieldDefs = new ArrayList<>(); while (typeMappingNamedList.get(COPY_FIELD_PARAM) != null) { Object copyFieldObj = typeMappingNamedList.remove(COPY_FIELD_PARAM); if ( ! (copyFieldObj instanceof NamedList)) { throw new SolrException(SERVER_ERROR, "'" + COPY_FIELD_PARAM + "' init param must be a <lst>"); } @SuppressWarnings({"rawtypes"}) NamedList copyFieldNamedList = (NamedList)copyFieldObj; // dest Object destObj = copyFieldNamedList.remove(DEST_PARAM); if (null == destObj) { throw new SolrException(SERVER_ERROR, "Each '" + COPY_FIELD_PARAM + "' <lst/> must contain a '" + DEST_PARAM + "' <str>"); } if ( ! (destObj instanceof CharSequence)) { throw new SolrException(SERVER_ERROR, "'" + COPY_FIELD_PARAM + "' init param must be a <str>"); } if (null != copyFieldNamedList.get(COPY_FIELD_PARAM)) { throw new SolrException(SERVER_ERROR, "Each '" + COPY_FIELD_PARAM + "' <lst/> may contain only one '" + COPY_FIELD_PARAM + "' <str>"); } String dest = destObj.toString(); // maxChars (optional) Integer maxChars = 0; Object maxCharsObj = copyFieldNamedList.remove(MAX_CHARS_PARAM); if (null != maxCharsObj) { if ( ! (maxCharsObj instanceof Integer)) { throw new SolrException(SERVER_ERROR, "'" + MAX_CHARS_PARAM + "' init param must be a <int>"); } if (null != copyFieldNamedList.get(MAX_CHARS_PARAM)) { throw new SolrException(SERVER_ERROR, "Each '" + COPY_FIELD_PARAM + "' <lst/> may contain only one '" + MAX_CHARS_PARAM + "' <str>"); } maxChars = Integer.parseInt(maxCharsObj.toString()); } copyFieldDefs.add(new CopyFieldDef(dest, maxChars)); } typeMappings.add(new TypeMapping(fieldType, valueClasses, isDefault, copyFieldDefs)); if (0 != typeMappingNamedList.size()) { throw new SolrException(SERVER_ERROR, "Unexpected '" + TYPE_MAPPING_PARAM + "' init sub-param(s): '" + typeMappingNamedList.toString() + "'"); } args.remove(TYPE_MAPPING_PARAM); } return typeMappings; }
Example 16
Source File: MetricsQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) public static List<MetricsQuery> from(Node node) throws JsonQueryException { List<MetricsQuery> metricsQueries = new ArrayList<>(); NamedList config = DOMUtil.childNodesToNamedList(node); List<NamedList> requests = config.getAll("request"); for (NamedList request : requests) { NamedList query = (NamedList) request.get("query"); NamedList queryParameters = (NamedList) query.get("params"); String path = (String) query.get("path"); String core = (String) query.get("core"); String collection = (String) query.get("collection"); List<String> jsonQueries = (ArrayList<String>) request.get("jsonQueries"); ModifiableSolrParams params = new ModifiableSolrParams(); if (queryParameters != null) { for (Map.Entry<String, String> entrySet : (Set<Map.Entry<String, String>>) queryParameters.asShallowMap().entrySet()) { params.add(entrySet.getKey(), entrySet.getValue()); } } QueryRequest queryRequest = new QueryRequest(params); queryRequest.setPath(path); List<JsonQuery> compiledQueries = new ArrayList<>(); if (jsonQueries != null) { for (String jsonQuery : jsonQueries) { JsonQuery compiledJsonQuery = JsonQuery.compile(jsonQuery); compiledQueries.add(compiledJsonQuery); } } metricsQueries.add(new MetricsQuery( path, params, core, collection, compiledQueries)); } return metricsQueries; }
Example 17
Source File: AbstractQuerqyDismaxQParserPlugin.java From querqy with Apache License 2.0 | 4 votes |
/** * Loads the whole {@link RewriteChain}s from the args and returns a list of * them. */ private RewriteChain loadRewriteChain(final ResourceLoader loader) throws IOException { final NamedList<?> chainConfig = (NamedList<?>) initArgs.get("rewriteChain"); final List<RewriterFactory> factories = new ArrayList<>(); if (chainConfig != null) { @SuppressWarnings("unchecked") final List<NamedList<?>> rewriterConfigs = (List<NamedList<?>>) chainConfig.getAll("rewriter"); if (rewriterConfigs != null) { int count = 0; final Set<String> seenRewriterIds = new HashSet<>(rewriterConfigs.size()); for (NamedList<?> config : rewriterConfigs) { final String className = (String) config.get("class"); @SuppressWarnings("unchecked") final FactoryAdapter<RewriterFactory> factoryAdapter = loader .newInstance(className, FactoryAdapter.class); final String idConf = (String) config.get("id"); final String id = idConf == null ? factoryAdapter.getCreatedClass().getClass().getName() + "#" + count : idConf; final RewriterFactory factory = factoryAdapter.createFactory(id, config, loader); if (!seenRewriterIds.add(factory.getRewriterId())) { throw new IllegalStateException("Rewriter id is not unique: " + id); } factories.add(factory); count++; } } } return new RewriteChain(factories); }
Example 18
Source File: SimpleCommonRulesRewriterFactory.java From querqy with Apache License 2.0 | 4 votes |
@Override public RewriterFactory createFactory(final String id, final NamedList<?> args, final ResourceLoader resourceLoader) throws IOException { final String rulesResourceName = (String) args.get("rules"); if (rulesResourceName == null) { throw new IllegalArgumentException("Property 'rules' not configured"); } final Map<String, SelectionStrategyFactory> selectionStrategyFactories = new HashMap<>(); final NamedList<?> selectionStrategyConfiguration = (NamedList<?>) args.get("rules.selectionStrategy"); if (selectionStrategyConfiguration != null) { @SuppressWarnings("unchecked") final List<NamedList<?>> strategyConfigs = (List<NamedList<?>>) selectionStrategyConfiguration .getAll("strategy"); if (strategyConfigs != null) { for (NamedList<?> config : strategyConfigs) { @SuppressWarnings("unchecked") final FactoryAdapter<SelectionStrategyFactory> factory = resourceLoader .newInstance((String) config.get("class"), FactoryAdapter.class); final String strategyId = (String) config.get("id"); if (selectionStrategyFactories.put(strategyId, factory.createFactory(strategyId, config, resourceLoader)) != null) { throw new IOException("Duplicate id in rules.selectionStrategy: " + id); } } } } final Boolean ignoreCase = args.getBooleanArg("ignoreCase"); // querqy parser for queries that are part of the instructions in the // rules String rulesQuerqyParser = (String) args.get("querqyParser"); QuerqyParserFactory querqyParser = null; if (rulesQuerqyParser != null) { rulesQuerqyParser = rulesQuerqyParser.trim(); if (rulesQuerqyParser.length() > 0) { querqyParser = resourceLoader.newInstance(rulesQuerqyParser, QuerqyParserFactory.class); } } if (querqyParser == null) { querqyParser = new WhiteSpaceQuerqyParserFactory(); } return new querqy.rewrite.commonrules.SimpleCommonRulesRewriterFactory(id, new InputStreamReader(resourceLoader.openResource(rulesResourceName), "UTF-8"), querqyParser, ignoreCase == null || ignoreCase, selectionStrategyFactories, DEFAULT_SELECTION_STRATEGY_FACTORY); }
Example 19
Source File: SuggestionRequestHandler.java From vind with Apache License 2.0 | 4 votes |
public void inform(SolrCore core) { super.inform(core); suggestionService = new SuggestionService(core,this.getInitArgs()); //set default args NamedList args = (NamedList)this.getInitArgs().get("defaults"); SUGGESTION = args.get(SuggestionRequestParams.SUGGESTION) != null ? Boolean.parseBoolean((String)args.get(SuggestionRequestParams.SUGGESTION)) : SUGGESTION; TERM_LIMIT = args.get(SuggestionRequestParams.SUGGESTION_TERM_LIMIT) != null ? Integer.parseInt((String)args.get(SuggestionRequestParams.SUGGESTION_TERM_LIMIT)) : TERM_LIMIT; LIMIT = args.get(SuggestionRequestParams.SUGGESTION_LIMIT) != null ? Integer.parseInt((String)args.get(SuggestionRequestParams.SUGGESTION_LIMIT)) : LIMIT; LIMIT_TYPE = args.get(SuggestionRequestParams.SUGGESTION_LIMIT_TYPE) != null ? LimitType.parse((String) args.get(SuggestionRequestParams.SUGGESTION_LIMIT_TYPE), LIMIT_TYPE) : LIMIT_TYPE; DF = args.get(SuggestionRequestParams.SUGGESTION_DF) != null ? (String) args.get(SuggestionRequestParams.SUGGESTION_DF) : DF; STRATEGY = args.get(SuggestionRequestParams.SUGGESTION_STRATEGY) != null ? Strategy.parse((String)args.get(SuggestionRequestParams.SUGGESTION_STRATEGY), STRATEGY) :STRATEGY; List<String> fields = args.getAll(SuggestionRequestParams.SUGGESTION_FIELD) != null ? args.getAll(SuggestionRequestParams.SUGGESTION_FIELD) : Collections.emptyList(); if(!fields.isEmpty()) { FIELDS = fields.toArray(new String[fields.size()]); } List<String> multivalue_fields = args.getAll(SuggestionRequestParams.SUGGESTION_MULTIVALUE_FIELD) != null ? args.getAll(SuggestionRequestParams.SUGGESTION_MULTIVALUE_FIELD) : Collections.emptyList(); if(!multivalue_fields.isEmpty()) { MULTIVALUE_FIELDS = fields.toArray(new String[multivalue_fields.size()]); } List<String> fqs = args.getAll(CommonParams.FQ) != null ? args.getAll(CommonParams.FQ) : Collections.emptyList(); if(!fqs.isEmpty()) { FQS = fqs.toArray(new String[fields.size()]); } }