diff --git a/zulia-server/src/main/java/io/zulia/server/index/ZuliaIndex.java b/zulia-server/src/main/java/io/zulia/server/index/ZuliaIndex.java index 2141933e..a4f06e4a 100644 --- a/zulia-server/src/main/java/io/zulia/server/index/ZuliaIndex.java +++ b/zulia-server/src/main/java/io/zulia/server/index/ZuliaIndex.java @@ -63,6 +63,7 @@ import org.apache.lucene.search.IndexOrDocValuesQuery; import org.apache.lucene.search.KnnFloatVectorQuery; import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermInSetQuery; import org.apache.lucene.search.TermQuery; @@ -396,7 +397,7 @@ else if (query.getQfList().size() == 1) { BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder(); booleanQueryBuilder.setMinimumNumberShouldMatch(query.getMm()); for (String field : query.getQfList()) { - TermInSetQuery inSetQuery = getTermInSetQuery(query, field); + Query inSetQuery = getTermInSetQuery(query, field); booleanQueryBuilder.add(inSetQuery, BooleanClause.Occur.SHOULD); } return booleanQueryBuilder.build(); @@ -404,13 +405,23 @@ else if (query.getQfList().size() == 1) { } - private TermInSetQuery getTermInSetQuery(ZuliaQuery.Query query, String field) { + private Query getTermInSetQuery(ZuliaQuery.Query query, String field) { List termBytesRef = new ArrayList<>(); for (String term : query.getTermList()) { termBytesRef.add(new BytesRef(term)); } + IndexFieldInfo indexFieldInfo = indexConfig.getIndexFieldInfo(field); + + String sortField = indexFieldInfo.getInternalSortFieldName(); + + if (sortField != null) { + Query indexQuery = new TermInSetQuery(field, termBytesRef); + Query dvQuery = new TermInSetQuery(MultiTermQuery.DOC_VALUES_REWRITE, sortField, termBytesRef); + return new IndexOrDocValuesQuery(indexQuery, dvQuery); + } + return new TermInSetQuery(field, termBytesRef); } diff --git a/zulia-server/src/test/java/io/zulia/server/test/node/StartStopTest.java b/zulia-server/src/test/java/io/zulia/server/test/node/StartStopTest.java index 44ac06ca..16f61471 100644 --- a/zulia-server/src/test/java/io/zulia/server/test/node/StartStopTest.java +++ b/zulia-server/src/test/java/io/zulia/server/test/node/StartStopTest.java @@ -61,7 +61,7 @@ public void createIndex() throws Exception { ZuliaWorkPool zuliaWorkPool = nodeExtension.getClient(); ClientIndexConfig indexConfig = new ClientIndexConfig(); indexConfig.addDefaultSearchField("title"); - indexConfig.addFieldConfig(FieldConfigBuilder.createString("id").indexAs(DefaultAnalyzers.LC_KEYWORD).sort()); + indexConfig.addFieldConfig(FieldConfigBuilder.createString("id").indexAs(DefaultAnalyzers.LC_KEYWORD)); indexConfig.addFieldConfig(FieldConfigBuilder.createString("title").indexAs(DefaultAnalyzers.STANDARD).sort()); indexConfig.addFieldConfig(FieldConfigBuilder.createString("issn").indexAs(DefaultAnalyzers.LC_KEYWORD).facet().sort()); indexConfig.addFieldConfig(FieldConfigBuilder.createString("eissn").indexAs(DefaultAnalyzers.LC_KEYWORD)); @@ -373,7 +373,7 @@ public void reindex() throws Exception { ZuliaWorkPool zuliaWorkPool = nodeExtension.getClient(); ClientIndexConfig indexConfig = new ClientIndexConfig(); indexConfig.addDefaultSearchField("title"); - indexConfig.addFieldConfig(FieldConfigBuilder.createString("id").indexAs(DefaultAnalyzers.LC_KEYWORD).sort()); + indexConfig.addFieldConfig(FieldConfigBuilder.createString("id").indexAs(DefaultAnalyzers.LC_KEYWORD).sort()); // make it sortable this time indexConfig.addFieldConfig(FieldConfigBuilder.createString("title").indexAs(DefaultAnalyzers.STANDARD).sort()); indexConfig.addFieldConfig(FieldConfigBuilder.createString("issn").indexAs(DefaultAnalyzers.LC_KEYWORD).facet().sort()); indexConfig.addFieldConfig(FieldConfigBuilder.createString("eissn").indexAs(DefaultAnalyzers.LC_KEYWORD).facet()); @@ -383,6 +383,7 @@ public void reindex() throws Exception { indexConfig.addFieldConfig( FieldConfigBuilder.createDate("date").index().facetAs(DateHandling.DATE_YYYY_MM_DD).description("The very special data").sort()); indexConfig.addFieldConfig(FieldConfigBuilder.createString("testList").indexAs(DefaultAnalyzers.STANDARD).facet()); + indexConfig.addFieldConfig(FieldConfigBuilder.createBool("testBool").index().facet().sort()); indexConfig.setIndexName(FACET_TEST_INDEX); indexConfig.setNumberOfShards(1); @@ -727,4 +728,11 @@ public void confirmBuilder() throws Exception { } + @Test + @Order(57) + public void confirmTermInSet() throws Exception { + //try it again with id being sortable + termTestBuilder(); + } + }