Skip to content

Commit

Permalink
feat(index): make SolrStaticField + SolrDynamicField buildable from S…
Browse files Browse the repository at this point in the history
…olrJ field Map<String,Object> IQSS#5989
  • Loading branch information
poikilotherm committed Aug 26, 2021
1 parent b5a6c9b commit 15e1034
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,24 @@ boolean isValidName(String name) {
if (name == null) return false;
return validNameMatcher.reset(name).matches();
}

/**
* Create a modelled Solr Field from a raw schema response, containing the attributes.
*
* @param rawMap The attributes map as given by {@ SchemaResponse}
* @return An instance of the Solr Field ready for our internal usage.
* @throws IllegalArgumentException if any attributes are not known/invalid or the type has not been implemented by us
*/
public static SolrDynamicField build(Map<String,Object> rawMap) throws IllegalArgumentException {
Map<SolrFieldProperty, String> properties = SolrField.convertToProperties(rawMap);

String name = properties.remove(SolrFieldProperty.NAME);
String typeName = properties.remove(SolrFieldProperty.TYPE);
SolrFieldType type = SolrFieldType.ALL.stream()
.filter(t -> t.getName().equals(typeName))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Given type \""+typeName+"\" from Solr not implemented"));

return new SolrDynamicField(name, type, properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,24 @@ public SolrStaticField(String nameProperty, SolrFieldType type, Map<SolrFieldPro
throw new IllegalArgumentException("Given properties map may not override fields name or type.");
this.properties.putAll(properties);
}

/**
* Create a modelled Solr Field from a raw schema response, containing the attributes.
*
* @param rawMap The attributes map as given by {@ SchemaResponse}
* @return An instance of the Solr Field ready for our internal usage.
* @throws IllegalArgumentException if any attributes are not known/invalid or the type has not been implemented by us
*/
public static SolrStaticField build(Map<String,Object> rawMap) throws IllegalArgumentException {
Map<SolrFieldProperty, String> properties = SolrField.convertToProperties(rawMap);

String name = properties.remove(SolrFieldProperty.NAME);
String typeName = properties.remove(SolrFieldProperty.TYPE);
SolrFieldType type = SolrFieldType.ALL.stream()
.filter(t -> t.getName().equals(typeName))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Given type \""+typeName+"\" from Solr not implemented"));

return new SolrStaticField(name, type, properties);
}
}

0 comments on commit 15e1034

Please sign in to comment.