mirror of https://github.com/apache/lucene.git
SOLR-2719: restore ability to specify fl=field-with-dashes
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1300314 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
401924c273
commit
10e3c49303
|
@ -137,6 +137,27 @@ public class ReturnFields
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// like getId, but also accepts dashes for legacy fields
|
||||||
|
String getFieldName(QueryParsing.StrParser sp) throws ParseException {
|
||||||
|
sp.eatws();
|
||||||
|
int id_start = sp.pos;
|
||||||
|
char ch;
|
||||||
|
if (sp.pos < sp.end && (ch = sp.val.charAt(sp.pos)) != '$' && Character.isJavaIdentifierStart(ch)) {
|
||||||
|
sp.pos++;
|
||||||
|
while (sp.pos < sp.end) {
|
||||||
|
ch = sp.val.charAt(sp.pos);
|
||||||
|
if (!Character.isJavaIdentifierPart(ch) && ch != '.' && ch != '-') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sp.pos++;
|
||||||
|
}
|
||||||
|
return sp.val.substring(id_start, sp.pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private void add(String fl, NamedList<String> rename, DocTransformers augmenters, SolrQueryRequest req) {
|
private void add(String fl, NamedList<String> rename, DocTransformers augmenters, SolrQueryRequest req) {
|
||||||
if( fl == null ) {
|
if( fl == null ) {
|
||||||
return;
|
return;
|
||||||
|
@ -153,7 +174,7 @@ public class ReturnFields
|
||||||
|
|
||||||
// short circuit test for a really simple field name
|
// short circuit test for a really simple field name
|
||||||
String key = null;
|
String key = null;
|
||||||
String field = sp.getId(null);
|
String field = getFieldName(sp);
|
||||||
char ch = sp.ch();
|
char ch = sp.ch();
|
||||||
|
|
||||||
if (field != null) {
|
if (field != null) {
|
||||||
|
|
|
@ -20,27 +20,31 @@ package org.apache.solr.search;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.response.transform.*;
|
import org.apache.solr.response.transform.*;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
|
||||||
* See: https://issues.apache.org/jira/browse/SOLR-2719
|
|
||||||
*
|
|
||||||
* This has tests for fields that should work, but are currently broken
|
|
||||||
*/
|
|
||||||
public class ReturnFieldsTest extends SolrTestCaseJ4 {
|
public class ReturnFieldsTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
|
// :TODO: datatypes produced by the functions used may change
|
||||||
|
|
||||||
|
/**
|
||||||
|
* values of the fl param that mean all real fields
|
||||||
|
*/
|
||||||
|
private static String[] ALL_REAL_FIELDS = new String[] { "", "*" };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* values of the fl param that mean all real fields and score
|
||||||
|
*/
|
||||||
|
private static String[] SCORE_AND_REAL_FIELDS = new String[] {
|
||||||
|
"score", "score,*", "*,score"
|
||||||
|
};
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
initCore("solrconfig.xml", "schema12.xml");
|
initCore("solrconfig.xml", "schema12.xml");
|
||||||
createIndex();
|
String v = "how now brown cow";
|
||||||
}
|
assertU(adoc("id","1", "text",v, "text_np", v));
|
||||||
|
v = "now cow";
|
||||||
private static void createIndex() {
|
|
||||||
String v;
|
|
||||||
v="how now brown cow";
|
|
||||||
assertU(adoc("id","1", "text",v, "text_np",v));
|
|
||||||
v="now cow";
|
|
||||||
assertU(adoc("id","2", "text",v, "text_np",v));
|
assertU(adoc("id","2", "text",v, "text_np",v));
|
||||||
assertU(commit());
|
assertU(commit());
|
||||||
}
|
}
|
||||||
|
@ -164,6 +168,13 @@ public class ReturnFieldsTest extends SolrTestCaseJ4 {
|
||||||
assertFalse(rf.wantsAllFields());
|
assertFalse(rf.wantsAllFields());
|
||||||
assertEquals( "[docid]", rf.getTransformer().getName() );
|
assertEquals( "[docid]", rf.getTransformer().getName() );
|
||||||
|
|
||||||
|
rf = new ReturnFields( req("fl", "mydocid:[docid]") );
|
||||||
|
assertFalse( rf.wantsScore() );
|
||||||
|
assertFalse( rf.wantsField( "id" ) );
|
||||||
|
assertFalse(rf.wantsField("xxx"));
|
||||||
|
assertFalse(rf.wantsAllFields());
|
||||||
|
assertEquals( "mydocid", rf.getTransformer().getName() );
|
||||||
|
|
||||||
rf = new ReturnFields( req("fl", "[docid][shard]") );
|
rf = new ReturnFields( req("fl", "[docid][shard]") );
|
||||||
assertFalse( rf.wantsScore() );
|
assertFalse( rf.wantsScore() );
|
||||||
assertFalse(rf.wantsField("xxx"));
|
assertFalse(rf.wantsField("xxx"));
|
||||||
|
@ -185,6 +196,10 @@ public class ReturnFieldsTest extends SolrTestCaseJ4 {
|
||||||
assertTrue(rf.wantsField("name"));
|
assertTrue(rf.wantsField("name"));
|
||||||
assertTrue(rf.wantsField("test"));
|
assertTrue(rf.wantsField("test"));
|
||||||
assertTrue(rf.wantsField("subject"));
|
assertTrue(rf.wantsField("subject"));
|
||||||
|
assertTrue(rf.wantsField("newId"));
|
||||||
|
assertTrue(rf.wantsField("newName"));
|
||||||
|
assertTrue(rf.wantsField("newTest"));
|
||||||
|
assertTrue(rf.wantsField("newSubject"));
|
||||||
assertFalse(rf.wantsField("xxx"));
|
assertFalse(rf.wantsField("xxx"));
|
||||||
assertFalse(rf.wantsAllFields());
|
assertFalse(rf.wantsAllFields());
|
||||||
assertTrue( rf.getTransformer() instanceof RenameFieldsTransformer);
|
assertTrue( rf.getTransformer() instanceof RenameFieldsTransformer);
|
||||||
|
@ -194,16 +209,20 @@ public class ReturnFieldsTest extends SolrTestCaseJ4 {
|
||||||
assertTrue(rf.wantsField("name"));
|
assertTrue(rf.wantsField("name"));
|
||||||
assertTrue(rf.wantsField("test"));
|
assertTrue(rf.wantsField("test"));
|
||||||
assertTrue(rf.wantsField("subject"));
|
assertTrue(rf.wantsField("subject"));
|
||||||
|
assertTrue(rf.wantsField("newId"));
|
||||||
|
assertTrue(rf.wantsField("newName"));
|
||||||
|
assertTrue(rf.wantsField("newTest"));
|
||||||
|
assertTrue(rf.wantsField("newSubject"));
|
||||||
assertFalse(rf.wantsField("xxx"));
|
assertFalse(rf.wantsField("xxx"));
|
||||||
assertFalse(rf.wantsAllFields());
|
assertFalse(rf.wantsAllFields());
|
||||||
assertTrue( rf.getTransformer() instanceof DocTransformers);
|
assertTrue( rf.getTransformer() instanceof DocTransformers);
|
||||||
assertEquals(2, ((DocTransformers)rf.getTransformer()).size());
|
assertEquals(2, ((DocTransformers)rf.getTransformer()).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
// hyphens in field names are not supported in all contexts, but we wanted
|
||||||
|
// the simplest case of fl=foo-bar to work
|
||||||
@Test
|
@Test
|
||||||
public void testTrailingHyphenInFieldName() {
|
public void testHyphenInFieldName() {
|
||||||
//java.lang.NumberFormatException: For input string: "-"
|
|
||||||
ReturnFields rf = new ReturnFields(req("fl", "id-test"));
|
ReturnFields rf = new ReturnFields(req("fl", "id-test"));
|
||||||
assertFalse(rf.wantsScore());
|
assertFalse(rf.wantsScore());
|
||||||
assertTrue(rf.wantsField("id-test"));
|
assertTrue(rf.wantsField("id-test"));
|
||||||
|
@ -211,18 +230,29 @@ public class ReturnFieldsTest extends SolrTestCaseJ4 {
|
||||||
assertFalse(rf.wantsAllFields());
|
assertFalse(rf.wantsAllFields());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
@Test
|
||||||
public void testLeadingHyphenInFieldName() {
|
public void testTrailingDotInFieldName() {
|
||||||
//java.lang.NumberFormatException: For input string: "-"
|
ReturnFields rf = new ReturnFields(req("fl", "id.test"));
|
||||||
ReturnFields rf = new ReturnFields(req("fl", "-idtest"));
|
|
||||||
assertFalse(rf.wantsScore());
|
assertFalse(rf.wantsScore());
|
||||||
assertTrue(rf.wantsField("id-test"));
|
assertTrue(rf.wantsField("id.test"));
|
||||||
|
assertFalse(rf.wantsField("xxx"));
|
||||||
|
assertFalse(rf.wantsAllFields());
|
||||||
|
|
||||||
|
rf = new ReturnFields(req("fl", "test:id.test"));
|
||||||
|
assertFalse(rf.wantsScore());
|
||||||
|
assertTrue(rf.wantsField("id.test"));
|
||||||
|
assertTrue(rf.wantsField("test"));
|
||||||
|
assertFalse(rf.wantsField("xxx"));
|
||||||
|
assertFalse(rf.wantsAllFields());
|
||||||
|
|
||||||
|
rf = new ReturnFields(req("fl", "test.id:id.test"));
|
||||||
|
assertFalse(rf.wantsScore());
|
||||||
|
assertTrue(rf.wantsField("id.test"));
|
||||||
|
assertTrue(rf.wantsField("test.id"));
|
||||||
assertFalse(rf.wantsField("xxx"));
|
assertFalse(rf.wantsField("xxx"));
|
||||||
assertFalse(rf.wantsAllFields());
|
assertFalse(rf.wantsAllFields());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
@Test
|
||||||
public void testTrailingDollarInFieldName() {
|
public void testTrailingDollarInFieldName() {
|
||||||
ReturnFields rf = new ReturnFields(req("fl", "id$test"));
|
ReturnFields rf = new ReturnFields(req("fl", "id$test"));
|
||||||
|
@ -231,37 +261,4 @@ public class ReturnFieldsTest extends SolrTestCaseJ4 {
|
||||||
assertFalse(rf.wantsField("xxx"));
|
assertFalse(rf.wantsField("xxx"));
|
||||||
assertFalse(rf.wantsAllFields());
|
assertFalse(rf.wantsAllFields());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
public void testLeadingDollarInFieldName() {
|
|
||||||
//throws Missing param idtest while parsing function '$idtest'
|
|
||||||
ReturnFields rf = new ReturnFields(req("fl", "$idtest"));
|
|
||||||
assertFalse(rf.wantsScore());
|
|
||||||
assertTrue(rf.wantsField("id$test"));
|
|
||||||
assertFalse(rf.wantsField("xxx"));
|
|
||||||
assertFalse(rf.wantsAllFields());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
public void testTrailingTildeInFieldName() {
|
|
||||||
//Error parsing fieldname: Expected identifier at pos 0 str='~test'
|
|
||||||
ReturnFields rf = new ReturnFields(req("fl", "id~test"));
|
|
||||||
assertFalse(rf.wantsScore());
|
|
||||||
assertTrue(rf.wantsField("id$test"));
|
|
||||||
assertFalse(rf.wantsField("xxx"));
|
|
||||||
assertFalse(rf.wantsAllFields());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
public void testLeadingTildeInFieldName() {
|
|
||||||
//Error parsing fieldname: Expected identifier at pos 0 str='~idtest'
|
|
||||||
ReturnFields rf = new ReturnFields(req("fl", "~idtest"));
|
|
||||||
assertFalse(rf.wantsScore());
|
|
||||||
assertTrue(rf.wantsField("id$test"));
|
|
||||||
assertFalse(rf.wantsField("xxx"));
|
|
||||||
assertFalse(rf.wantsAllFields());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue