/** * Adds (or replaces) the fields targeted by this translation, by default {@code name}, {@code def} and * {@code synonym} with the {@link #getTargetLocale() targeted locale} as a suffix, for example {@code name_es}. * * @throws SolrServerException if communicating with the Solr server failed * @throws IOException if communicating with the Solr server failed */ protected void addFields() throws SolrServerException, IOException { addField("name_" + getTargetLocale().toString(), false); addField("def_" + getTargetLocale().toString(), false); addField("synonym_" + getTargetLocale().toString(), true); }
/** * Adds (or replaces) the fields targeted by this translation, by default {@code name}, {@code def} and * {@code synonym} with the {@link #getTargetLocale() targeted locale} as a suffix, for example {@code name_es}. * * @throws SolrServerException if communicating with the Solr server failed * @throws IOException if communicating with the Solr server failed */ protected void addFields() throws SolrServerException, IOException { addField("name_" + getTargetLocale().toString(), false); addField("def_" + getTargetLocale().toString(), false); addField("synonym_" + getTargetLocale().toString(), true); }
@Override public void initialize() { try { addFieldType(); addFields(); } catch (SolrServerException | IOException ex) { this.logger.error("Failed to add the required Solr fields for {}-{}: {}", getTargetLocale(), getTargetVocabularyId(), ex.getMessage(), ex); } }
@Override public void initialize() { try { addFieldType(); addFields(); } catch (SolrServerException | IOException ex) { this.logger.error("Failed to add the required Solr fields for {}-{}: {}", getTargetLocale(), getTargetVocabularyId(), ex.getMessage(), ex); } }
/** * Adds (or replaces) a field in the schema, set up to copy the values from the field with the locale suffix * trimmed. * * @param name the name of the field to set up * @param multiValued whether the field accepts multiple values or not * @throws SolrServerException if communicating with the Solr server failed * @throws IOException if communicating with the Solr server failed */ protected void addField(String name, boolean multiValued) throws SolrServerException, IOException { Map<String, Object> fieldDefinition = new LinkedHashMap<>(); fieldDefinition.put("name", name); fieldDefinition.put("type", "text_general_" + getTargetLocale().toString()); fieldDefinition.put("indexed", true); fieldDefinition.put("stored", true); fieldDefinition.put("multiValued", multiValued); // Add or redefine the field UpdateResponse response = new SchemaRequest.AddField(fieldDefinition).process(getClient()); if (response.getResponse().get("errors") != null) { response = new SchemaRequest.ReplaceField(fieldDefinition).process(getClient()); } }
/** * Adds (or replaces) a field in the schema, set up to copy the values from the field with the locale suffix * trimmed. * * @param name the name of the field to set up * @param multiValued whether the field accepts multiple values or not * @throws SolrServerException if communicating with the Solr server failed * @throws IOException if communicating with the Solr server failed */ protected void addField(String name, boolean multiValued) throws SolrServerException, IOException { Map<String, Object> fieldDefinition = new LinkedHashMap<>(); fieldDefinition.put("name", name); fieldDefinition.put("type", "text_general_" + getTargetLocale().toString()); fieldDefinition.put("indexed", true); fieldDefinition.put("stored", true); fieldDefinition.put("multiValued", multiValued); // Add or redefine the field UpdateResponse response = new SchemaRequest.AddField(fieldDefinition).process(getClient()); if (response.getResponse().get("errors") != null) { response = new SchemaRequest.ReplaceField(fieldDefinition).process(getClient()); } }
/** * Adds (or replaces) a type definition for the {@link #addFields() fields used by this translation}. * * @throws SolrServerException if communicating with the Solr server failed * @throws IOException if communicating with the Solr server failed */ protected void addFieldType() throws SolrServerException, IOException { FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition(); Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>(); String name = "text_general_" + getTargetLocale().toString(); fieldTypeAttributes.put("name", name); fieldTypeAttributes.put("class", "solr.TextField"); fieldTypeDefinition.setAttributes(fieldTypeAttributes); AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition(); analyzerDefinition.setAttributes( Collections.<String, Object>singletonMap("class", getAnalyzerType())); fieldTypeDefinition.setAnalyzer(analyzerDefinition); try { // The current version (5.5) of SolrJ/EmbeddedSolrServer doesn't support getting schema information, // so we do this the ugly way: try to add, check for errors, try to replace UpdateResponse response = new SchemaRequest.AddFieldType(fieldTypeDefinition).process(getClient()); if (response.getResponse().get("errors") != null) { response = new SchemaRequest.ReplaceFieldType(fieldTypeDefinition).process(getClient()); } this.logger.debug(response.toString()); } catch (Exception ex) { } }
/** * Adds (or replaces) a type definition for the {@link #addFields() fields used by this translation}. * * @throws SolrServerException if communicating with the Solr server failed * @throws IOException if communicating with the Solr server failed */ protected void addFieldType() throws SolrServerException, IOException { FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition(); Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>(); String name = "text_general_" + getTargetLocale().toString(); fieldTypeAttributes.put("name", name); fieldTypeAttributes.put("class", "solr.TextField"); fieldTypeDefinition.setAttributes(fieldTypeAttributes); AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition(); analyzerDefinition.setAttributes( Collections.<String, Object>singletonMap("class", getAnalyzerType())); fieldTypeDefinition.setAnalyzer(analyzerDefinition); try { // The current version (5.5) of SolrJ/EmbeddedSolrServer doesn't support getting schema information, // so we do this the ugly way: try to add, check for errors, try to replace UpdateResponse response = new SchemaRequest.AddFieldType(fieldTypeDefinition).process(getClient()); if (response.getResponse().get("errors") != null) { response = new SchemaRequest.ReplaceFieldType(fieldTypeDefinition).process(getClient()); } this.logger.debug(response.toString()); } catch (Exception ex) { } }