fix #2060 use url pattern in ds
This commit is contained in:
parent
a3e2c9c5b2
commit
36c963c224
3 changed files with 49 additions and 0 deletions
|
@ -15,11 +15,14 @@
|
|||
*/
|
||||
package org.codelibs.fess.ds.callback;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.codelibs.core.stream.StreamUtil;
|
||||
import org.codelibs.fess.es.client.FessEsClient;
|
||||
import org.codelibs.fess.exception.DataStoreException;
|
||||
import org.codelibs.fess.helper.CrawlingInfoHelper;
|
||||
|
@ -82,6 +85,15 @@ public class IndexUpdateCallbackImpl implements IndexUpdateCallback {
|
|||
addFavoriteCountField(dataMap, url, fessConfig.getIndexFieldFavoriteCount());
|
||||
}
|
||||
|
||||
final Set<String> matchedLabelSet = ComponentUtil.getLabelTypeHelper().getMatchedLabelValueSet(url);
|
||||
if (!matchedLabelSet.isEmpty()) {
|
||||
final Set<String> newLabelSet = new HashSet<>();
|
||||
final String[] oldLabels = DocumentUtil.getValue(dataMap, fessConfig.getIndexFieldLabel(), String[].class);
|
||||
StreamUtil.stream(oldLabels).of(stream -> stream.forEach(newLabelSet::add));
|
||||
matchedLabelSet.stream().forEach(newLabelSet::add);
|
||||
dataMap.put(fessConfig.getIndexFieldLabel(), newLabelSet.toArray(new String[newLabelSet.size()]));
|
||||
}
|
||||
|
||||
if (!dataMap.containsKey(fessConfig.getIndexFieldDocId())) {
|
||||
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
|
||||
dataMap.put(fessConfig.getIndexFieldDocId(), systemHelper.generateDocId(dataMap));
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.codelibs.fess.util;
|
|||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -53,6 +54,8 @@ public final class DocumentUtil {
|
|||
if (value instanceof List) {
|
||||
if (clazz.isAssignableFrom(List.class)) {
|
||||
return (T) value;
|
||||
} else if (clazz.isAssignableFrom(String[].class)) {
|
||||
return (T) ((List<?>) value).stream().filter(s -> s != null).map(s -> s.toString()).toArray(n -> new String[n]);
|
||||
}
|
||||
|
||||
if (((List<?>) value).isEmpty()) {
|
||||
|
@ -60,6 +63,22 @@ public final class DocumentUtil {
|
|||
}
|
||||
|
||||
return convertObj(((List<?>) value).get(0), clazz);
|
||||
} else if (value instanceof String[]) {
|
||||
if (clazz.isAssignableFrom(String[].class)) {
|
||||
return (T) value;
|
||||
} else if (clazz.isAssignableFrom(List.class)) {
|
||||
final List<String> list = new ArrayList<>();
|
||||
for (final String s : (String[]) value) {
|
||||
list.add(s);
|
||||
}
|
||||
return (T) list;
|
||||
}
|
||||
|
||||
if (((String[]) value).length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return convertObj(((String[]) value)[0], clazz);
|
||||
}
|
||||
|
||||
return convertObj(value, clazz);
|
||||
|
|
|
@ -15,13 +15,17 @@
|
|||
*/
|
||||
package org.codelibs.fess.util;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.unit.UnitFessTestCase;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
public class DocumentUtilTest extends UnitFessTestCase {
|
||||
|
||||
|
@ -39,6 +43,20 @@ public class DocumentUtilTest extends UnitFessTestCase {
|
|||
assertNull(DocumentUtil.getValue(doc, "key2", String.class));
|
||||
}
|
||||
|
||||
public void test_strings() {
|
||||
Map<String, Object> doc = new HashMap<>();
|
||||
doc.put("key1", new String[] { "aaa", "bbb" });
|
||||
assertArrayEquals(new String[] { "aaa", "bbb" }, DocumentUtil.getValue(doc, "key1", String[].class));
|
||||
assertEquals(Arrays.asList("aaa", "bbb"), (List<String>) DocumentUtil.getValue(doc, "key1", List.class));
|
||||
}
|
||||
|
||||
public void test_list() {
|
||||
Map<String, Object> doc = new HashMap<>();
|
||||
doc.put("key1", Arrays.asList("aaa", "bbb"));
|
||||
assertArrayEquals(new String[] { "aaa", "bbb" }, DocumentUtil.getValue(doc, "key1", String[].class));
|
||||
assertEquals(Arrays.asList("aaa", "bbb"), (List<String>) DocumentUtil.getValue(doc, "key1", List.class));
|
||||
}
|
||||
|
||||
public void test_integer() {
|
||||
Map<String, Object> doc = new HashMap<>();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue