Skip to content

Commit

Permalink
Merge pull request #5911 from BartChris/fix_index_long_numbers
Browse files Browse the repository at this point in the history
[3.6] Allow datatype Long when indexing
  • Loading branch information
solth authored Feb 26, 2024
2 parents 225fddc + 60a62af commit 04f4c9a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -653,7 +654,7 @@ public List<ProcessDTO> findByAnything(String searchQuery) throws DataException
ProcessTypeField.PROJECT_TITLE.getKey(),
ProcessTypeField.COMMENTS.getKey(),
ProcessTypeField.WIKI_FIELD.getKey(),
ProcessTypeField.TEMPLATE_TITLE.getKey()).operator(Operator.AND);
ProcessTypeField.TEMPLATE_TITLE.getKey()).operator(Operator.AND).lenient(true);

if (searchQuery.matches("^\\d*$")) {
multiMatchQueryForProcessFields.fields().put(ProcessTypeField.ID.getKey(), 1.0f);
Expand Down Expand Up @@ -810,7 +811,7 @@ public List<ProcessDTO> findLinkableParentProcesses(String searchInput, int proj
BoolQueryBuilder processQuery = new BoolQueryBuilder()
.should(createSimpleWildcardQuery(ProcessTypeField.TITLE.getKey(), searchInput));
if (searchInput.matches("\\d*")) {
processQuery.should(new MatchQueryBuilder(ProcessTypeField.ID.getKey(), searchInput));
processQuery.should(new MatchQueryBuilder(ProcessTypeField.ID.getKey(), searchInput).lenient(true));
}
BoolQueryBuilder query = new BoolQueryBuilder().must(processQuery)
.must(new MatchQueryBuilder(ProcessTypeField.PROJECT_ID.getKey(), projectId))
Expand Down Expand Up @@ -2113,6 +2114,8 @@ private Map<String, Object> iterateOverJsonObject(JSONObject xmlJSONObject) {
Object value = xmlJSONObject.get(key);
if (value instanceof String || value instanceof Integer) {
json.put(prepareKey(key), value);
} else if (value instanceof Long || value instanceof BigInteger) {
json.put(prepareKey(key), value.toString());
} else if (value instanceof JSONObject) {
JSONObject jsonObject = (JSONObject) value;
Map<String, Object> map = iterateOverJsonObject(jsonObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ public void shouldFindByMetadataContent() throws DataException {
assertEquals(processNotFound, 1, processService.findByAnything("SecondMetaShort").size());
}

@Test
public void shouldFindByLongNumberInMetadata() throws DataException {
assertEquals(processNotFound, 1, processService
.findByMetadata(Collections.singletonMap("CatalogIDDigital", "999999999999999991")).size());
assertEquals(processNotFound, 1, processService
.findByMetadata(Collections.singletonMap("CatalogIDDigital", "991022551489706476")).size());
assertEquals(processNotFound, 1, processService
.findByMetadata(Collections.singletonMap("CatalogIDDigital", "999999999999999999999999991")).size());
}

@Test
public void shouldFindProcessWithUnderscore() throws DataException, DAOException {
Project project = ServiceManager.getProjectService().getById(1);
Expand Down
3 changes: 3 additions & 0 deletions Kitodo/src/test/resources/metadata/5/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<kitodo:metadata name="TitleDocMain">Second process</kitodo:metadata>
<kitodo:metadata name="TitleDocMainShort">Second</kitodo:metadata>
<kitodo:metadata name="TSL_ATS">Proc</kitodo:metadata>
<kitodo:metadata name="CatalogIDDigital">999999999999999991</kitodo:metadata>
<kitodo:metadata name="CatalogIDDigital">991022551489706476</kitodo:metadata>
<kitodo:metadata name="CatalogIDDigital">999999999999999999999999991</kitodo:metadata>
</kitodo:kitodo>
</mets:xmlData>
</mets:mdWrap>
Expand Down

0 comments on commit 04f4c9a

Please sign in to comment.