-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend MARC-MARC search query to account for qualifiers #633
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d8728fe
Update submodule to commit 1e4076bf5e4eae9670cd005adea7a174ccfaf681
dmytrokrutii b0b0c68
MODSOURCE-783 add qualifier
dmytrokrutii a2f2a58
MODSOURCE-783 Add tests for match on external ids by qualifier
dmytrokrutii 7b3092c
MODSOURCE-783 Remove unused import
dmytrokrutii cdf47a8
MODSOURCE-783 Remove wildcard import
dmytrokrutii bd2e7d5
MODSOURCE-783 Add search by qualifiers to non-external ids field
dmytrokrutii fe58f08
MODSOURCE-783 Remove redundant constant
dmytrokrutii 29b33e3
MODSOURCE-783 Update NEWS.md
dmytrokrutii 5f41bff
MODSOURCE-783 Update javadoc
dmytrokrutii df5923e
Merge remote-tracking branch 'refs/remotes/origin/master' into MODSOU…
dmytrokrutii 1e91501
MODSOURCE-783 Remove wildcard import
dmytrokrutii 1b21926
MODSOURCE-783 Remove unused variable
dmytrokrutii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,9 @@ public class RecordDaoImpl implements RecordDao { | |
static final int INDEXERS_DELETION_LOCK_NAMESPACE_ID = "delete_marc_indexers".hashCode(); | ||
|
||
public static final String CONTROL_FIELD_CONDITION_TEMPLATE = "\"{partition}\".\"value\" in ({value})"; | ||
public static final String CONTROL_FIELD_CONDITION_TEMPLATE_WITH_QUALIFIER = "\"{partition}\".\"value\" IN ({value}) AND \"{partition}\".\"value\" LIKE {qualifier}"; | ||
public static final String DATA_FIELD_CONDITION_TEMPLATE = "\"{partition}\".\"value\" in ({value}) and \"{partition}\".\"ind1\" LIKE '{ind1}' and \"{partition}\".\"ind2\" LIKE '{ind2}' and \"{partition}\".\"subfield_no\" = '{subfield}'"; | ||
public static final String DATA_FIELD_CONDITION_TEMPLATE_WITH_QUALIFIER = "\"{partition}\".\"value\" IN ({value}) AND \"{partition}\".\"value\" LIKE {qualifier} AND \"{partition}\".\"ind1\" LIKE '{ind1}' AND \"{partition}\".\"ind2\" LIKE '{ind2}' AND \"{partition}\".\"subfield_no\" = '{subfield}'"; | ||
private static final String VALUE_IN_SINGLE_QUOTES = "'%s'"; | ||
private static final String RECORD_NOT_FOUND_BY_ID_TYPE = "Record with %s id: %s was not found"; | ||
private static final String INVALID_PARSED_RECORD_MESSAGE_TEMPLATE = "Record %s has invalid parsed record; %s"; | ||
|
@@ -352,18 +354,26 @@ public Future<List<Record>> getMatchedRecordsWithoutIndexersVersionUsage(MatchFi | |
|
||
private Condition getMatchedFieldCondition(MatchField matchedField, String partition) { | ||
Map<String, String> params = new HashMap<>(); | ||
var qualifierSearch = false; | ||
params.put("partition", partition); | ||
params.put("value", getValueInSqlFormat(matchedField.getValue())); | ||
if (matchedField.getQualifierMatch() != null) { | ||
qualifierSearch = true; | ||
params.put("qualifier", getSqlQualifier(matchedField.getQualifierMatch())); | ||
} | ||
String sql; | ||
Condition condition; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if condition is not used, let's remove it |
||
if (matchedField.isControlField()) { | ||
String sql = StrSubstitutor.replace(CONTROL_FIELD_CONDITION_TEMPLATE, params, "{", "}"); | ||
return condition(sql); | ||
sql = qualifierSearch ? StrSubstitutor.replace(CONTROL_FIELD_CONDITION_TEMPLATE_WITH_QUALIFIER, params, "{", "}") | ||
: StrSubstitutor.replace(CONTROL_FIELD_CONDITION_TEMPLATE, params, "{", "}"); | ||
} else { | ||
params.put("ind1", getSqlInd(matchedField.getInd1())); | ||
params.put("ind2", getSqlInd(matchedField.getInd2())); | ||
params.put("subfield", matchedField.getSubfield()); | ||
String sql = StrSubstitutor.replace(DATA_FIELD_CONDITION_TEMPLATE, params, "{", "}"); | ||
return condition(sql); | ||
sql = qualifierSearch ? sql = StrSubstitutor.replace(DATA_FIELD_CONDITION_TEMPLATE_WITH_QUALIFIER, params, "{", "}") | ||
: StrSubstitutor.replace(DATA_FIELD_CONDITION_TEMPLATE, params, "{", "}"); | ||
} | ||
return condition(sql); | ||
} | ||
|
||
private String getSqlInd(String ind) { | ||
|
@@ -372,6 +382,19 @@ private String getSqlInd(String ind) { | |
return ind; | ||
} | ||
|
||
private String getSqlQualifier(MatchField.QualifierMatch qualifierMatch) { | ||
if (qualifierMatch == null) { | ||
return null; | ||
} | ||
var value = qualifierMatch.value(); | ||
|
||
return switch (qualifierMatch.qualifier()) { | ||
case BEGINS_WITH -> "'" + value + "%'"; | ||
case ENDS_WITH -> "'%" + value + "'"; | ||
case CONTAINS -> "'%" + value + "%'"; | ||
}; | ||
} | ||
|
||
private String getValueInSqlFormat(Value value) { | ||
if (Value.ValueType.STRING.equals(value.getType())) { | ||
return format(VALUE_IN_SINGLE_QUOTES, value.getValue()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please also replace this line
import static org.jooq.impl.DSL.*;
with exact importing classes?