Skip to content

Commit

Permalink
Merge pull request kitodo#5936 from BartChris/fix_index_long_numbers_…
Browse files Browse the repository at this point in the history
…master

Allow datatype Long when indexing
  • Loading branch information
solth authored Feb 26, 2024
2 parents ad2e804 + 0d9a889 commit 7a19973
Show file tree
Hide file tree
Showing 4 changed files with 62 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 @@ -655,7 +656,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 @@ -812,7 +813,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 @@ -2126,6 +2127,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 @@ -239,6 +239,19 @@ public void shouldFindByMetadataContent() throws DataException, DAOException, IO
ProcessTestUtils.removeTestProcess(testProcessId);
}

@Test
public void shouldFindByLongNumberInMetadata() throws DataException, DAOException, IOException {
int processId = MockDatabase.insertTestProcess("Test process", 1, 1, 1);
ProcessTestUtils.copyTestMetadataFile(processId, ProcessTestUtils.testFileForLongNumbers);
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());
ProcessTestUtils.removeTestProcess(processId);
}

@Test
public void shouldFindProcessWithUnderscore() throws DataException, DAOException {
Project project = ServiceManager.getProjectService().getById(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ProcessTestUtils {
private static final int TEST_TEMPLATE_ID = 1;
private static final String ID_PLACEHOLDER = "IDENTIFIER_PLACEHOLDER";
public static final String testFileForHierarchyParent = "multivalued_metadata.xml";
public static final String testFileForLongNumbers = "testMetadataWithLongNumbers.xml";
public static final String testFileChildProcessToKeep = "testMetadataForChildProcessToKeep.xml";
private static final String testFileChildProcessToRemove = "testMetadataForKitodoScript.xml";
private static final Map<String, String> hierarchyProcessTitlesAndFiles;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<mets:mets
xsi:schemaLocation="info:lc/xmlns/premis-v2 http://www.loc.gov/standards/premis/v2/premis-v2-0.xsd http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/mods.xsd http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd http://www.loc.gov/mix/v10 http://www.loc.gov/standards/mix/mix10/mix10.xsd"
xmlns:mets="http://www.loc.gov/METS/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mets:metsHdr CREATEDATE="2018-09-14T07:45:17">
<mets:agent OTHERTYPE="SOFTWARE" ROLE="CREATOR" TYPE="OTHER">
<mets:name>Kitodo - kitodo-ugh-3.0-SNAPSHOT - 18-April-2018 13:20:13</mets:name>
<mets:note>Kitodo</mets:note>
</mets:agent>
</mets:metsHdr>
<mets:dmdSec ID="DMDLOG_0000">
<mets:mdWrap MDTYPE="MODS">
<mets:xmlData>
<kitodo:kitodo xmlns:kitodo="http://meta.kitodo.org/v1/">
<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>
</mets:dmdSec>
<mets:dmdSec ID="DMDPHYS_0000">
<mets:mdWrap MDTYPE="MODS">
<mets:xmlData>
<kitodo:kitodo xmlns:kitodo="http://meta.kitodo.org/v1/">
<kitodo:metadata name="pathimagefiles">file:/2/images/Sec_Proc_tif</kitodo:metadata>
</kitodo:kitodo>
</mets:xmlData>
</mets:mdWrap>
</mets:dmdSec>
<mets:structMap TYPE="LOGICAL">
<mets:div DMDID="DMDLOG_0000" ID="LOG_0000" TYPE="Monograph"/>
</mets:structMap>
<mets:structMap TYPE="PHYSICAL">
<mets:div DMDID="DMDPHYS_0000" ID="PHYS_0000" TYPE="physSequence"/>
</mets:structMap>
<mets:structLink>
<mets:smLink xlink:to="PHYS_0000" xlink:from="LOG_0000" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</mets:structLink>
</mets:mets>

0 comments on commit 7a19973

Please sign in to comment.