mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-04 09:59:16 +00:00
use term query instead of a specialized SpanTermQuery on _all field if positions are omitted
This commit is contained in:
parent
a4acb9a95b
commit
b0b5775c98
@ -25,6 +25,7 @@ import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.lucene.Lucene;
|
||||
import org.elasticsearch.common.lucene.all.AllField;
|
||||
@ -142,12 +143,16 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
||||
|
||||
@Override
|
||||
public Query queryStringTermQuery(Term term) {
|
||||
return new AllTermQuery(term);
|
||||
if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) {
|
||||
return new AllTermQuery(term);
|
||||
}
|
||||
return new TermQuery(term);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query fieldQuery(String value, QueryParseContext context) {
|
||||
return new AllTermQuery(names().createIndexNameTerm(value));
|
||||
return queryStringTermQuery(names().createIndexNameTerm(value));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,12 +20,18 @@
|
||||
package org.elasticsearch.test.unit.index.mapper.all;
|
||||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.lucene.all.AllEntries;
|
||||
import org.elasticsearch.common.lucene.all.AllField;
|
||||
import org.elasticsearch.common.lucene.all.AllTermQuery;
|
||||
import org.elasticsearch.common.lucene.all.AllTokenStream;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.index.mapper.FieldMappers;
|
||||
import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
|
||||
@ -51,7 +57,27 @@ public class SimpleAllMapperTests {
|
||||
assertThat(allEntries.fields().contains("address.last.location"), equalTo(true));
|
||||
assertThat(allEntries.fields().contains("name.last"), equalTo(true));
|
||||
assertThat(allEntries.fields().contains("simple1"), equalTo(true));
|
||||
FieldMapper mapper = docMapper.mappers().smartNameFieldMapper("_all");
|
||||
assertThat(mapper.queryStringTermQuery(new Term("_all", "foobar")), Matchers.instanceOf(AllTermQuery.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllMappersTermQuery() throws Exception {
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/test/unit/index/mapper/all/mapping_omit_positions_on_all.json");
|
||||
DocumentMapper docMapper = MapperTests.newParser().parse(mapping);
|
||||
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/test/unit/index/mapper/all/test1.json");
|
||||
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
|
||||
AllField field = (AllField) doc.getFieldable("_all");
|
||||
AllEntries allEntries = ((AllTokenStream) field.tokenStreamValue()).allEntries();
|
||||
assertThat(allEntries.fields().size(), equalTo(3));
|
||||
assertThat(allEntries.fields().contains("address.last.location"), equalTo(true));
|
||||
assertThat(allEntries.fields().contains("name.last"), equalTo(true));
|
||||
assertThat(allEntries.fields().contains("simple1"), equalTo(true));
|
||||
FieldMapper mapper = docMapper.mappers().smartNameFieldMapper("_all");
|
||||
assertThat(mapper.queryStringTermQuery(new Term("_all", "foobar")), Matchers.instanceOf(TermQuery.class));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleAllMappersWithReparse() throws Exception {
|
||||
|
@ -0,0 +1,56 @@
|
||||
{
|
||||
"person":{
|
||||
"_all":{
|
||||
"enabled": true ,
|
||||
"index_options" : "freqs"
|
||||
},
|
||||
"properties":{
|
||||
"name":{
|
||||
"type":"object",
|
||||
"dynamic":false,
|
||||
"properties":{
|
||||
"first":{
|
||||
"type":"string",
|
||||
"store":"yes",
|
||||
"include_in_all":false
|
||||
},
|
||||
"last":{
|
||||
"type":"string",
|
||||
"index":"not_analyzed"
|
||||
}
|
||||
}
|
||||
},
|
||||
"address":{
|
||||
"type":"object",
|
||||
"include_in_all":false,
|
||||
"properties":{
|
||||
"first":{
|
||||
"properties":{
|
||||
"location":{
|
||||
"type":"string",
|
||||
"store":"yes",
|
||||
"index_name":"firstLocation"
|
||||
}
|
||||
}
|
||||
},
|
||||
"last":{
|
||||
"properties":{
|
||||
"location":{
|
||||
"type":"string",
|
||||
"include_in_all":true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"simple1":{
|
||||
"type":"long",
|
||||
"include_in_all":true
|
||||
},
|
||||
"simple2":{
|
||||
"type":"long",
|
||||
"include_in_all":false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user