mirror of https://github.com/apache/lucene.git
SOLR-7679: Schema API doesn't take similarity attribute into account when adding field types
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1686491 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
33db301f5f
commit
b68d571781
|
@ -171,6 +171,9 @@ Bug Fixes
|
|||
|
||||
* SOLR-7697: Schema API doesn't take class or luceneMatchVersion attributes into
|
||||
account for the analyzer when adding a new field type. (Marius Grama, Steve Rowe)
|
||||
|
||||
* SOLR-7679: Schema API doesn't take similarity attribute into account when adding
|
||||
field types. (Marius Grama, Steve Rowe)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
|
|
@ -65,9 +65,28 @@ public class FieldTypeXmlAdapter {
|
|||
analyzer = transformAnalyzer(doc, json, "multiTermAnalyzer", "multiterm");
|
||||
if (analyzer != null)
|
||||
fieldType.appendChild(analyzer);
|
||||
|
||||
Element similarity = transformSimilarity(doc, json, "similarity");
|
||||
if (similarity != null)
|
||||
fieldType.appendChild(similarity);
|
||||
|
||||
return fieldType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static Element transformSimilarity(Document doc, Map<String,?> json, String jsonFieldName) {
|
||||
Object jsonField = json.get(jsonFieldName);
|
||||
if (jsonField == null)
|
||||
return null; // it's ok for this field to not exist in the JSON map
|
||||
|
||||
if (!(jsonField instanceof Map))
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid fieldType definition! Expected JSON object for "+
|
||||
jsonFieldName+" not a "+jsonField.getClass().getName());
|
||||
|
||||
Element similarity = doc.createElement("similarity");
|
||||
appendAttrs(similarity, (Map<String,?>)jsonField);
|
||||
return similarity;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static Element transformAnalyzer(Document doc, Map<String,?> json, String jsonFieldName, String analyzerType) {
|
||||
|
|
|
@ -820,9 +820,6 @@ public abstract class FieldType extends FieldProperties {
|
|||
namedPropertyValues.add(getPropertyName(TOKENIZED), isTokenized());
|
||||
// The BINARY property is always false
|
||||
// namedPropertyValues.add(getPropertyName(BINARY), hasProperty(BINARY));
|
||||
if (null != getSimilarityFactory()) {
|
||||
namedPropertyValues.add(SIMILARITY, getSimilarityFactory().getNamedPropertyValues());
|
||||
}
|
||||
if (null != getPostingsFormat()) {
|
||||
namedPropertyValues.add(POSTINGS_FORMAT, getPostingsFormat());
|
||||
}
|
||||
|
@ -843,6 +840,10 @@ public abstract class FieldType extends FieldProperties {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null != getSimilarityFactory()) {
|
||||
namedPropertyValues.add(SIMILARITY, getSimilarityFactory().getNamedPropertyValues());
|
||||
}
|
||||
|
||||
if (isExplicitAnalyzer()) {
|
||||
String analyzerProperty = isExplicitQueryAnalyzer() ? INDEX_ANALYZER : ANALYZER;
|
||||
|
|
|
@ -263,6 +263,18 @@ public class TestBulkSchemaAPI extends RestTestBase {
|
|||
" 'type': 'myWhitespaceTxtField',\n" +
|
||||
" 'stored':true\n" +
|
||||
" },\n" +
|
||||
" 'add-field-type' : {" +
|
||||
" 'name' : 'mySimField',\n" +
|
||||
" 'class':'solr.TextField',\n" +
|
||||
" 'analyzer' : {'tokenizer':{'class':'solr.WhitespaceTokenizerFactory'}},\n" +
|
||||
" 'similarity' : {'class':'org.apache.lucene.misc.SweetSpotSimilarity'}\n" +
|
||||
" },\n"+
|
||||
" 'add-field' : {\n" +
|
||||
" 'name':'a4',\n" +
|
||||
" 'type': 'mySimField',\n" +
|
||||
" 'stored':true,\n" +
|
||||
" 'indexed':true\n" +
|
||||
" },\n" +
|
||||
" 'delete-field' : {'name':'wdf_nocase'},\n" +
|
||||
" 'delete-field-type' : {'name':'wdf_nocase'},\n" +
|
||||
" 'delete-dynamic-field' : {'name':'*_tt'},\n" +
|
||||
|
@ -340,6 +352,16 @@ public class TestBulkSchemaAPI extends RestTestBase {
|
|||
assertNotNull("field a3 not created", m);
|
||||
assertEquals("myNewTxtField", m.get("type"));
|
||||
|
||||
m = getObj(harness, "mySimField", "fieldTypes");
|
||||
assertNotNull(m);
|
||||
m = (Map)m.get("similarity");
|
||||
assertNotNull(m);
|
||||
assertEquals("org.apache.lucene.misc.SweetSpotSimilarity", m.get("class"));
|
||||
|
||||
m = getObj(harness, "a4", "fields");
|
||||
assertNotNull("field a4 not created", m);
|
||||
assertEquals("mySimField", m.get("type"));
|
||||
|
||||
m = getObj(harness, "myWhitespaceTxtField", "fieldTypes");
|
||||
assertNotNull(m);
|
||||
|
||||
|
|
Loading…
Reference in New Issue