Finally removed legacy collection classes
Change-Id: I05948702b76d14a9024cefa3c7c5882e00cb718a
diff --git a/Changes b/Changes
index fe5d4f3..f6b5eb9 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.53 2015-07-31
+0.53 2015-08-04
- [feature] Implemented new KrillCollection (diewald)
This should fix a lot of issues with deleted
documents and negation in virtual collections.
diff --git a/src/main/java/de/ids_mannheim/korap/Krill.java b/src/main/java/de/ids_mannheim/korap/Krill.java
index e026682..0d02b79 100644
--- a/src/main/java/de/ids_mannheim/korap/Krill.java
+++ b/src/main/java/de/ids_mannheim/korap/Krill.java
@@ -217,7 +217,8 @@
}
else if (json.has("collections")) {
- this.addError(899, "Collections are not supported anymore in favour of a single collection");
+ this.addError(899,
+ "Collections are not supported anymore in favour of a single collection");
};
}
catch (QueryException q) {
diff --git a/src/main/java/de/ids_mannheim/korap/KrillCollection.java b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
index ceb6671..14cbec1 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
@@ -93,7 +93,8 @@
this.fromJson(json.get("collection"));
else if (json.has("collections"))
- this.addError(899, "Collections are not supported anymore in favour of a single collection");
+ this.addError(899,
+ "Collections are not supported anymore in favour of a single collection");
}
// Query Exception
@@ -155,7 +156,8 @@
};
- private CollectionBuilder.Interface _fromJson (JsonNode json) throws QueryException {
+ private CollectionBuilder.Interface _fromJson (JsonNode json)
+ throws QueryException {
if (!json.has("@type")) {
throw new QueryException(701,
@@ -189,14 +191,14 @@
// TODO: This isn't stable yet
switch (match) {
- case "match:eq":
- return this.cb.date(key, dateStr);
- case "match:ne":
- return this.cb.date(key, dateStr).not();
- case "match:geq":
- return this.cb.since(key, dateStr);
- case "match:leq":
- return this.cb.till(key, dateStr);
+ case "match:eq":
+ return this.cb.date(key, dateStr);
+ case "match:ne":
+ return this.cb.date(key, dateStr).not();
+ case "match:geq":
+ return this.cb.since(key, dateStr);
+ case "match:leq":
+ return this.cb.till(key, dateStr);
};
throw new QueryException(841, "Match relation unknown for type");
@@ -209,22 +211,26 @@
switch (match) {
- case "match:eq":
- return this.cb.term(key, json.get("value").asText());
- case "match:ne":
- return this.cb.term(key, json.get("value").asText()).not();
+ case "match:eq":
+ return this.cb.term(key, json.get("value").asText());
+ case "match:ne":
+ return this.cb.term(key, json.get("value").asText())
+ .not();
- // This may change - but for now it means the elements are lowercased
- case "match:contains":
- return this.cb.term(key, json.get("value").asText().toLowerCase());
+ // This may change - but for now it means the elements are lowercased
+ case "match:contains":
+ return this.cb.term(key, json.get("value").asText()
+ .toLowerCase());
- case "match:containsnot":
- return this.cb.term(key, json.get("value").asText().toLowerCase()).not();
+ case "match:containsnot":
+ return this.cb.term(key,
+ json.get("value").asText().toLowerCase()).not();
- // <LEGACY>
- case "match:excludes":
- return this.cb.term(key, json.get("value").asText().toLowerCase()).not();
- // </LEGACY>
+ // <LEGACY>
+ case "match:excludes":
+ return this.cb.term(key,
+ json.get("value").asText().toLowerCase()).not();
+ // </LEGACY>
};
throw new QueryException(841, "Match relation unknown for type");
@@ -259,21 +265,23 @@
else if (type.equals("koral:docGroup")) {
if (!json.has("operands") || !json.get("operands").isArray())
- throw new QueryException(842, "Document group needs operand list");
+ throw new QueryException(842,
+ "Document group needs operand list");
CollectionBuilder.Group group;
String operation = "operation:and";
if (json.has("operation"))
- operation = json.get("operation").asText();
+ operation = json.get("operation").asText();
if (operation.equals("operation:or"))
group = this.cb.orGroup();
else if (operation.equals("operation:and"))
group = this.cb.andGroup();
else
- throw new QueryException(810, "Unknown document group operation");
-
+ throw new QueryException(810,
+ "Unknown document group operation");
+
for (JsonNode operand : json.get("operands")) {
group.with(this._fromJson(operand));
};
@@ -282,7 +290,8 @@
// Unknown type
throw new QueryException(813, "Collection type is not supported");
- };
+ };
+
// Returns the number of filters - always one!
@Deprecated
@@ -294,13 +303,15 @@
/**
* Set the collection from a {@link CollectionBuilder} object.
*
- * @param cb The CollectionBuilder object.
+ * @param cb
+ * The CollectionBuilder object.
*/
public KrillCollection fromBuilder (CollectionBuilder.Interface cbi) {
this.cbi = cbi;
return this;
};
+
public CollectionBuilder.Interface getBuilder () {
return this.cbi;
};
@@ -310,12 +321,15 @@
return this.cb;
};
+
public KrillCollection filter (CollectionBuilder.Interface filter) {
return this.fromBuilder(this.cb.andGroup().with(this.cbi).with(filter));
};
+
public KrillCollection extend (CollectionBuilder.Interface extension) {
- return this.fromBuilder(this.cb.orGroup().with(this.cbi).with(extension));
+ return this.fromBuilder(this.cb.orGroup().with(this.cbi)
+ .with(extension));
};
@@ -434,12 +448,13 @@
* This will respect deleted documents.
*
* @param atomic
- * The {@link AtomicReaderContext} to search in.
+ * The {@link AtomicReaderContext} to search in.
* @param accepted
* {@link Bits} vector of accepted documents.
* @throws IOException
*/
- public DocIdSet getDocIdSet (AtomicReaderContext atomic, Bits acceptDocs) throws IOException {
+ public DocIdSet getDocIdSet (AtomicReaderContext atomic, Bits acceptDocs)
+ throws IOException {
int maxDoc = atomic.reader().maxDoc();
FixedBitSet bitset = new FixedBitSet(maxDoc);
@@ -455,7 +470,8 @@
// Init vector
DocIdSet docids = filter.getDocIdSet(atomic, null);
- DocIdSetIterator filterIter = (docids == null) ? null : docids.iterator();
+ DocIdSetIterator filterIter = (docids == null) ? null : docids
+ .iterator();
if (filterIter == null) {
if (!this.cbi.isNegative())
@@ -479,16 +495,16 @@
};
// Remove deleted docs
- return (DocIdSet) BitsFilteredDocIdSet.wrap(
- (DocIdSet) bitset,
- acceptDocs
- );
+ return (DocIdSet) BitsFilteredDocIdSet.wrap((DocIdSet) bitset,
+ acceptDocs);
};
+
public long numberOf (String type) throws IOException {
return this.numberOf("tokens", type);
};
+
/**
* Search for the number of occurrences of different types,
* e.g. <i>documents</i>, <i>sentences</i> etc. in the virtual
@@ -525,7 +541,7 @@
else
return this.docCount();
};
-
+
// Create search term
// This may be prefixed by foundries
Term term = new Term(field, "-:" + type);
@@ -544,10 +560,11 @@
occurrences += this._numberOfAtomic(bits, atomic, term);
if (DEBUG)
- log.debug("Added up to {} for {}/{}", occurrences, field, type);
+ log.debug("Added up to {} for {}/{}", occurrences, field,
+ type);
};
}
-
+
// Something went wrong
catch (IOException e) {
log.warn(e.getMessage());
@@ -577,11 +594,8 @@
// TODO: Reuse a DocsAndPositionsEnum!!
// Start an iterator to fetch all payloads of the term
- DocsAndPositionsEnum docs = termsEnum.docsAndPositions(
- docvec,
- null,
- DocsAndPositionsEnum.FLAG_PAYLOADS
- );
+ DocsAndPositionsEnum docs = termsEnum.docsAndPositions(docvec,
+ null, DocsAndPositionsEnum.FLAG_PAYLOADS);
// The iterator is empty
@@ -605,17 +619,17 @@
// Copy payload with the offset of the BytesRef
payload = docs.getPayload();
if (payload != null) {
- System.arraycopy(payload.bytes, payload.offset, pl, 0, 4);
+ System.arraycopy(payload.bytes, payload.offset, pl, 0,
+ 4);
// Add payload as integer
occurrences += bb.wrap(pl).getInt();
if (DEBUG)
- log.debug("Value for {} incremented by {} to {} in {}",
- term,
- bb.wrap(pl).getInt(),
- occurrences,
- docs.docID());
+ log.debug(
+ "Value for {} incremented by {} to {} in {}",
+ term, bb.wrap(pl).getInt(), occurrences,
+ docs.docID());
};
};
@@ -626,7 +640,7 @@
// Nothing found
return 0;
- };
+ };
/**
diff --git a/src/main/java/de/ids_mannheim/korap/KrillCollectionLegacy.java b/src/main/java/de/ids_mannheim/korap/KrillCollectionLegacy.java
deleted file mode 100644
index 17fa1fe..0000000
--- a/src/main/java/de/ids_mannheim/korap/KrillCollectionLegacy.java
+++ /dev/null
@@ -1,937 +0,0 @@
-package de.ids_mannheim.korap;
-
-import java.util.*;
-import java.io.IOException;
-
-import de.ids_mannheim.korap.*;
-import de.ids_mannheim.korap.util.KrillDate;
-import de.ids_mannheim.korap.util.QueryException;
-import de.ids_mannheim.korap.collection.BooleanFilter;
-import de.ids_mannheim.korap.collection.RegexFilter;
-import de.ids_mannheim.korap.collection.FilterOperation;
-import de.ids_mannheim.korap.collection.CollectionBuilderLegacy;
-import de.ids_mannheim.korap.response.Notifications;
-import de.ids_mannheim.korap.response.Result;
-
-import org.apache.lucene.search.spans.SpanQuery;
-import org.apache.lucene.search.*;
-
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.util.FixedBitSet;
-import org.apache.lucene.util.Bits;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.JsonNode;
-
-import java.io.StringWriter;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Create a Virtual Collection of documents by means of a KoralQuery
- * collection object.
- * Alternatively by applying manual filters and extensions on Lucene
- * fields.
- *
- * <blockquote><pre>
- * KrillCollectionLegacy kc = new KrillCollectionLegacy(json);
- * kc.filterUIDS("a1", "a2", "a3");
- * </pre></blockquote>
- *
- * <strong>Warning</strong>: This API is deprecated and will
- * be replaced in future versions. It supports legacy versions of
- * KoralQuery that will be disabled.
- *
- * @author diewald
- */
-/*
- * TODO: Clean up for new KoralQuery
- * TODO: Make a cache for the bits
- * Delete it in case of an extension or a filter
- * TODO: Maybe use randomaccessfilterstrategy
- * TODO: Maybe a constantScoreQuery can make things faster?
- * See http://mail-archives.apache.org/mod_mbox/lucene-java-user/
- * 200805.mbox/%3C17080852.post@talk.nabble.com%3E
- */
-public class KrillCollectionLegacy extends Notifications {
- private KrillIndex index;
- private KrillDate created;
- private String id;
- private ArrayList<FilterOperation> filter;
- private int filterCount = 0;
- private JsonNode json;
-
- // Logger
- private final static Logger log = LoggerFactory
- .getLogger(KrillCollection.class);
-
- // This advices the java compiler to ignore all loggings
- public static final boolean DEBUG = false;
-
-
- /**
- * Construct a new KrillCollectionLegacy by passing a KrillIndex.
- *
- * @param index
- * The {@link KrillIndex} object.
- */
- public KrillCollectionLegacy (KrillIndex index) {
- this.index = index;
- this.filter = new ArrayList<FilterOperation>(5);
- };
-
-
- /**
- * Construct a new KrillCollectionLegacy by passing a KoralQuery.
- * This supports collections with the key "collection" and
- * legacy collections with the key "collections".
- *
- * @param jsonString
- * The virtual collection as a KoralQuery.
- */
- public KrillCollectionLegacy (String jsonString) {
- ObjectMapper mapper = new ObjectMapper();
- this.filter = new ArrayList<FilterOperation>(5);
-
- try {
- JsonNode json = mapper.readTree(jsonString);
-
- // Deserialize from recent collections
- if (json.has("collection")) {
- this.fromJson(json.get("collection"));
- }
-
- // Legacy collection serialization
- // This will be removed!
- else if (json.has("collections")) {
- this.addMessage(850,
- "Collections are deprecated in favour of a single collection");
- for (JsonNode collection : json.get("collections")) {
- this.fromJsonLegacy(collection);
- };
- };
- }
- // Some exceptions ...
- catch (QueryException qe) {
- this.addError(qe.getErrorCode(), qe.getMessage());
- }
- catch (IOException e) {
- this.addError(621, "Unable to parse JSON", "KrillCollectionLegacy",
- e.getLocalizedMessage());
- };
- };
-
-
- /**
- * Construct a new KrillCollectionLegacy.
- */
- public KrillCollectionLegacy () {
- this.filter = new ArrayList<FilterOperation>(5);
- };
-
-
- /**
- * Import the "collection" part of a KoralQuery.
- *
- * @param jsonString
- * The "collection" part of a KoralQuery.
- * @throws QueryException
- */
- public KrillCollectionLegacy fromJson (String jsonString) throws QueryException {
- ObjectMapper mapper = new ObjectMapper();
- try {
- this.fromJson((JsonNode) mapper.readTree(jsonString));
- }
- catch (Exception e) {
- this.addError(621, "Unable to parse JSON", "KrillCollection");
- };
-
- return this;
- };
-
-
- /**
- * Import the "collection" part of a KoralQuery.
- *
- * @param json
- * The "collection" part of a KoralQuery
- * as a {@link JsonNode} object.
- * @throws QueryException
- */
- public KrillCollectionLegacy fromJson (JsonNode json) throws QueryException {
- this.json = json;
- this.filter(this._fromJson(json));
- return this;
- };
-
-
- // Create a boolean filter from JSON
- private BooleanFilter _fromJson (JsonNode json) throws QueryException {
- return this._fromJson(json, "tokens");
- };
-
-
- // Create a booleanfilter from JSON
- private BooleanFilter _fromJson (JsonNode json, String field)
- throws QueryException {
- BooleanFilter bfilter = new BooleanFilter();
-
- if (!json.has("@type")) {
- throw new QueryException(701,
- "JSON-LD group has no @type attribute");
- };
-
- String type = json.get("@type").asText();
-
- // Single filter
- if (type.equals("koral:doc")) {
-
- String key = "tokens";
- String valtype = "type:string";
- String match = "match:eq";
-
- if (json.has("key"))
- key = json.get("key").asText();
-
- if (json.has("type"))
- valtype = json.get("type").asText();
-
- // Filter based on date
- if (valtype.equals("type:date")) {
-
- if (!json.has("value"))
- throw new QueryException(612, "Dates require value fields");
-
- String dateStr = json.get("value").asText();
- if (json.has("match"))
- match = json.get("match").asText();
-
- // TODO: This isn't stable yet
- switch (match) {
- case "match:eq":
- bfilter.date(dateStr);
- break;
- case "match:geq":
- bfilter.since(dateStr);
- break;
- case "match:leq":
- bfilter.till(dateStr);
- break;
- };
-
- // No good reason for gt or lt
- return bfilter;
- }
-
- // Filter based on string
- else if (valtype.equals("type:string")) {
- if (json.has("match"))
- match = json.get("match").asText();
-
- if (match.equals("match:eq")) {
- bfilter.and(key, json.get("value").asText());
- }
- else if (match.equals("match:ne")) {
- bfilter.andNot(key, json.get("value").asText());
- }
- // This may change - but for now it means the elements are lowercased
- else if (match.equals("match:contains")) {
- bfilter.and(key, json.get("value").asText().toLowerCase());
- }
- else if (match.equals("match:containsnot")) {
- bfilter.andNot(key, json.get("value").asText().toLowerCase());
- }
- // <LEGACY>
- else if (match.equals("match:excludes")) {
- bfilter.andNot(key, json.get("value").asText().toLowerCase());
- }
- // </LEGACY>
- else {
- throw new QueryException(0, "Unknown match type");
- };
-
- return bfilter;
- }
-
- // Filter based on regex
- else if (valtype.equals("type:regex")) {
- if (json.has("match"))
- match = json.get("match").asText();
-
- if (match.equals("match:eq")) {
- return bfilter.and(key, new RegexFilter(json.get("value")
- .asText()));
- }
- else if (match.equals("match:ne")) {
- return bfilter.andNot(key, new RegexFilter(json
- .get("value").asText()));
- };
-
- // TODO! for excludes and contains
- throw new QueryException(0, "Unknown document type");
- };
-
- // TODO!
- throw new QueryException(0, "Unknown document operation");
- }
-
- // nested group
- else if (type.equals("koral:docGroup")) {
- if (!json.has("operands") || !json.get("operands").isArray())
- throw new QueryException(612, "Groups need operands");
-
- String operation = "operation:and";
- if (json.has("operation"))
- operation = json.get("operation").asText();
-
- BooleanFilter group = new BooleanFilter();
-
- for (JsonNode operand : json.get("operands")) {
- if (operation.equals("operation:and"))
- group.and(this._fromJson(operand, field));
-
- else if (operation.equals("operation:or"))
- group.or(this._fromJson(operand, field));
-
- else
- throw new QueryException(613,
- "Unknown document group operation");
- };
- bfilter.and(group);
- return bfilter;
- }
-
- // Unknown type
- else
- throw new QueryException(613,
- "Collection query type has to be doc or docGroup");
-
- // return new BooleanFilter();
- };
-
-
- /**
- * Import the "collections" part of a KoralQuery.
- * This method is deprecated and will vanish in future versions.
- *
- * @param jsonString
- * The "collections" part of a KoralQuery.
- * @throws QueryException
- */
- @Deprecated
- public KrillCollectionLegacy fromJsonLegacy (String jsonString)
- throws QueryException {
- ObjectMapper mapper = new ObjectMapper();
- try {
- this.fromJsonLegacy((JsonNode) mapper.readValue(jsonString,
- JsonNode.class));
- }
- catch (Exception e) {
- this.addError(621, "Unable to parse JSON", "KrillCollection");
- };
- return this;
- };
-
-
- /**
- * Import the "collections" part of a KoralQuery.
- * This method is deprecated and will vanish in future versions.
- *
- * @param json
- * The "collections" part of a KoralQuery
- * as a {@link JsonNode} object.
- * @throws QueryException
- */
- @Deprecated
- public KrillCollectionLegacy fromJsonLegacy (JsonNode json) throws QueryException {
- if (!json.has("@type"))
- throw new QueryException(701,
- "JSON-LD group has no @type attribute");
-
- if (!json.has("@value"))
- throw new QueryException(851, "Legacy filter need @value fields");
-
- BooleanFilter bf = this._fromJsonLegacy(json.get("@value"), "tokens");
- String type = json.get("@type").asText();
-
- // Filter the collection
- if (type.equals("koral:meta-filter")) {
- if (DEBUG)
- log.trace("Add Filter LEGACY");
- this.filter(bf);
- }
-
- // Extend the collection
- else if (type.equals("koral:meta-extend")) {
- if (DEBUG)
- log.trace("Add Extend LEGACY");
- this.extend(bf);
- };
-
- return this;
- };
-
-
- // Create a boolean filter from a Json string
- @Deprecated
- private BooleanFilter _fromJsonLegacy (JsonNode json, String field)
- throws QueryException {
- BooleanFilter bfilter = new BooleanFilter();
-
- if (!json.has("@type"))
- throw new QueryException(612,
- "JSON-LD group has no @type attribute");
-
- String type = json.get("@type").asText();
-
- if (DEBUG)
- log.trace("@type: " + type);
-
- if (json.has("@field"))
- field = _getFieldLegacy(json);
-
- if (type.equals("koral:term")) {
- if (field != null && json.has("@value"))
- bfilter.and(field, json.get("@value").asText());
- return bfilter;
- }
- else if (type.equals("koral:group")) {
- if (!json.has("relation"))
- throw new QueryException(612, "Group needs relation");
-
- if (!json.has("operands"))
- throw new QueryException(612, "Group needs operand list");
-
- String dateStr, till;
- JsonNode operands = json.get("operands");
-
- if (!operands.isArray())
- throw new QueryException(612, "Group needs operand list");
-
- if (DEBUG)
- log.trace("relation found {}", json.get("relation").asText());
-
- BooleanFilter group = new BooleanFilter();
-
- switch (json.get("relation").asText()) {
- case "between":
- dateStr = _getDateLegacy(json, 0);
- till = _getDateLegacy(json, 1);
- if (dateStr != null && till != null)
- bfilter.between(dateStr, till);
- break;
-
- case "until":
- dateStr = _getDateLegacy(json, 0);
- if (dateStr != null)
- bfilter.till(dateStr);
- break;
-
- case "since":
- dateStr = _getDateLegacy(json, 0);
- if (dateStr != null)
- bfilter.since(dateStr);
- break;
-
- case "equals":
- dateStr = _getDateLegacy(json, 0);
- if (dateStr != null)
- bfilter.date(dateStr);
- break;
-
- case "and":
- if (operands.size() < 1)
- throw new QueryException(612,
- "Operation needs at least two operands");
-
- for (JsonNode operand : operands) {
- group.and(this._fromJsonLegacy(operand, field));
- }
- ;
- bfilter.and(group);
- break;
-
- case "or":
- if (operands.size() < 1)
- throw new QueryException(612,
- "Operation needs at least two operands");
-
- for (JsonNode operand : operands) {
- group.or(this._fromJsonLegacy(operand, field));
- }
- ;
- bfilter.and(group);
- break;
-
- default:
- throw new QueryException(613, "Relation is not supported");
- };
- }
- else {
- throw new QueryException(613,
- "Filter type is not a supported group");
- };
- return bfilter;
- };
-
-
- /**
- * Set the {@link KrillIndex} the virtual collection refers to.
- *
- * @param index
- * The {@link KrillIndex} the virtual collection refers
- * to.
- */
- public void setIndex (KrillIndex index) {
- this.index = index;
- };
-
-
- /**
- * Add a filter by means of a {@link BooleanFilter}.
- *
- * <strong>Warning</strong>: Filters are part of the collections
- * legacy API and may vanish without warning.
- *
- * @param filter
- * The filter to add to the collection.
- * @return The {@link KrillCollectionLegacy} object for chaining.
- */
- // TODO: The checks may not be necessary
- public KrillCollectionLegacy filter (BooleanFilter filter) {
- if (DEBUG)
- log.trace("Added filter: {}", filter.toString());
-
- if (filter == null) {
- this.addWarning(830, "Filter was empty");
- return this;
- };
-
- Filter f = (Filter) new QueryWrapperFilter(filter.toQuery());
- if (f == null) {
- this.addWarning(831, "Filter is not wrappable");
- return this;
- };
- FilterOperation fo = new FilterOperation(f, false);
- if (fo == null) {
- this.addWarning(832, "Filter operation is invalid");
- return this;
- };
- this.filter.add(fo);
- this.filterCount++;
- return this;
- };
-
-
- /**
- * Add a filter by means of a {@link CollectionBuilderLegacy} object.
- *
- * <strong>Warning</strong>: Filters are part of the collections
- * legacy API and may vanish without warning.
- *
- * @param filter
- * The filter to add to the collection.
- * @return The {@link KrillCollectionLegacy} object for chaining.
- */
- public KrillCollectionLegacy filter (CollectionBuilderLegacy filter) {
- return this.filter(filter.getBooleanFilter());
- };
-
-
- /**
- * Add an extension by means of a {@link BooleanFilter}.
- *
- * <strong>Warning</strong>: Extensions are part of the
- * collections
- * legacy API and may vanish without warning.
- *
- * @param extension
- * The extension to add to the collection.
- * @return The {@link KrillCollectionLegacy} object for chaining.
- */
- public KrillCollectionLegacy extend (BooleanFilter extension) {
- if (DEBUG)
- log.trace("Added extension: {}", extension.toString());
-
- this.filter.add(new FilterOperation((Filter) new QueryWrapperFilter(
- extension.toQuery()), true));
- this.filterCount++;
- return this;
- };
-
-
- /**
- * Add an extension by means of a {@link CollectionBuilderLegacy}
- * object.
- *
- * <strong>Warning</strong>: Extensions are part of the
- * collections
- * legacy API and may vanish without warning.
- *
- * @param extension
- * The extension to add to the collection.
- * @return The {@link KrillCollectionLegacy} object for chaining.
- */
- public KrillCollectionLegacy extend (CollectionBuilderLegacy extension) {
- return this.extend(extension.getBooleanFilter());
- };
-
-
- /**
- * Add a filter based on a list of unique document identifiers.
- * UIDs may be indexed in the field "UID".
- *
- * This filter is not part of the legacy API!
- *
- * @param uids
- * The list of unique document identifier.
- * @return The {@link KrillCollectionLegacy} object for chaining.
- */
- public KrillCollectionLegacy filterUIDs (String ... uids) {
- BooleanFilter filter = new BooleanFilter();
- filter.or("UID", uids);
- if (DEBUG)
- log.debug("UID based filter: {}", filter.toString());
- return this.filter(filter);
- };
-
-
- /**
- * Get the list of filters constructing the collection.
- *
- * <strong>Warning</strong>: This is part of the collections
- * legacy API and may vanish without warning.
- *
- * @return The list of filters.
- */
- public List<FilterOperation> getFilters () {
- return this.filter;
- };
-
-
- /**
- * Get a certain {@link FilterOperation} from the list of filters
- * constructing the collection by its numerical index.
- *
- * <strong>Warning</strong>: This is part of the collections
- * legacy API and may vanish without warning.
- *
- * @param index
- * The index position of the requested
- * {@link FilterOperation}.
- * @return The {@link FilterOperation} at the certain list
- * position.
- */
- public FilterOperation getFilter (int index) {
- return this.filter.get(index);
- };
-
-
- /**
- * Get the number of filter operations constructing this
- * collection.
- *
- * <strong>Warning</strong>: This is part of the collections
- * legacy API and may vanish without warning.
- *
- * @return The number of filter operations constructing this
- * collection.
- */
- public int getCount () {
- return this.filterCount;
- };
-
-
- /**
- * Generate a string representatio of the virtual collection.
- *
- * <strong>Warning</strong>: This currently does not generate a
- * valid
- * KoralQuery string, so this may change in a future version.
- *
- * @return A string representation of the virtual collection.
- */
- public String toString () {
- StringBuilder sb = new StringBuilder();
- for (FilterOperation fo : this.filter) {
- sb.append(fo.toString()).append("; ");
- };
- return sb.toString();
- };
-
-
- /**
- * Return the associated KoralQuery collection object
- * as a {@link JsonNode}. This won't work,
- * if the object was build using a CollectionBuilderLegacy,
- * therefore it is limited to mirror a deserialized KoralQuery
- * object.
- *
- * @return The {@link JsonNode} representing the collection object
- * of a deserialized KoralQuery object.
- */
- public JsonNode toJsonNode () {
- return this.json;
- };
-
-
-
- /**
- * Search in the virtual collection.
- * This is mostly used for testing purposes
- * and <strong>is not recommended</strong>
- * as a common search API.
- *
- * Please use {@link KrillQuery#run} instead.
- *
- * @param query
- * a {@link SpanQuery} to apply on the
- * virtual collection.
- * @return A {@link Result} object representing the search's
- * result.
- */
- public Result search (SpanQuery query) {
- /*
-return this.index.search(this, query, 0, (short) 20, true, (short) 5,
- true, (short) 5);
- */
- return null;
- };
-
-
- /**
- * Create a bit vector representing the live documents of the
- * virtual collection to be used in searches.
- *
- * @param The
- * {@link AtomicReaderContext} to search in.
- * @return A bit vector representing the live documents of the
- * virtual collection.
- * @throws IOException
- */
- public FixedBitSet bits (AtomicReaderContext atomic) throws IOException {
- // TODO: Probably use Bits.MatchAllBits(int len)
- boolean noDoc = true;
- FixedBitSet bitset;
-
- // There are filters set
- if (this.filterCount > 0) {
- bitset = new FixedBitSet(atomic.reader().maxDoc());
-
- ArrayList<FilterOperation> filters = (ArrayList<FilterOperation>) this.filter
- .clone();
-
- FilterOperation kcInit = filters.remove(0);
- if (DEBUG)
- log.trace("FILTER: {}", kcInit);
-
- // Init vector
- DocIdSet docids = kcInit.filter.getDocIdSet(atomic, null);
-
- DocIdSetIterator filterIter = docids.iterator();
-
- // The filter has an effect
- if (filterIter != null) {
- if (DEBUG)
- log.trace("InitFilter has effect");
- bitset.or(filterIter);
- noDoc = false;
- };
-
- // Apply all filters sequentially
- for (FilterOperation kc : filters) {
- if (DEBUG)
- log.trace("FILTER: {}", kc);
-
- // TODO: BUG???
- docids = kc.filter.getDocIdSet(atomic, kc.isExtension() ? null
- : bitset);
- filterIter = docids.iterator();
-
- if (filterIter == null) {
- // There must be a better way ...
- if (kc.isFilter()) {
- // TODO: Check if this is really correct!
- // Maybe here is the bug
- bitset.clear(0, bitset.length());
- noDoc = true;
- };
- continue;
- };
- if (kc.isExtension())
- bitset.or(filterIter);
- else
- bitset.and(filterIter);
- };
-
- if (!noDoc) {
- FixedBitSet livedocs = (FixedBitSet) atomic.reader()
- .getLiveDocs();
- if (livedocs != null)
- bitset.and(livedocs);
- };
- }
- else {
- bitset = (FixedBitSet) atomic.reader().getLiveDocs();
- };
-
- return bitset;
- };
-
-
- /**
- * Search for the number of occurrences of different types,
- * e.g. <i>documents</i>, <i>sentences</i> etc. in the virtual
- * collection.
- *
- * @param field
- * The field containing the textual data and the
- * annotations as a string.
- * @param type
- * The type of meta information,
- * e.g. <i>documents</i> or <i>sentences</i> as a
- * string.
- * @return The number of the occurrences.
- * @throws IOException
- * @see KrillIndex#numberOf
- */
- public long numberOf (String field, String type) throws IOException {
- if (this.index == null)
- return (long) -1;
-
- // return this.index.numberOf(this, field, type);
- return (long) 0;
- };
-
-
- /**
- * Search for the number of occurrences of different types,
- * e.g. <i>documents</i>, <i>sentences</i> etc. in the virtual
- * collection, in the <i>base</i> foundry.
- *
- * @param type
- * The type of meta information,
- * e.g. <i>documents</i> or <i>sentences</i> as a
- * string.
- * @return The number of the occurrences.
- * @throws IOException
- * @see KrillIndex#numberOf
- */
- public long numberOf (String type) throws IOException {
- if (this.index == null)
- return (long) -1;
-
- // return this.index.numberOf(this, "tokens", type);
- return (long) 0;
- };
-
-
- // Term relation API is not in use anymore
- /*
- @Deprecated
- public HashMap getTermRelation (String field) throws Exception {
- if (this.index == null) {
- HashMap<String, Long> map = new HashMap<>(1);
- map.put("-docs", (long) 0);
- return map;
- };
-
- return this.index.getTermRelation(this, field);
- };
- */
-
-
- // Term relation API is not in use anymore
- /*
- @Deprecated
- public String getTermRelationJSON (String field) throws IOException {
- ObjectMapper mapper = new ObjectMapper();
- StringWriter sw = new StringWriter();
- sw.append("{\"field\":");
- mapper.writeValue(sw, field);
- sw.append(",");
-
- try {
- HashMap<String, Long> map = this.getTermRelation(field);
-
- sw.append("\"documents\":");
- mapper.writeValue(sw, map.remove("-docs"));
- sw.append(",");
-
- String[] keys = map.keySet().toArray(new String[map.size()]);
-
- HashMap<String, Integer> setHash = new HashMap<>(20);
- ArrayList<HashMap<String, Long>> set = new ArrayList<>(20);
- ArrayList<Long[]> overlap = new ArrayList<>(100);
-
- int count = 0;
- for (String key : keys) {
- if (!key.startsWith("#__")) {
- HashMap<String, Long> simpleMap = new HashMap<>();
- simpleMap.put(key, map.remove(key));
- set.add(simpleMap);
- setHash.put(key, count++);
- };
- };
-
- keys = map.keySet().toArray(new String[map.size()]);
- for (String key : keys) {
- String[] comb = key.substring(3).split(":###:");
- Long[] l = new Long[3];
- l[0] = (long) setHash.get(comb[0]);
- l[1] = (long) setHash.get(comb[1]);
- l[2] = map.remove(key);
- overlap.add(l);
- };
-
- sw.append("\"sets\":");
- mapper.writeValue(sw, (Object) set);
- sw.append(",\"overlaps\":");
- mapper.writeValue(sw, (Object) overlap);
- sw.append(",\"error\":null");
- }
- catch (Exception e) {
- sw.append("\"error\":");
- mapper.writeValue(sw, e.getMessage());
- };
-
- sw.append("}");
- return sw.getBuffer().toString();
- };
- */
-
- // Get legacy field
- @Deprecated
- private static String _getFieldLegacy (JsonNode json) {
- if (!json.has("@field"))
- return (String) null;
-
- String field = json.get("@field").asText();
- return field.replaceFirst("koral:field#", "");
- };
-
-
- // Get legacy date
- @Deprecated
- private static String _getDateLegacy (JsonNode json, int index) {
- if (!json.has("operands"))
- return (String) null;
-
- if (!json.get("operands").has(index))
- return (String) null;
-
- JsonNode date = json.get("operands").get(index);
-
- if (!date.has("@type"))
- return (String) null;
-
- if (!date.get("@type").asText().equals("koral:date"))
- return (String) null;
-
- if (!date.has("@value"))
- return (String) null;
-
- return date.get("@value").asText();
- };
-};
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index c1c0c00..7dc25ee 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -218,8 +218,7 @@
analyzerPerField.put("keywords", new KeywordAnalyzer());
analyzerPerField.put("foundries", new KeywordAnalyzer());
PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(
- new TextAnalyzer(), analyzerPerField
- );
+ new TextAnalyzer(), analyzerPerField);
// Create configuration with base analyzer
this.config = new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer);
@@ -430,9 +429,7 @@
if (field == null || term == null)
return false;
try {
- this.writer().deleteDocuments(
- new Term(field, term)
- );
+ this.writer().deleteDocuments(new Term(field, term));
if (++commitCounter > autoCommit) {
this.commit();
commitCounter = 0;
@@ -1011,7 +1008,7 @@
field);
HashSet<String> fields = (HashSet<String>) new Krill()
- .getMeta().getFields().clone();
+ .getMeta().getFields().clone();
fields.add(field);
@@ -1025,8 +1022,7 @@
match.populateDocument(doc, field, fields);
if (DEBUG)
log.trace("The document has the id '{}' or the sigle '{}'",
- match.getDocID(),
- match.getTextSigle());
+ match.getDocID(), match.getTextSigle());
// Todo:
SearchContext context = match.getContext();
@@ -1034,7 +1030,8 @@
// Search for minimal surrounding sentences
if (extendToSentence) {
- String element = (match.getTextSigle() == null ? "s" : "base/s:s");
+ String element = (match.getTextSigle() == null ? "s"
+ : "base/s:s");
// SUPPORT FOR LEGACY ANNOTATIONS
int[] spanContext = match.expandContextToSpan(element);
@@ -1043,8 +1040,7 @@
log.trace("Extend to sentence element '{}'", element);
// </legacy>
- if (spanContext[0] >= 0 &&
- spanContext[0] < spanContext[1]) {
+ if (spanContext[0] >= 0 && spanContext[0] < spanContext[1]) {
match.setStartPos(spanContext[0]);
match.setEndPos(spanContext[1]);
match.startMore = false;
@@ -1222,7 +1218,7 @@
// Todo: Make kr subclassing ks - so ks has a method for a new Result!
Result kr = new Result(query.toString(), meta.getStartIndex(),
meta.getCount(), meta.getContext());
-
+
// Set version info to result
if (this.getVersion() != null)
kr.setVersion(this.getVersion());
@@ -1350,8 +1346,8 @@
int docID = atomic.docBase + localDocID;
// Do not load all of this, in case the doc is the same!
- Document doc = (fields != null) ? lreader.document(localDocID, fields) :
- lreader.document(localDocID);
+ Document doc = (fields != null) ? lreader.document(
+ localDocID, fields) : lreader.document(localDocID);
// Create new Match
Match match = new Match(pto, localDocID, spans.start(),
@@ -1451,6 +1447,7 @@
return kr;
};
+
public void getFields () {
/*
* Return a map of key, value pairs:
@@ -1460,10 +1457,12 @@
*/
};
+
public void getValues (String field) {
};
+
// Collect matches
public MatchCollector collect (Krill ks, MatchCollector mc) {
if (DEBUG)
diff --git a/src/main/java/de/ids_mannheim/korap/KrillQuery.java b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
index 72fc389..07a3c3b 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
@@ -399,39 +399,39 @@
// Branch on operation
switch (operation) {
- case "operation:junction":
- return this._operationJunctionFromJson(operands);
+ case "operation:junction":
+ return this._operationJunctionFromJson(operands);
- case "operation:position":
- return this._operationPositionFromJson(json, operands);
+ case "operation:position":
+ return this._operationPositionFromJson(json, operands);
- case "operation:sequence":
- return this._operationSequenceFromJson(json, operands);
+ case "operation:sequence":
+ return this._operationSequenceFromJson(json, operands);
- case "operation:class":
- return this._operationClassFromJson(json, operands);
+ case "operation:class":
+ return this._operationClassFromJson(json, operands);
- case "operation:repetition":
- return this._operationRepetitionFromJson(json, operands);
+ case "operation:repetition":
+ return this._operationRepetitionFromJson(json, operands);
- case "operation:relation":
- if (!json.has("relation")) {
- throw new QueryException(717, "Missing relation node");
- }
+ case "operation:relation":
+ if (!json.has("relation")) {
+ throw new QueryException(717, "Missing relation node");
+ }
- return _operationRelationFromJson(operands,
- json.get("relation"));
- /*throw new QueryException(765,
- "Relations are currently not supported");*/
+ return _operationRelationFromJson(operands,
+ json.get("relation"));
+ /*throw new QueryException(765,
+ "Relations are currently not supported");*/
- case "operation:or": // Deprecated in favor of operation:junction
- return this._operationJunctionFromJson(operands);
- /*
- case "operation:submatch": // Deprecated in favor of koral:reference
- return this._operationSubmatchFromJson(json, operands);
- */
- case "operation:disjunction":
- return this._operationJunctionFromJson(operands);
+ case "operation:or": // Deprecated in favor of operation:junction
+ return this._operationJunctionFromJson(operands);
+ /*
+ case "operation:submatch": // Deprecated in favor of koral:reference
+ return this._operationSubmatchFromJson(json, operands);
+ */
+ case "operation:disjunction":
+ return this._operationJunctionFromJson(operands);
};
// Unknown
diff --git a/src/main/java/de/ids_mannheim/korap/collection/BooleanFilter.java b/src/main/java/de/ids_mannheim/korap/collection/BooleanFilter.java
deleted file mode 100644
index 19693c6..0000000
--- a/src/main/java/de/ids_mannheim/korap/collection/BooleanFilter.java
+++ /dev/null
@@ -1,229 +0,0 @@
-package de.ids_mannheim.korap.collection;
-
-import java.util.*;
-
-import org.apache.lucene.index.Term;
-
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.RegexpQuery;
-import org.apache.lucene.search.NumericRangeQuery;
-
-import de.ids_mannheim.korap.util.KrillDate;
-import de.ids_mannheim.korap.KrillCollection;
-import de.ids_mannheim.korap.util.QueryException;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/*
- THIS IS LIMITED TO PUBDATE AT THE MOMENT AND COMPLETELY LEGACY!
-*/
-
-/**
- * @author Nils Diewald
- *
- * BooleanFilter implements a simple API for boolean
- * operations
- * on constraints for KorapFilter.
- */
-public class BooleanFilter {
- private String type;
-
- // Logger
- private final static Logger log = LoggerFactory
- .getLogger(KrillCollection.class);
-
- // This advices the java compiler to ignore all loggings
- public static final boolean DEBUG = false;
-
- private BooleanQuery bool;
- private String error;
-
-
- public BooleanFilter () {
- bool = new BooleanQuery();
- };
-
-
- public BooleanFilter or (String type, String ... terms) {
- for (String term : terms) {
-
- if (DEBUG)
- log.trace("Filter: OR {}={}", type, term);
-
- bool.add(new TermQuery(new Term(type, term)),
- BooleanClause.Occur.SHOULD);
- };
- return this;
- };
-
-
- public BooleanFilter or (String type, RegexFilter value) {
- bool.add(value.toQuery(type), BooleanClause.Occur.SHOULD);
- return this;
- };
-
-
- public BooleanFilter or (BooleanFilter bf) {
- if (bf.bool.clauses().size() == 1) {
- BooleanClause bc = bf.bool.getClauses()[0];
- bc.setOccur(BooleanClause.Occur.SHOULD);
- bool.add(bc);
- return this;
- }
- bool.add(bf.toQuery(), BooleanClause.Occur.SHOULD);
- return this;
- };
-
-
- public BooleanFilter or (NumericRangeQuery<Integer> nrq) {
- bool.add(nrq, BooleanClause.Occur.SHOULD);
- return this;
- };
-
-
- public BooleanFilter and (String type, String ... terms) {
- for (String term : terms) {
- bool.add(new TermQuery(new Term(type, term)),
- BooleanClause.Occur.MUST);
- };
- return this;
- };
-
-
- public BooleanFilter and (String type, RegexFilter value) {
- bool.add(value.toQuery(type), BooleanClause.Occur.MUST);
- return this;
- };
-
-
- public BooleanFilter and (BooleanFilter bf) {
- if (bf.bool.clauses().size() == 1) {
- BooleanClause bc = bf.bool.getClauses()[0];
- bc.setOccur(BooleanClause.Occur.MUST);
- bool.add(bc);
- return this;
- }
- bool.add(bf.toQuery(), BooleanClause.Occur.MUST);
- return this;
- };
-
-
- public BooleanFilter andNot (String type, String ... terms) {
- for (String term : terms) {
- bool.add(new TermQuery(new Term(type, term)),
- BooleanClause.Occur.MUST_NOT);
- };
- return this;
- };
-
-
- public BooleanFilter andNot (String type, RegexFilter value) {
- bool.add(value.toQuery(type), BooleanClause.Occur.MUST_NOT);
- return this;
- };
-
-
- public BooleanFilter andNot (BooleanFilter bf) {
- if (bf.bool.clauses().size() == 1) {
- BooleanClause bc = bf.bool.getClauses()[0];
- bc.setOccur(BooleanClause.Occur.MUST_NOT);
- bool.add(bc);
- return this;
- }
- bool.add(bf.toQuery(), BooleanClause.Occur.MUST_NOT);
- return this;
- };
-
-
- public BooleanFilter since (String dateStr) {
- int since = new KrillDate(dateStr).floor();
-
- if (since == 0 || since == KrillDate.BEGINNING)
- return this;
-
- bool.add(NumericRangeQuery.newIntRange("pubDate", since, KrillDate.END,
- true, true), BooleanClause.Occur.MUST);
-
- return this;
- };
-
-
- public BooleanFilter till (String dateStr) {
- try {
- int till = new KrillDate(dateStr).ceil();
- if (till == 0 || till == KrillDate.END)
- return this;
-
- bool.add(NumericRangeQuery.newIntRange("pubDate",
- KrillDate.BEGINNING, till, true, true),
- BooleanClause.Occur.MUST);
- }
- catch (NumberFormatException e) {
- log.warn("Parameter of till(date) is invalid");
- };
- return this;
- };
-
-
- public BooleanFilter between (String beginStr, String endStr) {
- KrillDate beginDF = new KrillDate(beginStr);
-
- int begin = beginDF.floor();
-
- int end = new KrillDate(endStr).ceil();
-
- if (end == 0)
- return this;
-
- if (begin == KrillDate.BEGINNING && end == KrillDate.END)
- return this;
-
- if (begin == end) {
- this.and("pubDate", beginDF.toString());
- return this;
- };
-
- this.bool.add(NumericRangeQuery.newIntRange("pubDate", begin, end,
- true, true), BooleanClause.Occur.MUST);
- return this;
- };
-
-
- public BooleanFilter date (String dateStr) {
- KrillDate dateDF = new KrillDate(dateStr);
-
- if (dateDF.year == 0)
- return this;
-
- if (dateDF.day == 0 || dateDF.month == 0) {
- int begin = dateDF.floor();
- int end = dateDF.ceil();
-
- if (end == 0
- || (begin == KrillDate.BEGINNING && end == KrillDate.END))
- return this;
-
- this.bool.add(NumericRangeQuery.newIntRange("pubDate", begin, end,
- true, true), BooleanClause.Occur.MUST);
- return this;
- };
-
- this.and("pubDate", dateDF.toString());
- return this;
- };
-
-
- public Query toQuery () {
- return this.bool;
- };
-
-
- public String toString () {
- return this.bool.toString();
- };
-};
diff --git a/src/main/java/de/ids_mannheim/korap/collection/BooleanGroupFilter.java b/src/main/java/de/ids_mannheim/korap/collection/BooleanGroupFilter.java
index 60c4ebb..53b0b66 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/BooleanGroupFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/BooleanGroupFilter.java
@@ -20,17 +20,19 @@
/**
* A container Filter that allows Boolean composition of Filters
* in groups (either or-groups or and-groups).
- *
+ *
* @author Nils Diewald
- *
- * This filter is roughly based on org.apache.lucene.queries.BooleanFilter.
+ *
+ * This filter is roughly based on
+ * org.apache.lucene.queries.BooleanFilter.
*/
public class BooleanGroupFilter extends Filter {
// Group is either an or- or an and-Group
private boolean isOptional;
// Logger
- private final static Logger log = LoggerFactory.getLogger(KrillCollection.class);
+ private final static Logger log = LoggerFactory
+ .getLogger(KrillCollection.class);
// This advices the java compiler to ignore all loggings
public static final boolean DEBUG = false;
@@ -43,6 +45,7 @@
public Filter filter;
public boolean isNegative;
+
// Operand has filter and negativity information
public GroupFilterOperand (Filter filter, boolean negative) {
this.filter = filter;
@@ -50,6 +53,7 @@
};
};
+
/**
* Create a new BooleanGroupFilter.
* Accepts a boolean parameter to make it an or-Group
@@ -82,7 +86,7 @@
public boolean equals (Object obj) {
if (this == obj)
return true;
-
+
if ((obj == null) || (obj.getClass() != this.getClass()))
return false;
@@ -92,16 +96,15 @@
@Override
- public int hashCode() {
+ public int hashCode () {
return 657153719 ^ operands.hashCode();
};
-
+
@Override
public String toString () {
- StringBuilder buffer = new StringBuilder(
- this.isOptional ? "OrGroup(" : "AndGroup("
- );
+ StringBuilder buffer = new StringBuilder(this.isOptional ? "OrGroup("
+ : "AndGroup(");
boolean first = true;
for (final GroupFilterOperand operand : this.operands) {
if (first)
@@ -117,12 +120,13 @@
return buffer.append(')').toString();
};
-
+
@Override
- public DocIdSet getDocIdSet (AtomicReaderContext context, Bits acceptDocs) throws IOException {
+ public DocIdSet getDocIdSet (AtomicReaderContext context, Bits acceptDocs)
+ throws IOException {
final AtomicReader reader = context.reader();
int maxDoc = reader.maxDoc();
- FixedBitSet bitset = new FixedBitSet(maxDoc);
+ FixedBitSet bitset = new FixedBitSet(maxDoc);
FixedBitSet combinator = new FixedBitSet(maxDoc);
boolean init = true;
@@ -131,17 +135,18 @@
for (final GroupFilterOperand operand : this.operands) {
final DocIdSet docids = operand.filter.getDocIdSet(context, null);
- final DocIdSetIterator filterIter = (docids == null) ? null : docids.iterator();
+ final DocIdSetIterator filterIter = (docids == null) ? null
+ : docids.iterator();
if (DEBUG)
log.debug("> Filter to bitset of {} ({} negative)",
- operand.filter.toString(),
- operand.isNegative);
+ operand.filter.toString(), operand.isNegative);
// Filter resulted in no docs
if (filterIter == null) {
- if (DEBUG) log.debug("- Filter is null");
+ if (DEBUG)
+ log.debug("- Filter is null");
// Filter matches
if (operand.isNegative) {
@@ -150,25 +155,29 @@
if (this.isOptional) {
// Everything is allowed
- if (DEBUG) log.debug("- Filter to allow all documents");
+ if (DEBUG)
+ log.debug("- Filter to allow all documents");
bitset.set(0, maxDoc);
return BitsFilteredDocIdSet.wrap(bitset, acceptDocs);
};
// There is no possible match
- if (DEBUG) log.debug("- Filter to allow no documents (1)");
+ if (DEBUG)
+ log.debug("- Filter to allow no documents (1)");
return null;
}
// The result is unimportant
else if (this.isOptional) {
- if (DEBUG) log.debug("- Filter is ignorable");
+ if (DEBUG)
+ log.debug("- Filter is ignorable");
continue;
};
// There is no possible match
- if (DEBUG) log.debug("- Filter to allow no documents (2)");
+ if (DEBUG)
+ log.debug("- Filter to allow no documents (2)");
return null;
}
@@ -177,30 +186,40 @@
bitset.or(filterIter);
- if (DEBUG) log.debug("- Filter is inial with card {}", bitset.cardinality());
+ if (DEBUG)
+ log.debug("- Filter is inial with card {}",
+ bitset.cardinality());
// Flip the matching documents
if (operand.isNegative) {
bitset.flip(0, maxDoc);
- if (DEBUG) log.debug("- Filter is negative - so flipped to card {} (1)", bitset.cardinality());
+ if (DEBUG)
+ log.debug(
+ "- Filter is negative - so flipped to card {} (1)",
+ bitset.cardinality());
};
init = false;
}
else {
- if (DEBUG) log.debug("- Filter is fine and operating");
+ if (DEBUG)
+ log.debug("- Filter is fine and operating");
// Operator is negative and needs to be flipped
if (operand.isNegative) {
if (this.isOptional) {
- if (DEBUG) log.debug("- Filter is negative optional");
+ if (DEBUG)
+ log.debug("- Filter is negative optional");
// Negative or ... may be slow
combinator.or(filterIter);
combinator.flip(0, maxDoc);
- if (DEBUG) log.debug("- Filter is negative - so flipped to card {} (2)", combinator.cardinality());
+ if (DEBUG)
+ log.debug(
+ "- Filter is negative - so flipped to card {} (2)",
+ combinator.cardinality());
bitset.or(combinator);
combinator.clear(0, maxDoc);
@@ -208,22 +227,27 @@
// Negative and
else {
- if (DEBUG) log.debug("- Filter is negative not optional");
+ if (DEBUG)
+ log.debug("- Filter is negative not optional");
bitset.andNot(filterIter);
- if (DEBUG) log.debug("- Filter is negative - so andNotted");
+ if (DEBUG)
+ log.debug("- Filter is negative - so andNotted");
}
}
else if (this.isOptional) {
- if (DEBUG) log.debug("- Filter is simply optional");
+ if (DEBUG)
+ log.debug("- Filter is simply optional");
bitset.or(filterIter);
}
else {
- if (DEBUG) log.debug("- Filter is simply not optional");
+ if (DEBUG)
+ log.debug("- Filter is simply not optional");
bitset.and(filterIter);
// TODO: Check with nextSetBit() if the filter is not applicable
};
- if (DEBUG) log.debug("- Subresult has card {} ", bitset.cardinality());
+ if (DEBUG)
+ log.debug("- Subresult has card {} ", bitset.cardinality());
};
};
return BitsFilteredDocIdSet.wrap(bitset, acceptDocs);
diff --git a/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java b/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
index 836aaa1..350d852 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
@@ -25,19 +25,23 @@
public class CollectionBuilder {
// Logger
- private final static Logger log = LoggerFactory.getLogger(KrillCollection.class);
+ private final static Logger log = LoggerFactory
+ .getLogger(KrillCollection.class);
// This advices the java compiler to ignore all loggings
public static final boolean DEBUG = false;
+
public CollectionBuilder.Interface term (String field, String term) {
return new CollectionBuilder.Term(field, term);
};
+
public CollectionBuilder.Interface re (String field, String term) {
return new CollectionBuilder.Term(field, term, true);
};
+
public CollectionBuilder.Interface since (String field, String date) {
int since = new KrillDate(date).floor();
@@ -47,6 +51,7 @@
return new CollectionBuilder.Range(field, since, KrillDate.END);
};
+
public CollectionBuilder.Interface till (String field, String date) {
try {
int till = new KrillDate(date).ceil();
@@ -61,8 +66,10 @@
return null;
};
+
// This will be optimized away in future versions
- public CollectionBuilder.Interface between (String field, String start, String end) {
+ public CollectionBuilder.Interface between (String field, String start,
+ String end) {
CollectionBuilder.Interface startObj = this.since(field, start);
if (startObj == null)
return null;
@@ -74,6 +81,7 @@
return this.andGroup().with(startObj).with(endObj);
};
+
public CollectionBuilder.Interface date (String field, String date) {
KrillDate dateDF = new KrillDate(date);
@@ -85,7 +93,7 @@
int end = dateDF.ceil();
if (end == 0
- || (begin == KrillDate.BEGINNING && end == KrillDate.END))
+ || (begin == KrillDate.BEGINNING && end == KrillDate.END))
return null;
return new CollectionBuilder.Range(field, begin, end);
@@ -94,18 +102,26 @@
return new CollectionBuilder.Range(field, dateDF.floor(), dateDF.ceil());
};
+
public CollectionBuilder.Group andGroup () {
return new CollectionBuilder.Group(false);
};
+
public CollectionBuilder.Group orGroup () {
return new CollectionBuilder.Group(true);
};
public interface Interface {
public String toString ();
+
+
public Filter toFilter ();
+
+
public boolean isNegative ();
+
+
public CollectionBuilder.Interface not ();
};
@@ -115,28 +131,33 @@
private String field;
private String term;
+
public Term (String field, String term) {
this.field = field;
this.term = term;
};
+
public Term (String field, String term, boolean regex) {
this.field = field;
this.term = term;
this.regex = regex;
};
+
public Filter toFilter () {
// Regular expression
if (this.regex)
return new QueryWrapperFilter(
- new RegexpQuery(new org.apache.lucene.index.Term(this.field, this.term))
- );
-
+ new RegexpQuery(new org.apache.lucene.index.Term(
+ this.field, this.term)));
+
// Simple term
- return new TermsFilter(new org.apache.lucene.index.Term(this.field, this.term));
+ return new TermsFilter(new org.apache.lucene.index.Term(this.field,
+ this.term));
};
+
public String toString () {
Filter filter = this.toFilter();
if (filter == null)
@@ -144,6 +165,7 @@
return filter.toString();
};
+
public boolean isNegative () {
return this.isNegative;
};
@@ -159,21 +181,25 @@
private boolean isOptional = false;
private boolean isNegative = true;
+
public boolean isNegative () {
return this.isNegative;
};
+
public boolean isOptional () {
return this.isOptional;
};
private ArrayList<CollectionBuilder.Interface> operands;
+
public Group (boolean optional) {
this.isOptional = optional;
this.operands = new ArrayList<CollectionBuilder.Interface>(3);
};
+
public Group with (CollectionBuilder.Interface cb) {
if (cb == null)
return this;
@@ -184,12 +210,14 @@
return this;
};
+
public Group with (String field, String term) {
if (field == null || term == null)
return this;
return this.with(new CollectionBuilder.Term(field, term));
};
+
public Filter toFilter () {
if (this.operands == null || this.operands.isEmpty())
return null;
@@ -214,6 +242,7 @@
return bool;
};
+
public String toString () {
Filter filter = this.toFilter();
if (filter == null)
@@ -221,6 +250,7 @@
return filter.toString();
};
+
public CollectionBuilder.Interface not () {
this.isNegative = true;
return this;
@@ -232,16 +262,19 @@
private String field;
private int start, end;
+
public Range (String field, int start, int end) {
this.field = field;
this.start = start;
this.end = end;
};
+
public boolean isNegative () {
return this.isNegative;
};
+
public String toString () {
Filter filter = this.toFilter();
if (filter == null)
@@ -249,14 +282,13 @@
return filter.toString();
};
+
public Filter toFilter () {
- return NumericRangeFilter.newIntRange(this.field,
- this.start,
- this.end,
- true,
- true);
+ return NumericRangeFilter.newIntRange(this.field, this.start,
+ this.end, true, true);
};
+
public CollectionBuilder.Interface not () {
this.isNegative = true;
return this;
diff --git a/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilderLegacy.java b/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilderLegacy.java
deleted file mode 100644
index 37fa50f..0000000
--- a/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilderLegacy.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package de.ids_mannheim.korap.collection;
-
-import de.ids_mannheim.korap.collection.BooleanFilter;
-import de.ids_mannheim.korap.collection.RegexFilter;
-import de.ids_mannheim.korap.util.QueryException;
-import de.ids_mannheim.korap.util.KrillDate;
-
-import org.apache.lucene.search.Query;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.JsonNode;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * CollectionBuilderLegacy implements a simple API for creating queries
- * constituing Virtual Collections.
- *
- * <strong>Warning</strong>: The API is likely to change.
- *
- * @author diewald
- */
-/*
- * Todo: WildCardFilter!
- * Todo: Support delete boolean etc.
- * Todo: Supports foundries
- */
-public class CollectionBuilderLegacy {
- private BooleanFilter filter;
- private String field = "tokens";
-
- // Logger
- private final static Logger log = LoggerFactory
- .getLogger(CollectionBuilder.class);
-
- // This advices the java compiler to ignore all loggings
- public static final boolean DEBUG = false;
-
-
- /**
- * Construct a new CollectionBuilderLegacy object.
- */
- public CollectionBuilderLegacy () {
- filter = new BooleanFilter();
- };
-
-
- public BooleanFilter and (String type, String ... terms) {
- BooleanFilter bf = new BooleanFilter();
- bf.and(type, terms);
- return bf;
- };
-
-
- public BooleanFilter or (String type, String ... terms) {
- BooleanFilter bf = new BooleanFilter();
- bf.or(type, terms);
- return bf;
- };
-
-
- public BooleanFilter and (String type, RegexFilter re) {
- BooleanFilter bf = new BooleanFilter();
- bf.and(type, re);
- return bf;
- };
-
-
- public BooleanFilter or (String type, RegexFilter re) {
- BooleanFilter bf = new BooleanFilter();
- bf.or(type, re);
- return bf;
- };
-
-
- public BooleanFilter since (String date) {
- BooleanFilter bf = new BooleanFilter();
- bf.since(date);
- return bf;
- };
-
-
- public BooleanFilter till (String date) {
- BooleanFilter bf = new BooleanFilter();
- bf.till(date);
- return bf;
- };
-
-
- public BooleanFilter date (String date) {
- BooleanFilter bf = new BooleanFilter();
- bf.date(date);
- return bf;
- };
-
-
- public BooleanFilter between (String date1, String date2) {
- BooleanFilter bf = new BooleanFilter();
- bf.between(date1, date2);
- return bf;
- };
-
-
- public RegexFilter re (String regex) {
- return new RegexFilter(regex);
- };
-
-
- public BooleanFilter getBooleanFilter () {
- return this.filter;
- };
-
-
- public void setBooleanFilter (BooleanFilter bf) {
- this.filter = bf;
- };
-
-
- public Query toQuery () {
- return this.filter.toQuery();
- };
-
-
- public String toString () {
- return this.filter.toQuery().toString();
- };
-};
diff --git a/src/main/java/de/ids_mannheim/korap/collection/FilterOperation.java b/src/main/java/de/ids_mannheim/korap/collection/FilterOperation.java
deleted file mode 100644
index 5d3be07..0000000
--- a/src/main/java/de/ids_mannheim/korap/collection/FilterOperation.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package de.ids_mannheim.korap.collection;
-
-import org.apache.lucene.search.Filter;
-
-public class FilterOperation {
- private boolean extension;
- public Filter filter;
-
-
- public FilterOperation (Filter filter, boolean extension) {
- this.extension = extension;
- this.filter = filter;
- };
-
-
- public boolean isExtension () {
- return this.extension;
- };
-
-
- public boolean isFilter () {
- return !(this.extension);
- };
-
-
- @Override
- public Object clone () throws CloneNotSupportedException {
- return (Object) new FilterOperation(this.filter, this.extension);
- };
-
-
- @Override
- public String toString () {
- StringBuilder sb = new StringBuilder();
- if (this.extension) {
- sb.append("extend with ");
- }
- else {
- sb.append("filter with ");
- };
- sb.append(this.filter.toString());
- return sb.toString();
- };
-};
diff --git a/src/main/java/de/ids_mannheim/korap/collection/RegexFilter.java b/src/main/java/de/ids_mannheim/korap/collection/RegexFilter.java
deleted file mode 100644
index c948dab..0000000
--- a/src/main/java/de/ids_mannheim/korap/collection/RegexFilter.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package de.ids_mannheim.korap.collection;
-
-import java.util.*;
-
-import org.apache.lucene.search.RegexpQuery;
-import org.apache.lucene.index.Term;
-
-/**
- * @author Nils Diewald
- *
- * RegexFilter implements a helper object for
- * regular expressions used in KrillCollection
- * constraints.
- */
-
-public class RegexFilter {
- String regex;
-
-
- public RegexFilter (String regex) {
- this.regex = regex;
- };
-
-
- public RegexpQuery toQuery (String field) {
- return new RegexpQuery(new Term(field, this.regex));
- };
-};
diff --git a/src/main/java/de/ids_mannheim/korap/index/KeywordAnalyzer.java b/src/main/java/de/ids_mannheim/korap/index/KeywordAnalyzer.java
index e20af6f..0725778 100644
--- a/src/main/java/de/ids_mannheim/korap/index/KeywordAnalyzer.java
+++ b/src/main/java/de/ids_mannheim/korap/index/KeywordAnalyzer.java
@@ -10,10 +10,11 @@
public class KeywordAnalyzer extends Analyzer {
- @Override
- protected TokenStreamComponents createComponents(final String fieldName, final Reader reader) {
- final Tokenizer source = new WhitespaceTokenizer(reader);
- TokenStream sink = new LowerCaseFilter(source);
- return new TokenStreamComponents(source, sink);
- };
+ @Override
+ protected TokenStreamComponents createComponents (final String fieldName,
+ final Reader reader) {
+ final Tokenizer source = new WhitespaceTokenizer(reader);
+ TokenStream sink = new LowerCaseFilter(source);
+ return new TokenStreamComponents(source, sink);
+ };
};
diff --git a/src/main/java/de/ids_mannheim/korap/index/TextAnalyzer.java b/src/main/java/de/ids_mannheim/korap/index/TextAnalyzer.java
index bca39b5..771c6c1 100644
--- a/src/main/java/de/ids_mannheim/korap/index/TextAnalyzer.java
+++ b/src/main/java/de/ids_mannheim/korap/index/TextAnalyzer.java
@@ -10,10 +10,11 @@
public class TextAnalyzer extends Analyzer {
- @Override
- protected TokenStreamComponents createComponents (final String fieldName, final Reader reader) {
- final Tokenizer source = new StandardTokenizer(reader);
- TokenStream sink = new LowerCaseFilter(source);
- return new TokenStreamComponents(source, sink);
- };
+ @Override
+ protected TokenStreamComponents createComponents (final String fieldName,
+ final Reader reader) {
+ final Tokenizer source = new StandardTokenizer(reader);
+ TokenStream sink = new LowerCaseFilter(source);
+ return new TokenStreamComponents(source, sink);
+ };
};
diff --git a/src/main/java/de/ids_mannheim/korap/response/Match.java b/src/main/java/de/ids_mannheim/korap/response/Match.java
index b324ffc..617f07a 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Match.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Match.java
@@ -374,7 +374,7 @@
this.addHighlight(new Highlight(target, target, id));
};
-
+
/**
* Populate document meta information with information coming from
* the index.
diff --git a/src/main/java/de/ids_mannheim/korap/response/match/DocIdentifier.java b/src/main/java/de/ids_mannheim/korap/response/match/DocIdentifier.java
index b384222..53280c7 100644
--- a/src/main/java/de/ids_mannheim/korap/response/match/DocIdentifier.java
+++ b/src/main/java/de/ids_mannheim/korap/response/match/DocIdentifier.java
@@ -8,8 +8,8 @@
public class DocIdentifier {
protected String textSigle, // fine
- corpusID, // LEGACY
- docID; // LEGACY
+ corpusID, // LEGACY
+ docID; // LEGACY
// Legacy
diff --git a/src/main/java/de/ids_mannheim/korap/response/match/MatchIdentifier.java b/src/main/java/de/ids_mannheim/korap/response/match/MatchIdentifier.java
index f9fdfbe..7ebf161 100644
--- a/src/main/java/de/ids_mannheim/korap/response/match/MatchIdentifier.java
+++ b/src/main/java/de/ids_mannheim/korap/response/match/MatchIdentifier.java
@@ -9,11 +9,9 @@
private ArrayList<int[]> pos = new ArrayList<>(8);
// TODO: "contains" is necessary for a compatibility bug in Kustvakt
- Pattern idRegex = Pattern
- .compile("^(?:match-|contains-)"
- + "(?:([^!]+?)[!\\.])?"
- + "([^!]+)-p([0-9]+)-([0-9]+)"
- + "((?:\\(-?[0-9]+\\)-?[0-9]+--?[0-9]+)*)" + "(?:c.+?)?$");
+ Pattern idRegex = Pattern.compile("^(?:match-|contains-)"
+ + "(?:([^!]+?)[!\\.])?" + "([^!]+)-p([0-9]+)-([0-9]+)"
+ + "((?:\\(-?[0-9]+\\)-?[0-9]+--?[0-9]+)*)" + "(?:c.+?)?$");
Pattern posRegex = Pattern.compile("\\(([0-9]+)\\)([0-9]+)-([0-9]+)");
diff --git a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
index 4f7ba16..922792e 100644
--- a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
+++ b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
@@ -11,7 +11,6 @@
import de.ids_mannheim.korap.KrillQuery;
import de.ids_mannheim.korap.query.QueryBuilder;
import org.apache.lucene.store.MMapDirectory;
-import de.ids_mannheim.korap.collection.BooleanFilter;
import org.apache.lucene.search.spans.SpanQuery;
import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
import de.ids_mannheim.korap.util.QueryException;
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestCollectionBuilder.java b/src/test/java/de/ids_mannheim/korap/collection/TestCollectionBuilder.java
index 9dd7baf..27a3dd7 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestCollectionBuilder.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestCollectionBuilder.java
@@ -20,38 +20,42 @@
@Test
public void builderTerm () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
- assertEquals("author:tree",
- kc.term("author", "tree").toString());
+ assertEquals("author:tree", kc.term("author", "tree").toString());
};
+
@Test
public void builderRegex () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
assertEquals("QueryWrapperFilter(author:/tre*?/)",
- kc.re("author", "tre*?").toString());
+ kc.re("author", "tre*?").toString());
};
+
@Test
public void builderDateYear () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
assertEquals("pubDate:[20050000 TO 20059999]",
- kc.date("pubDate", "2005").toString());
+ kc.date("pubDate", "2005").toString());
};
+
@Test
public void builderDateMonth () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
assertEquals("pubDate:[20051000 TO 20051099]",
- kc.date("pubDate", "2005-10").toString());
+ kc.date("pubDate", "2005-10").toString());
};
+
@Test
public void builderDateDay () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
assertEquals("pubDate:[20051011 TO 20051011]",
- kc.date("pubDate", "2005-10-11").toString());
+ kc.date("pubDate", "2005-10-11").toString());
};
+
@Test
public void builderDateBorders () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
@@ -59,109 +63,127 @@
assertNull(kc.date("pubDate", ""));
assertEquals("pubDate:[20051580 TO 20051580]",
- kc.date("pubDate", "2005-15-80").toString());
+ kc.date("pubDate", "2005-15-80").toString());
assertNull(kc.date("pubDate", "2005-15-8"));
assertNull(kc.date("pubDate", "2005-5-18"));
assertNull(kc.date("pubDate", "200-05-18"));
};
+
@Test
public void builderSince () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
assertEquals("pubDate:[20050000 TO 99999999]",
- kc.since("pubDate", "2005").toString());
+ kc.since("pubDate", "2005").toString());
assertEquals("pubDate:[20051000 TO 99999999]",
- kc.since("pubDate", "2005-10").toString());
+ kc.since("pubDate", "2005-10").toString());
assertEquals("pubDate:[20051012 TO 99999999]",
- kc.since("pubDate", "2005-10-12").toString());
+ kc.since("pubDate", "2005-10-12").toString());
};
@Test
public void builderTill () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
- assertEquals("pubDate:[0 TO 20059999]",
- kc.till("pubDate", "2005").toString());
+ assertEquals("pubDate:[0 TO 20059999]", kc.till("pubDate", "2005")
+ .toString());
- assertEquals("pubDate:[0 TO 20051299]",
- kc.till("pubDate", "2005-12").toString());
+ assertEquals("pubDate:[0 TO 20051299]", kc.till("pubDate", "2005-12")
+ .toString());
- assertEquals("pubDate:[0 TO 20051204]",
- kc.till("pubDate", "2005-12-04").toString());
+ assertEquals("pubDate:[0 TO 20051204]", kc
+ .till("pubDate", "2005-12-04").toString());
};
@Test
public void builderAndSimple () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
- assertEquals("author:tree", kc.andGroup().with(kc.term("author", "tree")).toString());
+ assertEquals("author:tree",
+ kc.andGroup().with(kc.term("author", "tree")).toString());
};
+
@Test
public void builderOrSimple () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
- assertEquals("author:tree", kc.orGroup().with(kc.term("author", "tree")).toString());
+ assertEquals("author:tree", kc.orGroup()
+ .with(kc.term("author", "tree")).toString());
};
+
@Test
public void builderAndCombined () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
- assertEquals("AndGroup(author:tree title:name)",
- kc.andGroup().with(kc.term("author", "tree"))
- .with(kc.term("title", "name")).toString());
+ assertEquals(
+ "AndGroup(author:tree title:name)",
+ kc.andGroup().with(kc.term("author", "tree"))
+ .with(kc.term("title", "name")).toString());
};
+
@Test
public void builderAndNestedSimple () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
- assertEquals("AndGroup(author:tree title:name)",
- kc.andGroup().with(kc.andGroup().with(kc.term("author", "tree")).with(kc.term("title", "name"))).toString());
+ assertEquals(
+ "AndGroup(author:tree title:name)",
+ kc.andGroup()
+ .with(kc.andGroup().with(kc.term("author", "tree"))
+ .with(kc.term("title", "name"))).toString());
};
@Test
public void builderOrCombined () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
- assertEquals("OrGroup(author:tree title:name)",
- kc.orGroup().with(kc.term("author", "tree"))
- .with(kc.term("title", "name")).toString());
+ assertEquals(
+ "OrGroup(author:tree title:name)",
+ kc.orGroup().with(kc.term("author", "tree"))
+ .with(kc.term("title", "name")).toString());
};
+
@Test
public void builderOrNestedSimple () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
- assertEquals("OrGroup(author:tree title:name)",
- kc.orGroup().with(kc.orGroup().with(kc.term("author", "tree"))
- .with(kc.term("title", "name"))).toString()
- );
+ assertEquals(
+ "OrGroup(author:tree title:name)",
+ kc.orGroup()
+ .with(kc.orGroup().with(kc.term("author", "tree"))
+ .with(kc.term("title", "name"))).toString());
};
+
@Test
public void builderGroups () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
- String g = kc.orGroup().with(
- kc.orGroup().with(kc.term("author", "tree1")).with(kc.term("title", "name1"))
- ).with(
- kc.andGroup().with(kc.term("author", "tree2")).with(kc.term("title", "name2"))
- ).toString();
- assertEquals("OrGroup(OrGroup(author:tree1 title:name1) AndGroup(author:tree2 title:name2))", g);
+ String g = kc
+ .orGroup()
+ .with(kc.orGroup().with(kc.term("author", "tree1"))
+ .with(kc.term("title", "name1")))
+ .with(kc.andGroup().with(kc.term("author", "tree2"))
+ .with(kc.term("title", "name2"))).toString();
+ assertEquals(
+ "OrGroup(OrGroup(author:tree1 title:name1) AndGroup(author:tree2 title:name2))",
+ g);
};
+
@Test
public void builderNegationRoot () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
- CollectionBuilder.Interface kbi = kc.orGroup().with(kc.term("author", "tree1")).with(kc.term("title", "name1"));
- assertEquals(
- "OrGroup(author:tree1 title:name1)",
- kbi.toString());
+ CollectionBuilder.Interface kbi = kc.orGroup()
+ .with(kc.term("author", "tree1"))
+ .with(kc.term("title", "name1"));
+ assertEquals("OrGroup(author:tree1 title:name1)", kbi.toString());
assertFalse(kbi.isNegative());
- kbi = kc.andGroup().with(
- kc.orGroup().with(kc.term("author", "tree1")).with(kc.term("title", "name1"))
- ).not();
+ kbi = kc.andGroup()
+ .with(kc.orGroup().with(kc.term("author", "tree1"))
+ .with(kc.term("title", "name1"))).not();
assertEquals("OrGroup(author:tree1 title:name1)", kbi.toString());
assertTrue(kbi.isNegative());
};
@@ -170,8 +192,7 @@
@Test
public void builderNegation () throws IOException {
CollectionBuilder kc = new CollectionBuilder();
- CollectionBuilder.Interface kbi =
- kc.term("author", "tree").not();
+ CollectionBuilder.Interface kbi = kc.term("author", "tree").not();
assertEquals("author:tree", kbi.toString());
assertTrue(kbi.isNegative());
@@ -184,6 +205,7 @@
assertTrue(kbi.isNegative());
};
+
// The legacy tests were adopted from the legacy collection builder and reformuated
@Test
@@ -193,14 +215,18 @@
/*
assertEquals("+textClass:tree", kf.and("textClass", "tree").toString());
*/
- assertEquals("textClass:tree", kf.andGroup().with(kf.term("textClass", "tree")).toString());
+ assertEquals("textClass:tree",
+ kf.andGroup().with(kf.term("textClass", "tree")).toString());
/*
assertEquals("+textClass:tree +textClass:sport",
kf.and("textClass", "tree").and("textClass", "sport")
.toString());
*/
- assertEquals("AndGroup(textClass:tree textClass:sport)", kf.andGroup().with(kf.term("textClass", "tree")).with(kf.term("textClass", "sport")).toString());
+ assertEquals(
+ "AndGroup(textClass:tree textClass:sport)",
+ kf.andGroup().with(kf.term("textClass", "tree"))
+ .with(kf.term("textClass", "sport")).toString());
/*
assertEquals(
@@ -208,22 +234,34 @@
kf.and("textClass", "tree").and("textClass", "sport")
.or("textClass", "news").toString());
*/
- assertEquals("OrGroup(AndGroup(textClass:tree textClass:sport) textClass:news)", kf.orGroup().with(kf.andGroup().with("textClass", "tree").with("textClass", "sport")).with("textClass", "news").toString());
+ assertEquals(
+ "OrGroup(AndGroup(textClass:tree textClass:sport) textClass:news)",
+ kf.orGroup()
+ .with(kf.andGroup().with("textClass", "tree")
+ .with("textClass", "sport"))
+ .with("textClass", "news").toString());
/*
assertEquals("+textClass:tree +textClass:sport +textClass:news", kf
.and("textClass", "tree", "sport", "news").toString());
*/
- assertEquals("AndGroup(textClass:tree textClass:sport textClass:news)", kf.andGroup().with("textClass", "tree").with("textClass", "sport").with("textClass", "news").toString());
+ assertEquals(
+ "AndGroup(textClass:tree textClass:sport textClass:news)",
+ kf.andGroup().with("textClass", "tree")
+ .with("textClass", "sport").with("textClass", "news")
+ .toString());
/*
assertEquals("corpusID:c-1 corpusID:c-2 corpusID:c-3",
kf.or("corpusID", "c-1", "c-2", "c-3").toString());
*/
- assertEquals("OrGroup(corpusID:c-1 corpusID:c-2 corpusID:c-3)", kf.orGroup().with("corpusID", "c-1").with("corpusID", "c-2").with("corpusID", "c-3").toString());
+ assertEquals("OrGroup(corpusID:c-1 corpusID:c-2 corpusID:c-3)", kf
+ .orGroup().with("corpusID", "c-1").with("corpusID", "c-2")
+ .with("corpusID", "c-3").toString());
};
+
@Test
public void LegacyRangeExample () throws IOException {
CollectionBuilder kf = new CollectionBuilder();
@@ -232,27 +270,31 @@
kf.between("2003-06-04", "2003-08-99").toString());
*/
// This will be optimized and probably crash
- assertEquals("AndGroup(pubDate:[20030604 TO 99999999] pubDate:[0 TO 20030899])", kf.andGroup().with(kf.since("pubDate", "2003-06-04")).with(kf.till("pubDate", "2003-08-99")).toString());
+ assertEquals(
+ "AndGroup(pubDate:[20030604 TO 99999999] pubDate:[0 TO 20030899])",
+ kf.andGroup().with(kf.since("pubDate", "2003-06-04"))
+ .with(kf.till("pubDate", "2003-08-99")).toString());
/*
assertEquals("+pubDate:[0 TO 20030604]", kf.till("2003-06-04")
.toString());
*/
- assertEquals("pubDate:[0 TO 20030604]", kf.till("pubDate", "2003-06-04")
- .toString());
+ assertEquals("pubDate:[0 TO 20030604]", kf
+ .till("pubDate", "2003-06-04").toString());
/*
assertEquals("+pubDate:[20030604 TO 99999999]", kf.since("2003-06-04")
.toString());
*/
- assertEquals("pubDate:[20030604 TO 99999999]", kf.since("pubDate", "2003-06-04")
- .toString());
+ assertEquals("pubDate:[20030604 TO 99999999]",
+ kf.since("pubDate", "2003-06-04").toString());
/*
assertEquals("+pubDate:20030604", kf.date("2003-06-04").toString());
*/
- assertEquals("pubDate:[20030604 TO 20030604]", kf.date("pubDate", "2003-06-04").toString());
+ assertEquals("pubDate:[20030604 TO 20030604]",
+ kf.date("pubDate", "2003-06-04").toString());
};
@@ -263,57 +305,66 @@
assertEquals("+pubDate:[20050000 TO 20099999]",
kf.between("2005", "2009").toString());
*/
- assertEquals("AndGroup(pubDate:[20050000 TO 99999999] pubDate:[0 TO 20099999])",
- kf.between("pubDate", "2005", "2009").toString());
+ assertEquals(
+ "AndGroup(pubDate:[20050000 TO 99999999] pubDate:[0 TO 20099999])",
+ kf.between("pubDate", "2005", "2009").toString());
/*
assertEquals("+pubDate:[20051000 TO 20090899]",
kf.between("200510", "200908").toString());
*/
- assertEquals("AndGroup(pubDate:[20051000 TO 99999999] pubDate:[0 TO 20090899])",
- kf.between("pubDate", "200510", "200908").toString());
+ assertEquals(
+ "AndGroup(pubDate:[20051000 TO 99999999] pubDate:[0 TO 20090899])",
+ kf.between("pubDate", "200510", "200908").toString());
/*
assertEquals("+pubDate:[20051000 TO 20090899]",
kf.between("2005-10", "2009-08").toString());
*/
- assertEquals("AndGroup(pubDate:[20051000 TO 99999999] pubDate:[0 TO 20090899])",
- kf.between("pubDate", "2005-10", "2009-08").toString());
+ assertEquals(
+ "AndGroup(pubDate:[20051000 TO 99999999] pubDate:[0 TO 20090899])",
+ kf.between("pubDate", "2005-10", "2009-08").toString());
/*
assertEquals("+pubDate:[20051006 TO 20090803]",
kf.between("2005-1006", "2009-0803").toString());
*/
- assertEquals("AndGroup(pubDate:[20051006 TO 99999999] pubDate:[0 TO 20090803])",
- kf.between("pubDate", "2005-1006", "2009-0803").toString());
+ assertEquals(
+ "AndGroup(pubDate:[20051006 TO 99999999] pubDate:[0 TO 20090803])",
+ kf.between("pubDate", "2005-1006", "2009-0803").toString());
/*
assertEquals("+pubDate:[20051006 TO 20090803]",
kf.between("2005-10-06", "2009-08-03").toString());
*/
- assertEquals("AndGroup(pubDate:[20051006 TO 99999999] pubDate:[0 TO 20090803])",
- kf.between("pubDate", "2005-10-06", "2009-08-03").toString());
+ assertEquals(
+ "AndGroup(pubDate:[20051006 TO 99999999] pubDate:[0 TO 20090803])",
+ kf.between("pubDate", "2005-10-06", "2009-08-03").toString());
/*
assertEquals("+pubDate:[0 TO 20059999]", kf.till("2005").toString());
*/
- assertEquals("pubDate:[0 TO 20059999]", kf.till("pubDate", "2005").toString());
+ assertEquals("pubDate:[0 TO 20059999]", kf.till("pubDate", "2005")
+ .toString());
/*
assertEquals("+pubDate:[0 TO 20051099]", kf.till("200510").toString());
*/
- assertEquals("pubDate:[0 TO 20051099]", kf.till("pubDate", "200510").toString());
+ assertEquals("pubDate:[0 TO 20051099]", kf.till("pubDate", "200510")
+ .toString());
/*
assertEquals("+pubDate:[0 TO 20051099]", kf.till("200510").toString());
*/
- assertEquals("pubDate:[0 TO 20051099]", kf.till("pubDate", "200510").toString());
+ assertEquals("pubDate:[0 TO 20051099]", kf.till("pubDate", "200510")
+ .toString());
/*
assertEquals("+pubDate:[0 TO 20051099]", kf.till("2005-10").toString());
*/
- assertEquals("pubDate:[0 TO 20051099]", kf.till("pubDate", "2005-10").toString());
+ assertEquals("pubDate:[0 TO 20051099]", kf.till("pubDate", "2005-10")
+ .toString());
/*
assertEquals("+pubDate:[0 TO 20051006]", kf.till("2005-1006")
@@ -326,76 +377,78 @@
assertEquals("+pubDate:[0 TO 20051006]", kf.till("2005-10-06")
.toString());
*/
- assertEquals("pubDate:[0 TO 20051006]", kf.till("pubDate", "2005-10-06")
- .toString());
+ assertEquals("pubDate:[0 TO 20051006]", kf
+ .till("pubDate", "2005-10-06").toString());
/*
assertEquals("+pubDate:[20050000 TO 99999999]", kf.since("2005")
.toString());
*/
- assertEquals("pubDate:[20050000 TO 99999999]", kf.since("pubDate", "2005")
- .toString());
+ assertEquals("pubDate:[20050000 TO 99999999]",
+ kf.since("pubDate", "2005").toString());
/*
assertEquals("+pubDate:[20051000 TO 99999999]", kf.since("200510")
.toString());
*/
- assertEquals("pubDate:[20051000 TO 99999999]", kf.since("pubDate", "200510")
- .toString());
+ assertEquals("pubDate:[20051000 TO 99999999]",
+ kf.since("pubDate", "200510").toString());
/*
assertEquals("+pubDate:[20051000 TO 99999999]", kf.since("2005-10")
.toString());
*/
- assertEquals("pubDate:[20051000 TO 99999999]", kf.since("pubDate", "2005-10")
- .toString());
+ assertEquals("pubDate:[20051000 TO 99999999]",
+ kf.since("pubDate", "2005-10").toString());
/*
assertEquals("+pubDate:[20051006 TO 99999999]", kf.since("2005-1006")
.toString());
*/
- assertEquals("pubDate:[20051006 TO 99999999]", kf.since("pubDate", "2005-1006")
- .toString());
+ assertEquals("pubDate:[20051006 TO 99999999]",
+ kf.since("pubDate", "2005-1006").toString());
/*
assertEquals("+pubDate:[20051006 TO 99999999]", kf.since("2005-10-06")
.toString());
*/
- assertEquals("pubDate:[20051006 TO 99999999]", kf.since("pubDate", "2005-10-06")
- .toString());
+ assertEquals("pubDate:[20051006 TO 99999999]",
+ kf.since("pubDate", "2005-10-06").toString());
/*
assertEquals("+pubDate:[20050000 TO 20059999]", kf.date("2005")
.toString());
*/
- assertEquals("pubDate:[20050000 TO 20059999]", kf.date("pubDate", "2005")
- .toString());
+ assertEquals("pubDate:[20050000 TO 20059999]",
+ kf.date("pubDate", "2005").toString());
/*
assertEquals("+pubDate:[20051000 TO 20051099]", kf.date("200510")
.toString());
*/
- assertEquals("pubDate:[20051000 TO 20051099]", kf.date("pubDate", "200510")
- .toString());
+ assertEquals("pubDate:[20051000 TO 20051099]",
+ kf.date("pubDate", "200510").toString());
/*
assertEquals("+pubDate:[20051000 TO 20051099]", kf.date("2005-10")
.toString());
*/
- assertEquals("pubDate:[20051000 TO 20051099]", kf.date("pubDate", "2005-10")
- .toString());
+ assertEquals("pubDate:[20051000 TO 20051099]",
+ kf.date("pubDate", "2005-10").toString());
/*
assertEquals("+pubDate:20051006", kf.date("2005-1006").toString());
*/
- assertEquals("pubDate:[20051006 TO 20051006]", kf.date("pubDate", "2005-1006").toString());
+ assertEquals("pubDate:[20051006 TO 20051006]",
+ kf.date("pubDate", "2005-1006").toString());
/*
assertEquals("+pubDate:20051006", kf.date("2005-10-06").toString());
*/
- assertEquals("pubDate:[20051006 TO 20051006]", kf.date("pubDate", "2005-10-06").toString());
+ assertEquals("pubDate:[20051006 TO 20051006]",
+ kf.date("pubDate", "2005-10-06").toString());
};
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestCollectionBuilderLegacy.java b/src/test/java/de/ids_mannheim/korap/collection/TestCollectionBuilderLegacy.java
deleted file mode 100644
index a52a575..0000000
--- a/src/test/java/de/ids_mannheim/korap/collection/TestCollectionBuilderLegacy.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package de.ids_mannheim.korap.collection;
-
-import java.util.*;
-import java.io.*;
-
-import org.apache.lucene.util.Version;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.Bits;
-
-import static org.junit.Assert.*;
-import org.junit.Test;
-import org.junit.Ignore;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import de.ids_mannheim.korap.collection.CollectionBuilderLegacy;
-
-@RunWith(JUnit4.class)
-public class TestCollectionBuilderLegacy {
-
- @Test
- @Ignore
- public void filterExample () throws IOException {
- CollectionBuilderLegacy kf = new CollectionBuilderLegacy();
-
- assertEquals("+textClass:tree", kf.and("textClass", "tree").toString());
- assertEquals("+textClass:tree +textClass:sport",
- kf.and("textClass", "tree").and("textClass", "sport")
- .toString());
- assertEquals(
- "+textClass:tree +textClass:sport textClass:news",
- kf.and("textClass", "tree").and("textClass", "sport")
- .or("textClass", "news").toString());
- assertEquals("+textClass:tree +textClass:sport +textClass:news", kf
- .and("textClass", "tree", "sport", "news").toString());
-
- assertEquals("corpusID:c-1 corpusID:c-2 corpusID:c-3",
- kf.or("corpusID", "c-1", "c-2", "c-3").toString());
- };
-
-
- @Test
- @Ignore
- public void rangeExample () throws IOException {
- CollectionBuilderLegacy kf = new CollectionBuilderLegacy();
- assertEquals("+pubDate:[20030604 TO 20030899]",
- kf.between("2003-06-04", "2003-08-99").toString());
- assertEquals("+pubDate:[0 TO 20030604]", kf.till("2003-06-04")
- .toString());
- assertEquals("+pubDate:[20030604 TO 99999999]", kf.since("2003-06-04")
- .toString());
- assertEquals("+pubDate:20030604", kf.date("2003-06-04").toString());
- };
-
-
- @Test
- @Ignore
- public void rangeLimited () throws IOException {
- CollectionBuilderLegacy kf = new CollectionBuilderLegacy();
- assertEquals("+pubDate:[20050000 TO 20099999]",
- kf.between("2005", "2009").toString());
- assertEquals("+pubDate:[20051000 TO 20090899]",
- kf.between("200510", "200908").toString());
- assertEquals("+pubDate:[20051000 TO 20090899]",
- kf.between("2005-10", "2009-08").toString());
- assertEquals("+pubDate:[20051006 TO 20090803]",
- kf.between("2005-1006", "2009-0803").toString());
- assertEquals("+pubDate:[20051006 TO 20090803]",
- kf.between("2005-10-06", "2009-08-03").toString());
-
- assertEquals("+pubDate:[0 TO 20059999]", kf.till("2005").toString());
- assertEquals("+pubDate:[0 TO 20051099]", kf.till("200510").toString());
- assertEquals("+pubDate:[0 TO 20051099]", kf.till("2005-10").toString());
- assertEquals("+pubDate:[0 TO 20051006]", kf.till("2005-1006")
- .toString());
- assertEquals("+pubDate:[0 TO 20051006]", kf.till("2005-10-06")
- .toString());
-
- assertEquals("+pubDate:[20050000 TO 99999999]", kf.since("2005")
- .toString());
- assertEquals("+pubDate:[20051000 TO 99999999]", kf.since("200510")
- .toString());
- assertEquals("+pubDate:[20051000 TO 99999999]", kf.since("2005-10")
- .toString());
- assertEquals("+pubDate:[20051006 TO 99999999]", kf.since("2005-1006")
- .toString());
- assertEquals("+pubDate:[20051006 TO 99999999]", kf.since("2005-10-06")
- .toString());
-
- assertEquals("+pubDate:[20050000 TO 20059999]", kf.date("2005")
- .toString());
- assertEquals("+pubDate:[20051000 TO 20051099]", kf.date("200510")
- .toString());
- assertEquals("+pubDate:[20051000 TO 20051099]", kf.date("2005-10")
- .toString());
- assertEquals("+pubDate:20051006", kf.date("2005-1006").toString());
- assertEquals("+pubDate:20051006", kf.date("2005-10-06").toString());
- };
-
-
- @Test
- @Ignore
- public void rangeFailure () throws IOException {
- CollectionBuilderLegacy kf = new CollectionBuilderLegacy();
- assertEquals("", kf.between("aaaa-bb-cc", "aaaabbcc").toString());
- assertEquals("", kf.till("aaaa-bb-cc").toString());
- assertEquals("", kf.since("aaaa-bb-cc").toString());
- assertEquals("", kf.date("aaaa-bb-cc").toString());
- };
-};
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java
index 5fe41bf..932426a 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java
@@ -1,4 +1,5 @@
package de.ids_mannheim.korap.collection;
+
import java.io.IOException;
import de.ids_mannheim.korap.KrillIndex;
@@ -10,7 +11,6 @@
import de.ids_mannheim.korap.KrillQuery;
import de.ids_mannheim.korap.query.QueryBuilder;
-
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
@@ -20,8 +20,6 @@
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.search.spans.SpanQuery;
-
-
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Ignore;
@@ -32,6 +30,7 @@
public class TestKrillCollectionIndex {
private KrillIndex ki;
+
@Test
public void testIndexWithCollectionBuilder () throws IOException {
ki = new KrillIndex();
@@ -65,47 +64,57 @@
assertEquals(1, kcn.docCount());
// Simple orGroup tests
- kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Frank")).with(cb.term("author", "Michael")));
+ kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Frank"))
+ .with(cb.term("author", "Michael")));
assertEquals(1, kcn.docCount());
- kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Frank")).with(cb.term("author", "Sebastian")));
+ kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Frank"))
+ .with(cb.term("author", "Sebastian")));
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Frank"))
- .with(cb.term("author", "Sebastian"))
- .with(cb.term("author", "Peter")));
+ .with(cb.term("author", "Sebastian"))
+ .with(cb.term("author", "Peter")));
assertEquals(3, kcn.docCount());
kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Huhu"))
- .with(cb.term("author", "Haha"))
- .with(cb.term("author", "Hehe")));
+ .with(cb.term("author", "Haha"))
+ .with(cb.term("author", "Hehe")));
assertEquals(0, kcn.docCount());
// Multi field orGroup tests
- kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Peter")));
+ kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1"))
+ .with(cb.term("author", "Peter")));
assertEquals(2, kcn.docCount());
- kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Frank")));
+ kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1"))
+ .with(cb.term("author", "Frank")));
assertEquals(1, kcn.docCount());
- kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Michael")));
+ kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1"))
+ .with(cb.term("author", "Michael")));
assertEquals(1, kcn.docCount());
// Simple andGroup tests
- kcn.fromBuilder(cb.andGroup().with(cb.term("author", "Frank")).with(cb.term("author", "Michael")));
+ kcn.fromBuilder(cb.andGroup().with(cb.term("author", "Frank"))
+ .with(cb.term("author", "Michael")));
assertEquals(0, kcn.docCount());
- kcn.fromBuilder(cb.andGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Frank")));
+ kcn.fromBuilder(cb.andGroup().with(cb.term("ID", "doc-1"))
+ .with(cb.term("author", "Frank")));
assertEquals(1, kcn.docCount());
// andGroup in keyword field test
- kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "reisen")).with(cb.term("textClass", "finanzen")));
+ kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "reisen"))
+ .with(cb.term("textClass", "finanzen")));
assertEquals(1, kcn.docCount());
- kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "reisen")).with(cb.term("textClass", "kultur")));
+ kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "reisen"))
+ .with(cb.term("textClass", "kultur")));
assertEquals(2, kcn.docCount());
- kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "finanzen")).with(cb.term("textClass", "kultur")));
+ kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "finanzen"))
+ .with(cb.term("textClass", "kultur")));
assertEquals(0, kcn.docCount());
kcn.fromBuilder(cb.term("text", "mann"));
@@ -115,6 +124,7 @@
assertEquals(1, kcn.docCount());
};
+
@Test
public void testIndexWithNegation () throws IOException {
ki = new KrillIndex();
@@ -136,18 +146,17 @@
assertEquals(1, kcn.docCount());
// orGroup with simple Negation
- kcn.fromBuilder(
- cb.orGroup().with(cb.term("textClass", "kultur").not()).with(cb.term("author", "Peter"))
- );
+ kcn.fromBuilder(cb.orGroup().with(cb.term("textClass", "kultur").not())
+ .with(cb.term("author", "Peter")));
assertEquals(2, kcn.docCount());
- kcn.fromBuilder(
- cb.orGroup().with(cb.term("textClass", "kultur").not()).with(cb.term("author", "Sebastian"))
- );
+ kcn.fromBuilder(cb.orGroup().with(cb.term("textClass", "kultur").not())
+ .with(cb.term("author", "Sebastian")));
assertEquals(1, kcn.docCount());
-
+
};
+
@Test
public void testIndexWithMultipleCommitsAndDeletes () throws IOException {
ki = new KrillIndex();
@@ -206,6 +215,7 @@
assertEquals(3, kcn.docCount());
};
+
@Test
public void testIndexStream () throws IOException {
ki = new KrillIndex();
@@ -215,8 +225,8 @@
Analyzer ana = new TextAnalyzer();
TokenStream ts = fd.doc.getField("text").tokenStream(ana, null);
- CharTermAttribute charTermAttribute =
- ts.addAttribute(CharTermAttribute.class);
+ CharTermAttribute charTermAttribute = ts
+ .addAttribute(CharTermAttribute.class);
ts.reset();
ts.incrementToken();
@@ -235,6 +245,7 @@
assertEquals("straße", charTermAttribute.toString());
};
+
@Test
public void testIndexWithDateRanges () throws IOException {
ki = new KrillIndex();
@@ -353,7 +364,9 @@
"freizeit-unterhaltung"));
*/
- kc.fromBuilder(kc.build().andGroup().with(kc.build().term("textClass", "reisen")).with(kc.build().term("textClass", "freizeit-unterhaltung")));
+ kc.fromBuilder(kc.build().andGroup()
+ .with(kc.build().term("textClass", "reisen"))
+ .with(kc.build().term("textClass", "freizeit-unterhaltung")));
assertEquals("Documents", 5, kc.numberOf("documents"));
assertEquals("Tokens", 1678, kc.numberOf("tokens"));
@@ -393,7 +406,8 @@
QueryBuilder kq = new QueryBuilder("tokens");
SpanQuery query = kq.seg("opennlp/p:NN").with("tt/p:NN").toQuery();
- Result kr = ki.search(kc, query, 0, (short) 20, true, (short) 5, true, (short) 5);
+ Result kr = ki.search(kc, query, 0, (short) 20, true, (short) 5, true,
+ (short) 5);
assertEquals(kr.getTotalResults(), 70);
@@ -444,7 +458,9 @@
kc.filter(kf.and("textClass", "reisen").and("textClass",
"freizeit-unterhaltung"));
*/
- kc.filter(kc.build().andGroup().with(kc.build().term("textClass", "reisen")).with(kc.build().term("textClass", "freizeit-unterhaltung")));
+ kc.filter(kc.build().andGroup()
+ .with(kc.build().term("textClass", "reisen"))
+ .with(kc.build().term("textClass", "freizeit-unterhaltung")));
assertEquals("Documents", 5, kc.numberOf("documents"));
assertEquals("Tokens", 1678, kc.numberOf("tokens"));
@@ -474,7 +490,8 @@
QueryBuilder kq = new QueryBuilder("tokens");
SpanQuery query = kq.seg("opennlp/p:NN").with("tt/p:NN").toQuery();
- Result kr = ki.search(kc, query, 0, (short) 20, true, (short) 5, true, (short) 5);
+ Result kr = ki.search(kc, query, 0, (short) 20, true, (short) 5, true,
+ (short) 5);
assertEquals(kr.getTotalResults(), 70);
// kc.extend(kf.and("textClass", "uninteresting"));
@@ -514,6 +531,7 @@
assertEquals("Paragraphs", 48, kc.numberOf("paragraphs"));
};
+
@Test
public void filterExample2Legacy () throws Exception {
@@ -544,7 +562,8 @@
KrillCollection kc = new KrillCollection(ki);
CollectionBuilder cb = kc.build();
- kc.filter(cb.andGroup().with(cb.term("textClass", "reisen")).with(cb.term("textClass","freizeit-unterhaltung")));
+ kc.filter(cb.andGroup().with(cb.term("textClass", "reisen"))
+ .with(cb.term("textClass", "freizeit-unterhaltung")));
assertEquals("Documents", 5, kc.numberOf("documents"));
assertEquals("Tokens", 1678, kc.numberOf("tokens"));
@@ -557,7 +576,8 @@
SpanQuery query = kq.seg("opennlp/p:NN").with("tt/p:NN").toQuery();
- Result kr = ki.search(kc, query, 0, (short) 20, true, (short) 5, true, (short) 5);
+ Result kr = ki.search(kc, query, 0, (short) 20, true, (short) 5, true,
+ (short) 5);
assertEquals(kr.getTotalResults(), 369);
// kc.filter(kf.and("corpusID", "QQQ"));
@@ -568,7 +588,8 @@
assertEquals("Sentences", 0, kc.numberOf("sentences"));
assertEquals("Paragraphs", 0, kc.numberOf("paragraphs"));
- kr = ki.search(kc, query, 0, (short) 20, true, (short) 5, true, (short) 5);
+ kr = ki.search(kc, query, 0, (short) 20, true, (short) 5, true,
+ (short) 5);
assertEquals(kr.getTotalResults(), 0);
};
@@ -612,6 +633,7 @@
assertEquals((long) 39, kr.getTotalResults());
};
+
@Test
public void uidCollectionWithDeletions () throws IOException {
@@ -665,6 +687,7 @@
return fd;
};
+
private FieldDocument createDoc2 () {
FieldDocument fd = new FieldDocument();
fd.addString("ID", "doc-2");
@@ -675,6 +698,7 @@
return fd;
};
+
private FieldDocument createDoc3 () {
FieldDocument fd = new FieldDocument();
fd.addString("ID", "doc-3");
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java
index a504bf2..2736722 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java
@@ -29,8 +29,7 @@
public void collection1 () {
String metaQuery = _getJSONString("collection_1.jsonld");
KrillCollection kc = new KrillCollection(metaQuery);
- assertEquals(kc.toString(),
- "pubDate:[20000101 TO 20000101]");
+ assertEquals(kc.toString(), "pubDate:[20000101 TO 20000101]");
};
@@ -55,7 +54,8 @@
public void collection5 () {
String metaQuery = _getJSONString("collection_5.jsonld");
KrillCollection kc = new KrillCollection(metaQuery);
- assertEquals(kc.toString(), "OrGroup(pubDate:[19900000 TO 99999999] title:Mannheim)");
+ assertEquals(kc.toString(),
+ "OrGroup(pubDate:[19900000 TO 99999999] title:Mannheim)");
};
@@ -66,8 +66,8 @@
assertFalse(ks.hasErrors());
assertFalse(ks.hasWarnings());
assertFalse(ks.hasMessages());
- assertEquals("QueryWrapperFilter(author:/Goethe/)", ks
- .getCollection().toString());
+ assertEquals("QueryWrapperFilter(author:/Goethe/)", ks.getCollection()
+ .toString());
};
@@ -78,8 +78,8 @@
assertFalse(ks.hasErrors());
assertFalse(ks.hasWarnings());
assertFalse(ks.hasMessages());
- assertEquals("-QueryWrapperFilter(author:/Goethe/)", ks
- .getCollection().toString());
+ assertEquals("-QueryWrapperFilter(author:/Goethe/)", ks.getCollection()
+ .toString());
};
@@ -90,8 +90,7 @@
assertFalse(ks.hasErrors());
assertFalse(ks.hasWarnings());
assertFalse(ks.hasMessages());
- assertEquals("-author:Goethe", ks
- .getCollection().toString());
+ assertEquals("-author:Goethe", ks.getCollection().toString());
};
@@ -166,9 +165,12 @@
*/
// This will and should fail on optimization
- assertEquals("OrGroup(AndGroup(textClass:wissenschaft AndGroup(pubPlace:Erfurt author:Hesse)) AndGroup(AndGroup(pubDate:[20110429 TO 99999999] pubDate:[0 TO 20131231]) textClass:freizeit))", kc.toString());
+ assertEquals(
+ "OrGroup(AndGroup(textClass:wissenschaft AndGroup(pubPlace:Erfurt author:Hesse)) AndGroup(AndGroup(pubDate:[20110429 TO 99999999] pubDate:[0 TO 20131231]) textClass:freizeit))",
+ kc.toString());
};
+
@Test
public void metaQuery2Legacy () {
String metaQuery = getString(getClass().getResource(
@@ -180,7 +182,8 @@
"filter with QueryWrapperFilter(+(+author:Hesse +pubDate:[0 TO 20131205]))",
kc.getFilter(0).toString());
*/
- assertEquals("AndGroup(author:Hesse pubDate:[0 TO 20131205])", kc.toString());
+ assertEquals("AndGroup(author:Hesse pubDate:[0 TO 20131205])",
+ kc.toString());
};
@@ -196,7 +199,9 @@
"filter with QueryWrapperFilter(+(+pubDate:[20000101 TO 99999999] +pubDate:[0 TO 20131231]))",
kc.getFilter(0).toString());
*/
- assertEquals("AndGroup(pubDate:[20000101 TO 99999999] pubDate:[0 TO 20131231])", kc.toString());
+ assertEquals(
+ "AndGroup(pubDate:[20000101 TO 99999999] pubDate:[0 TO 20131231])",
+ kc.toString());
};
@@ -215,7 +220,9 @@
kc.getFilter(1).toString());
*/
// TODO: This is subject to optimization and may change in further versions
- assertEquals("AndGroup(OrGroup(corpusID:c-1 corpusID:c-2) AndGroup(corpusID:d-1 corpusID:d-2))", kc.toString());
+ assertEquals(
+ "AndGroup(OrGroup(corpusID:c-1 corpusID:c-2) AndGroup(corpusID:d-1 corpusID:d-2))",
+ kc.toString());
};
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSONLegacy.java b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSONLegacy.java
deleted file mode 100644
index d9a8cff..0000000
--- a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSONLegacy.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package de.ids_mannheim.korap.collection;
-
-import java.util.*;
-import java.io.*;
-
-import de.ids_mannheim.korap.KrillCollectionLegacy;
-
-import static de.ids_mannheim.korap.TestSimple.*;
-
-import static org.junit.Assert.*;
-import org.junit.Test;
-import org.junit.Ignore;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public class TestKrillCollectionJSONLegacy {
-
- @Test
- @Ignore
- public void metaQuery1 () {
- String metaQuery = getString(getClass().getResource(
- "/queries/metaquery.jsonld").getFile());
- KrillCollectionLegacy kc = new KrillCollectionLegacy(metaQuery);
-
- assertEquals("filter with QueryWrapperFilter(+textClass:wissenschaft)",
- kc.getFilter(0).toString());
- assertEquals(
- "filter with QueryWrapperFilter(+(+pubPlace:Erfurt +author:Hesse))",
- kc.getFilter(1).toString());
- assertEquals(
- "extend with QueryWrapperFilter(+(+pubDate:[20110429 TO 20131231] +textClass:freizeit))",
- kc.getFilter(2).toString());
- assertEquals(3, kc.getCount());
- };
-
-
- @Test
- @Ignore
- public void metaQuery2 () {
- String metaQuery = getString(getClass().getResource(
- "/queries/metaquery2.jsonld").getFile());
- KrillCollectionLegacy kc = new KrillCollectionLegacy(metaQuery);
- assertEquals(1, kc.getCount());
- assertEquals(
- "filter with QueryWrapperFilter(+(+author:Hesse +pubDate:[0 TO 20131205]))",
- kc.getFilter(0).toString());
- };
-
-
- @Test
- @Ignore
- public void metaQuery3 () {
- String metaQuery = getString(getClass().getResource(
- "/queries/metaquery4.jsonld").getFile());
- KrillCollectionLegacy kc = new KrillCollectionLegacy(metaQuery);
- assertEquals(1, kc.getCount());
- assertEquals(
- // "filter with QueryWrapperFilter(+pubDate:[20000101 TO 20131231])"
- "filter with QueryWrapperFilter(+(+pubDate:[20000101 TO 99999999] +pubDate:[0 TO 20131231]))",
- kc.getFilter(0).toString());
- };
-
-
- @Test
- @Ignore
- public void metaQuery7 () {
- String metaQuery = getString(getClass().getResource(
- "/queries/metaquery7.jsonld").getFile());
- KrillCollectionLegacy kc = new KrillCollectionLegacy(metaQuery);
- assertEquals(2, kc.getCount());
- assertEquals(
- "filter with QueryWrapperFilter(+(corpusID:c-1 corpusID:c-2))",
- kc.getFilter(0).toString());
- assertEquals(
- "filter with QueryWrapperFilter(+(+corpusID:d-1 +corpusID:d-2))",
- kc.getFilter(1).toString());
- };
-
-
- @Test
- @Ignore
- public void metaQuery9 () {
- String metaQuery = getString(getClass().getResource(
- "/queries/metaquery9.jsonld").getFile());
- KrillCollectionLegacy kc = new KrillCollectionLegacy(metaQuery);
- assertEquals(1, kc.getCount());
- assertEquals("filter with QueryWrapperFilter(+corpusID:WPD)", kc
- .getFilter(0).toString());
- };
-};
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
index 49f9d8c..3f651b5 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
@@ -85,8 +85,7 @@
assertEquals(null, id.getTextSigle());
assertEquals(id.toString(), "match-c1!d1-p4-20(5)7-8(2)3-4(4)7-8");
- id = new MatchIdentifier(
- "match-GOE!GOE_AGF.02286-p2105-2106");
+ id = new MatchIdentifier("match-GOE!GOE_AGF.02286-p2105-2106");
assertEquals(2105, id.getStartPos());
assertEquals(2106, id.getEndPos());
assertEquals(null, id.getCorpusID());
@@ -95,6 +94,7 @@
assertEquals("match-GOE_AGF.02286-p2105-2106", id.toString());
};
+
@Test
public void posIdentifierExample1 () throws IOException {
PosIdentifier id = new PosIdentifier();
@@ -255,22 +255,15 @@
km.getSnippetHTML());
};
+
@Test
public void indexNewStructure () throws IOException, QueryException {
KrillIndex ki = new KrillIndex();
ki.addDoc(getClass().getResourceAsStream("/goe/AGX-00002.json"), false);
ki.commit();
- Match km = ki.getMatchInfo(
- "match-GOE!GOE_AGX.00002-p210-211",
- "tokens",
- true,
- (String) null,
- (String) null,
- true,
- true,
- true
- );
+ Match km = ki.getMatchInfo("match-GOE!GOE_AGX.00002-p210-211",
+ "tokens", true, (String) null, (String) null, true, true, true);
JsonNode res = mapper.readTree(km.toJsonString());
assertEquals("tokens", res.at("/field").asText());
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
index 603cbbc..3b96e13 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
@@ -19,7 +19,6 @@
import de.ids_mannheim.korap.response.Match;
import de.ids_mannheim.korap.response.Result;
import de.ids_mannheim.korap.Krill;
-import de.ids_mannheim.korap.collection.BooleanFilter;
import de.ids_mannheim.korap.query.DistanceConstraint;
import de.ids_mannheim.korap.query.SpanDistanceQuery;
import de.ids_mannheim.korap.query.SpanElementQuery;
@@ -168,15 +167,16 @@
//0.8s
// Check if it includes some results
-
+
/*
-BooleanFilter bf = new BooleanFilter();
+ BooleanFilter bf = new BooleanFilter();
bf.or("ID", "WPD_BBB.04463", "WPD_III.00758");
*/
-
+
KrillCollection kc = new KrillCollection();
CollectionBuilder cb = new CollectionBuilder();
- kc.fromBuilder(cb.orGroup().with(cb.term("ID", "WPD_BBB.04463")).with(cb.term("ID", "WPD_III.00758")));
+ kc.fromBuilder(cb.orGroup().with(cb.term("ID", "WPD_BBB.04463"))
+ .with(cb.term("ID", "WPD_III.00758")));
// kc.filter(bf);
ks.setCollection(kc);
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
index b906609..3663623 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
@@ -32,6 +32,7 @@
assertTrue(sqwi.isOptional());
};
+
@Test
public void queryJSONBsp1Disjunction () throws QueryException {
SpanQueryWrapper sqwi = jsonQuery(getClass().getResource(
@@ -481,7 +482,9 @@
SpanQueryWrapper sqwi = jsonQuery(getClass().getResource(
"/queries/bugs/unspecified_key_bug.jsonld").getFile());
- assertEquals(sqwi.toQuery().toString(), "spanContain(<tokens:s />, spanDistance(tokens:s:Erde, tokens:s:Sonne, [(w[0:100], ordered, notExcluded)]))");
+ assertEquals(
+ sqwi.toQuery().toString(),
+ "spanContain(<tokens:s />, spanDistance(tokens:s:Erde, tokens:s:Sonne, [(w[0:100], ordered, notExcluded)]))");
};
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java b/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java
index 3d25377..58c0507 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java
@@ -23,8 +23,10 @@
import org.junit.runners.JUnit4;
/**
- * These tests are meant to fail in a predictable way - but they describe
- * temporary behaviour and will be disabled once these features are part of Krill.
+ * These tests are meant to fail in a predictable way - but they
+ * describe
+ * temporary behaviour and will be disabled once these features are
+ * part of Krill.
*/
@RunWith(JUnit4.class)
@@ -57,9 +59,9 @@
assertEquals(kr.getStartIndex(), 0);
assertEquals("This is a warning coming from the serialization", kr
- .getWarning(0).getMessage());
+ .getWarning(0).getMessage());
assertEquals("Class reference checks are currently not supported"
- + " - results may not be correct", kr.getWarning(1)
- .getMessage());
+ + " - results may not be correct", kr.getWarning(1)
+ .getMessage());
};
};
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKrill.java b/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
index 01d1a4b..bde5902 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
@@ -263,6 +263,7 @@
assertEquals(kr.getTotalResults(), 0);
};
+
/*
* Queries should be mirrored correctly for debugging reasons.
*/
@@ -271,8 +272,7 @@
// Construct index
KrillIndex ki = new KrillIndex();
String json = getString(getClass().getResource(
- "/queries/bugs/failing_mirror.jsonld").getFile()
- );
+ "/queries/bugs/failing_mirror.jsonld").getFile());
Krill ks = new Krill(json);
Result kr = ks.apply(ki);
@@ -282,15 +282,14 @@
assertEquals("Unable to parse JSON", res.at("/errors/0/1").asText());
json = getString(getClass().getResource(
- "/queries/bugs/failing_mirror_2.jsonld").getFile()
- );
+ "/queries/bugs/failing_mirror_2.jsonld").getFile());
ks = new Krill(json);
kr = ks.apply(ki);
res = mapper.readTree(kr.toJsonString());
- assertEquals(23,res.at("/meta/count").asInt());
- assertEquals(25,res.at("/meta/itemsPerPage").asInt());
+ assertEquals(23, res.at("/meta/count").asInt());
+ assertEquals(25, res.at("/meta/itemsPerPage").asInt());
assertEquals("base/s:p", res.at("/meta/context").asText());
assertFalse(res.at("/query").isMissingNode());
assertTrue(res.at("/query/@type").isMissingNode());
@@ -813,7 +812,8 @@
kc.extend(new CollectionBuilder().or("corpusSigle", "BZK"));
*/
CollectionBuilder cb = new CollectionBuilder();
- kc.fromBuilder(cb.orGroup().with(kc.getBuilder()).with(cb.term("corpusSigle", "BZK")));
+ kc.fromBuilder(cb.orGroup().with(kc.getBuilder())
+ .with(cb.term("corpusSigle", "BZK")));
ks.setCollection(kc);
assertEquals(1, kc.numberOf("documents"));
@@ -913,7 +913,9 @@
+ " +tokens:s:Schriftzeichen)))",
ks.getCollection().getFilter(1).toString());
*/
- assertEquals("AndGroup(OrGroup(ID:WPD_AAA.00001 ID:WPD_AAA.00002) OrGroup(ID:WPD_AAA.00003 AndGroup(tokens:s:die tokens:s:Schriftzeichen)))", ks.getCollection().toString());
+ assertEquals(
+ "AndGroup(OrGroup(ID:WPD_AAA.00001 ID:WPD_AAA.00002) OrGroup(ID:WPD_AAA.00003 AndGroup(tokens:s:die tokens:s:Schriftzeichen)))",
+ ks.getCollection().toString());
assertEquals(kr.getTotalResults(), 119);
assertEquals(0, kr.getStartIndex());
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java b/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
index d0862a4..0ff48b5 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
@@ -215,6 +215,7 @@
.asText());
};
+
@Test
public void searchCollectionFields () throws IOException {
KrillIndex ki = new KrillIndex();
@@ -245,7 +246,7 @@
// textClass = reisen & wissenschaft
String jsonString = getString(getClass().getResource(
- "/queries/collections/collection_textClass.jsonld").getFile());
+ "/queries/collections/collection_textClass.jsonld").getFile());
Krill ks = new Krill(jsonString);
KrillCollection kc = ks.getCollection();
kc.setIndex(ki);
@@ -254,7 +255,7 @@
// textClass = reisen
jsonString = getString(getClass().getResource(
- "/queries/collections/collection_textClass_2.jsonld").getFile());
+ "/queries/collections/collection_textClass_2.jsonld").getFile());
ks = new Krill(jsonString);
kc = ks.getCollection();
kc.setIndex(ki);
@@ -282,7 +283,7 @@
// author = wolfgang
jsonString = getString(getClass().getResource(
- "/queries/collections/collection_goethe.jsonld").getFile());
+ "/queries/collections/collection_goethe.jsonld").getFile());
ks = new Krill(jsonString);
kc = ks.getCollection();
kc.setIndex(ki);
@@ -291,7 +292,7 @@
// author = Wolfgang
jsonString = getString(getClass().getResource(
- "/queries/collections/collection_goethe_2.jsonld").getFile());
+ "/queries/collections/collection_goethe_2.jsonld").getFile());
ks = new Krill(jsonString);
kc = ks.getCollection();
kc.setIndex(ki);
@@ -299,7 +300,7 @@
assertEquals(1, kc.numberOf("documents"));
Result kr = ks.apply(ki);
-
+
ObjectMapper mapper = new ObjectMapper();
JsonNode res = mapper.readTree(kr.toJsonString());
assertEquals(1, res.at("/meta/totalResults").asInt());