Skip to content

Commit 42a331d

Browse files
committed
GH-5149 Rename MAX_QUERY_DOCUMENTS_KEY to MAX_DOCUMENTS_KEY and MAX_DOCUMENTS_KEY to DEFAULT_NUM_DOCS_KEY
1 parent 3e6454e commit 42a331d

6 files changed

Lines changed: 51 additions & 24 deletions

File tree

core/sail/elasticsearch/src/main/java/org/eclipse/rdf4j/sail/elasticsearch/ElasticsearchIndex.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -737,13 +737,13 @@ public SearchHits search(SearchRequestBuilder request, QueryBuilder query, int n
737737
String[] types = getTypes();
738738
int nDocs;
739739
if (numDocs > 0) {
740-
if (maxQueryDocs > 0 && maxQueryDocs < numDocs) {
741-
nDocs = maxQueryDocs;
740+
if (maxDocs > 0 && maxDocs < numDocs) {
741+
nDocs = maxDocs;
742742
} else {
743743
nDocs = numDocs;
744744
}
745-
} else if (maxDocs > 0) {
746-
nDocs = maxDocs;
745+
} else if (defaultNumDocs > 0) {
746+
nDocs = defaultNumDocs;
747747
} else {
748748
long docCount = client.prepareSearch(indexName)
749749
.setTypes(types)

core/sail/lucene-api/src/main/java/org/eclipse/rdf4j/sail/lucene/AbstractSearchIndex.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public abstract class AbstractSearchIndex implements SearchIndex {
6565
REJECTED_DATATYPES.add("http://www.w3.org/2001/XMLSchema#float");
6666
}
6767

68+
protected int defaultNumDocs;
6869
protected int maxDocs;
69-
protected int maxQueryDocs;
7070

7171
protected Set<String> wktFields = Collections.singleton(SearchFields.getPropertyField(GEO.AS_WKT));
7272

@@ -76,10 +76,10 @@ public abstract class AbstractSearchIndex implements SearchIndex {
7676

7777
@Override
7878
public void initialize(Properties parameters) throws Exception {
79-
String maxDocParam = parameters.getProperty(LuceneSail.MAX_DOCUMENTS_KEY);
80-
maxDocs = (maxDocParam != null) ? Integer.parseInt(maxDocParam) : -1;
81-
String maxQueryDocParam = parameters.getProperty(LuceneSail.MAX_QUERY_DOCUMENTS_KEY);
82-
maxQueryDocs = (maxQueryDocParam != null) ? Integer.parseInt(maxQueryDocParam) : maxDocs;
79+
String maxDocumentsParam = parameters.getProperty(LuceneSail.MAX_DOCUMENTS_KEY);
80+
maxDocs = (maxDocumentsParam != null) ? Integer.parseInt(maxDocumentsParam) : -1;
81+
String defaultNumDocsParam = parameters.getProperty(LuceneSail.DEFAULT_NUM_DOCS_KEY);
82+
defaultNumDocs = (defaultNumDocsParam != null) ? Integer.parseInt(defaultNumDocsParam) : defaultNumDocs;
8383

8484
String wktFieldParam = parameters.getProperty(LuceneSail.WKT_FIELDS);
8585
if (wktFieldParam != null) {

core/sail/lucene-api/src/main/java/org/eclipse/rdf4j/sail/lucene/LuceneSail.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,18 @@ public class LuceneSail extends NotifyingSailWrapper {
290290
public static final String LUCENE_RAMDIR_KEY = "useramdir";
291291

292292
/**
293-
* Set the key "maxDocuments=&lt;n&gt;" as sail parameter to limit the maximum number of documents to return from a
294-
* search query. The default is to return all documents. NB: this may involve extra cost for some SearchIndex
293+
* Set the key "defaultNumDocs=&lt;n&gt;" as sail parameter to limit the maximum number of documents to return from
294+
* a search query. The default is to return all documents. NB: this may involve extra cost for some SearchIndex
295295
* implementations as they may have to determine this number.
296296
*/
297-
public static final String MAX_DOCUMENTS_KEY = "maxDocuments";
297+
public static final String DEFAULT_NUM_DOCS_KEY = "defaultNumDocs";
298298

299299
/**
300-
* Set the key "maxQueryDocuments=&lt;n&gt;" as sail parameter to limit the maximum number of documents the user can
301-
* query at a time to return from a search query. The default is the value of the {@link #MAX_DOCUMENTS_KEY}
300+
* Set the key "maxDocuments=&lt;n&gt;" as sail parameter to limit the maximum number of documents the user can
301+
* query at a time to return from a search query. The default is the value of the {@link #DEFAULT_NUM_DOCS_KEY}
302302
* parameter.
303303
*/
304-
public static final String MAX_QUERY_DOCUMENTS_KEY = "maxQueryDocuments";
304+
public static final String MAX_DOCUMENTS_KEY = "maxDocuments";
305305

306306
/**
307307
* Set this key to configure which fields contain WKT and should be spatially indexed. The value should be a

core/sail/lucene/src/main/java/org/eclipse/rdf4j/sail/lucene/impl/LuceneIndex.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,13 +1006,13 @@ public synchronized TopDocs search(Query query) throws IOException {
10061006
public synchronized TopDocs search(Query query, int numDocs) throws IOException {
10071007
int nDocs;
10081008
if (numDocs > 0) {
1009-
if (maxQueryDocs > 0 && maxQueryDocs < numDocs) {
1010-
nDocs = maxQueryDocs;
1009+
if (maxDocs > 0 && maxDocs < numDocs) {
1010+
nDocs = maxDocs;
10111011
} else {
10121012
nDocs = numDocs;
10131013
}
1014-
} else if (maxDocs > 0) {
1015-
nDocs = maxDocs;
1014+
} else if (defaultNumDocs > 0) {
1015+
nDocs = defaultNumDocs;
10161016
} else {
10171017
nDocs = Math.max(getIndexReader().numDocs(), 1);
10181018
}

core/sail/solr/src/main/java/org/eclipse/rdf4j/sail/solr/SolrIndex.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,13 +585,13 @@ public QueryResponse search(SolrQuery query) throws SolrServerException, IOExcep
585585
public QueryResponse search(SolrQuery query, int numDocs) throws SolrServerException, IOException {
586586
int nDocs;
587587
if (numDocs > 0) {
588-
if (maxQueryDocs > 0 && maxQueryDocs < numDocs) {
589-
nDocs = maxQueryDocs;
588+
if (maxDocs > 0 && maxDocs < numDocs) {
589+
nDocs = maxDocs;
590590
} else {
591591
nDocs = numDocs;
592592
}
593-
} else if (maxDocs > 0) {
594-
nDocs = maxDocs;
593+
} else if (defaultNumDocs > 0) {
594+
nDocs = defaultNumDocs;
595595
} else {
596596
long docCount = client.query(query.setRows(0)).getResults().getNumFound();
597597
nDocs = Math.max((int) Math.min(docCount, Integer.MAX_VALUE), 1);

testsuites/lucene/src/main/java/org/eclipse/testsuite/rdf4j/sail/lucene/AbstractLuceneSailTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,10 +1097,37 @@ public void run() {
10971097
assertEquals(0, exceptions.size(), "Exceptions occurred during testMultithreadedAdd, see stacktraces above");
10981098
}
10991099

1100+
@ParameterizedTest
1101+
@ValueSource(ints = { 1, 2, 3 })
1102+
public void testDefaultNumDocsResult(int numDoc) {
1103+
createTestSail(lc -> lc.setParameter(LuceneSail.DEFAULT_NUM_DOCS_KEY, String.valueOf(numDoc)));
1104+
Repositories.consumeNoTransaction(repository, conn -> {
1105+
try (TupleQueryResult res = conn.prepareTupleQuery(
1106+
"SELECT ?Resource {\n"
1107+
+ " ?Resource <" + MATCHES + "> [\n "
1108+
+ " <" + QUERY + "> \"one\"\n "
1109+
+ " ]. } "
1110+
).evaluate()) {
1111+
for (int k = 0; k < numDoc; k++) {
1112+
assertTrue(res.hasNext(), "missing result #" + k);
1113+
res.next();
1114+
}
1115+
if (res.hasNext()) {
1116+
StringBuilder b = new StringBuilder();
1117+
int r = 0;
1118+
do {
1119+
b.append("\n#").append(r++).append(res.next());
1120+
} while (res.hasNext());
1121+
fail("can't have more than " + numDoc + " result(s)" + b);
1122+
}
1123+
}
1124+
});
1125+
}
1126+
11001127
@ParameterizedTest
11011128
@ValueSource(ints = { 1, 2, 3 })
11021129
public void testMaxNumDocsResult(int numDoc) {
1103-
createTestSail(lc -> lc.setParameter(LuceneSail.MAX_QUERY_DOCUMENTS_KEY, String.valueOf(numDoc)));
1130+
createTestSail(lc -> lc.setParameter(LuceneSail.MAX_DOCUMENTS_KEY, String.valueOf(numDoc)));
11041131
Repositories.consumeNoTransaction(repository, conn -> {
11051132
try (TupleQueryResult res = conn.prepareTupleQuery(
11061133
"SELECT ?Resource {\n"

0 commit comments

Comments
 (0)