Skip to content

Commit 63ad8fb

Browse files
[MOD] GUI: full-text position handling revised
1 parent 5e545a0 commit 63ad8fb

2 files changed

Lines changed: 18 additions & 20 deletions

File tree

basex-core/src/main/java/org/basex/query/QueryContext.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public QueryContext(final Context context, final QueryContext parent, final Quer
170170
this.parent = parent;
171171
this.info = info != null ? info : new QueryInfo(context);
172172
this.resources = parent != null ? parent.resources : new QueryResources(this);
173-
this.ftPosData = parent != null ? parent.ftPosData : FTPosData.get(context);
173+
this.ftPosData = parent != null ? parent.ftPosData : null;
174174
this.user = context.user();
175175
}
176176

@@ -565,40 +565,38 @@ public String toString() {
565565
// CLASS METHODS ================================================================================
566566

567567
/**
568-
* This function is called by the GUI.
569-
* Caches the result of the specified query. If all nodes are of the same database
570-
* instance, the returned value will be of type {@link DBNodes}.
568+
* Caches the result of the specified query.
569+
* This function is called by the GUI and must only be called after optimizing the query.
571570
* @param cmd query command
572-
* @param max maximum number of items to cache (negative: return full result)
571+
* @param max maximum number of items to cache
573572
*/
574573
void cache(final AQuery cmd, final int max) {
575574
final ItemList items = new ItemList();
576575
final IntList pres = new IntList();
577576
final Data data = resources.globalData();
577+
if(data != null) ftPosData = new FTPosData(data);
578578
try {
579-
optimize();
580579
run(info.evaluating, () -> {
581580
// evaluates the query
582-
final int mx = max >= 0 ? max : Integer.MAX_VALUE;
583-
final Iter iter = iter();
581+
final Iter iter = updating ? update().iter() : main.iter(this);
584582
Item item;
585583

586584
do {
587585
// collect pre values if a database is opened globally
588586
if(defaultOutput && data != null) {
589-
while((item = next(iter)) != null && item.data() == data && pres.size() < mx) {
587+
while((item = next(iter)) != null && item.data() == data && pres.size() < max) {
590588
pres.add(((DBNode) item).pre());
591589
}
592590
// skip if all results have been collected
593-
if(item == null || pres.size() == mx) break;
591+
if(item == null || pres.size() >= max) break;
594592

595593
// otherwise, add nodes to standard iterator
596594
for(final int pre : pres.finish()) items.add(new DBNode(data, pre));
597595
items.add(item);
598596
}
599597

600598
// use standard iterator
601-
while((item = next(iter)) != null && items.size() < mx) {
599+
while((item = next(iter)) != null && items.size() < max) {
602600
item.cache(false, null);
603601
items.add(item);
604602
}

basex-core/src/main/java/org/basex/query/util/ft/FTPosData.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.*;
44

5-
import org.basex.core.*;
65
import org.basex.data.*;
76
import org.basex.util.*;
87
import org.basex.util.hash.*;
@@ -24,17 +23,18 @@ public final class FTPosData {
2423
/** Number of values. */
2524
private int size;
2625

26+
/**
27+
* Constructor.
28+
*/
29+
public FTPosData() {
30+
}
31+
2732
/**
2833
* Creates a new instance of this class.
29-
* @param context database context
30-
* @return new instance or {@code null}
34+
* @param data data reference
3135
*/
32-
public static FTPosData get(final Context context) {
33-
final Data data = context.data();
34-
if(data == null) return null;
35-
final FTPosData ftp = new FTPosData();
36-
ftp.dt = data;
37-
return ftp;
36+
public FTPosData(final Data data) {
37+
dt = data;
3838
}
3939

4040
/**

0 commit comments

Comments
 (0)