Skip to content

Commit

Permalink
fixed exceptions which can occur during reindexing
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Mar 30, 2023
1 parent f131d5e commit d98cf58
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>com.erudika</groupId>
<artifactId>para-core</artifactId>
<version>1.48.0</version>
<version>1.48.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/erudika/para/server/search/LuceneUtils.java
Expand Up @@ -33,6 +33,7 @@
import java.io.IOException;
import java.nio.file.FileSystems;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -115,7 +116,7 @@ public final class LuceneUtils {
private static final Set<String> NOT_ANALYZED_FIELDS;
private static final Analyzer QUERY_STRING_ANALYZER;
private static final String[] IGNORED_FIELDS;
private static final int FIELD_LIMIT = 16383; // 32766 / 2; = 2 bytes per char, max field length must be <= 32766
private static final int FIELD_LIMIT = 32766; // Lucene limitation for sorted doc values - max field length must be <= 32766 bytes

private static final Map<String, IndexWriter> WRITERS = new ConcurrentHashMap<String, IndexWriter>();
// private static S3Directory s3Directory;
Expand Down Expand Up @@ -430,12 +431,14 @@ private static void addFieldToStack(String prefix, JsonNode val, LinkedList<Map<
}

private static void addSortedDocValuesField(Document doc, String prefix, String txt) {
if (txt.length() > FIELD_LIMIT) {
if (txt.getBytes().length > FIELD_LIMIT) {
int i = 0;
for (int start = 0; start < txt.length(); start += FIELD_LIMIT) {
String s = txt.substring(start, Math.min(txt.length(), start + FIELD_LIMIT));
int len = txt.getBytes().length;
for (int start = 0; start < len; start += FIELD_LIMIT) {
// String s = new String();
// String s = txt.substring(start, Math.min(txt.length(), start + FIELD_LIMIT));
doc.add(new SortedDocValuesField(prefix + (start > 0 ? String.valueOf(++i) : ""),
new BytesRef(s.getBytes())));
new BytesRef(Arrays.copyOfRange(txt.getBytes(), start, Math.min(len, start + FIELD_LIMIT)))));
}
} else {
doc.add(new SortedDocValuesField(prefix, new BytesRef(txt.getBytes())));
Expand Down Expand Up @@ -860,6 +863,7 @@ private static DirectoryReader getIndexReader(String appid) {
}

private static IndexWriter getIndexWriter(String appid) {
appid = StringUtils.trimToEmpty(appid); // remove leading empty space for shared apps
synchronized (WRITERS) {
if (!WRITERS.containsKey(appid)) {
try {
Expand Down Expand Up @@ -1019,7 +1023,7 @@ static Pager getPager(Pager[] pager) {
* @return the correct index name
*/
static String getIndexName(String appid) {
return appid + "-lucene";
return StringUtils.trim(appid) + "-lucene"; // remove leading empty space for shared apps
}

}
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Expand Up @@ -19,6 +19,7 @@
module com.erudika.para.server.search.lucene {
requires com.erudika.para.core;
requires org.apache.commons.lang3;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
requires org.slf4j;
requires java.logging;
Expand Down

0 comments on commit d98cf58

Please sign in to comment.