mirror of https://github.com/apache/lucene.git
SOLR-13699 - maxChars no longer working on CopyField with Javabin
This commit is contained in:
parent
225fd3d8ee
commit
64a4ca57a8
|
@ -196,8 +196,8 @@ public class DocumentBuilder {
|
|||
|
||||
// Perhaps trim the length of a copy field
|
||||
Object val = v;
|
||||
if( val instanceof String && cf.getMaxChars() > 0 ) {
|
||||
val = cf.getLimitedValue((String)val);
|
||||
if( val instanceof CharSequence && cf.getMaxChars() > 0 ) {
|
||||
val = cf.getLimitedValue(val.toString());
|
||||
}
|
||||
|
||||
addField(out, destinationField, val,
|
||||
|
|
|
@ -651,6 +651,8 @@
|
|||
<!-- EnumType -->
|
||||
<field name="severity" type="severityType" docValues="true" indexed="true" stored="true" multiValued="false"/>
|
||||
|
||||
<field name="max_chars" type="string" indexed="false" stored="true"/>
|
||||
|
||||
|
||||
<!-- Dynamic field definitions. If a field name is not found, dynamicFields
|
||||
will be used if the name matches any of the patterns.
|
||||
|
@ -850,6 +852,8 @@
|
|||
<copyField source="*_dynamic" dest="dynamic_*"/>
|
||||
<copyField source="*_path" dest="*_ancestor"/>
|
||||
|
||||
<copyField source="title" dest="max_chars" maxChars="10"/>
|
||||
|
||||
<!-- example of a custom similarity -->
|
||||
<similarity class="solr.CustomSimilarityFactory">
|
||||
<str name="echo">I am your default sim</str>
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.solr.common.SolrDocument;
|
|||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.apache.solr.common.SolrInputField;
|
||||
import org.apache.solr.common.util.ByteArrayUtf8CharSequence;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
import org.apache.solr.schema.FieldType;
|
||||
import org.junit.After;
|
||||
|
@ -274,4 +275,28 @@ public class DocumentBuilderTest extends SolrTestCaseJ4 {
|
|||
assertTrue(field.stringValue().startsWith("STORED V3|"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyFieldMaxChars() {
|
||||
SolrCore core = h.getCore();
|
||||
|
||||
String testValue = "this is more than 10 characters";
|
||||
String truncatedValue = "this is mo";
|
||||
|
||||
//maxChars with a string value
|
||||
SolrInputDocument doc = new SolrInputDocument();
|
||||
doc.addField( "title", testValue);
|
||||
|
||||
Document out = DocumentBuilder.toDocument(doc, core.getLatestSchema());
|
||||
assertEquals(testValue, out.get("title"));
|
||||
assertEquals(truncatedValue, out.get("max_chars"));
|
||||
|
||||
//maxChars with a ByteArrayUtf8CharSequence
|
||||
doc = new SolrInputDocument();
|
||||
doc.addField( "title", new ByteArrayUtf8CharSequence(testValue));
|
||||
|
||||
out = DocumentBuilder.toDocument(doc, core.getLatestSchema());
|
||||
assertEquals(testValue, out.get("title"));
|
||||
assertEquals(truncatedValue, out.get("max_chars"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue