/** * Load the datatype analyzer config file specified by the schema. * <p/> * This should be called whenever the datatype analyzer configuration file changes. */ private void loadDatatypeConfig(final IndexSchema schema) { InputStream is; log.info("Loading datatype analyzer configuration file at " + datatypeAnalyzerConfigPath); try { is = schema.getResourceLoader().openResource(datatypeAnalyzerConfigPath); } catch (final IOException e) { log.error("Error loading datatype analyzer configuration file at " + datatypeAnalyzerConfigPath, e); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); } try { final SirenDatatypeAnalyzerConfig newConfig = new SirenDatatypeAnalyzerConfig(schema.getResourceLoader(), datatypeAnalyzerConfigPath, new InputSource(is), schema.getDefaultLuceneMatchVersion()); log.info("Read new datatype analyzer configuration " + newConfig); datatypeConfigRef.set(newConfig); } finally { if (is != null) { try { is.close(); } catch (final IOException ignored) { } } } }
/** * When index schema is informed, load the datatype config and append the * SIREn's filters to the tokenizer chain. */ @Override public void inform(final IndexSchema schema) { // load the datatypes this.loadDatatypeConfig(schema); // Append the SIREn's filters and update the index analyzer reference this.setAnalyzer(this.appendSirenFilters( this.getAnalyzer(), this.datatypeConfigRef.get().getDatatypes(), schema.getDefaultLuceneMatchVersion())); // tell the {@link IndexSchema} to refresh its analyzers schema.refreshAnalyzers(); }
@Override protected void init(final IndexSchema schema, final Map<String,String> args) { // first call TextField.init to set omitTermFreqAndPositions to false super.init(schema, args); this.checkFieldTypeProperties(); // initialise specific SIREn's properties this.datatypeAnalyzerConfigPath = args.remove(DATATYPECONFIG_KEY); if (datatypeAnalyzerConfigPath == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "ExtendedJsonField types require a '"+DATATYPECONFIG_KEY+"' parameter: " + this.typeName); } // set the posting format args.put("postingsFormat", Siren10AForPostingsFormat.NAME); this.luceneDefaultVersion = schema.getDefaultLuceneMatchVersion(); // instantiate the index analyzer associated to the field Analyzer indexAnalyzer = new TokenizerChain(new CharFilterFactory[0], this.getTokenizerFactory(args), new TokenFilterFactory[0]); indexAnalyzer = this.appendSirenFilters(indexAnalyzer, this.getDatatypes()); this.setIndexAnalyzer(indexAnalyzer); super.init(schema, args); }