Skip to content

Commit

Permalink
UFAL/Autocomplete enhancement (#768)
Browse files Browse the repository at this point in the history
* Added solr index `handle_title_ac` and `_comp` for the Item

* Added support for searching results from specific solr indexes.

1. Updated submission-forms autocomplete definition to specify a specific index. 2. Updated configuration is provided via REST API. 3. Create a new `/suggestions` endpoint for searching values from custom solr index - it returns VocabularyEntry page.

* Supported searching Item byHandle when passed a handle as parameter without handle canonical prefix.

* Added autocompleteCustom `solr-subject_ac` and `handle_title_ac`.

* Added autocompleteCustom `solr-publisher_ac`.

* Added cfg property to define a separator from the solr value to get only display value.

* Added autocompleteCustom `solr-dataProvider_ac`

* Refactored code and created integration test for the SuggestionRestController

* Updated suggestion integration tests because it has had a conflict with another IT

* Added doc and changed `autocomplete.custom.format` to `autocomplete.custom.separator` for proper naming.

* Added support for loading suggestions from the json file - need to refactor.

* Refactored and added docs.

* Created tests and fixed failing ones due to updated solr definition

* Synchronized submission-forms_cs.xml with the original-english one

* Added docs about magic constants

* Added doc why the handle is updated to canonical form in the searchbyHandle endpoint

* Allow searching only within the solr indexes or JSON files permitted by the configuration.

* Removed normalization of handle prefix because there could be more prefixes. Expect only handle value.

* Fixed if condition and config property default value.

* Fixed integration tests. Allowed autocomplete custom was missing in the test cfg.

* The suggestion endpoint is allowed only for authorized users

* Refactored method for the normalizing the query for the discoverQuery and added unit tests.
  • Loading branch information
milanmajchrak authored Nov 19, 2024
1 parent 32f61b3 commit 582906c
Show file tree
Hide file tree
Showing 23 changed files with 8,863 additions and 174 deletions.
16 changes: 16 additions & 0 deletions dspace-api/src/main/java/org/dspace/app/util/DCInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ public class DCInput {
*/
private ComplexDefinition complexDefinition = null;

/**
* give suggestions from this specific autocomplete solr index/file
*/
private String autocompleteCustom = null;

/**
* the dropdown input type could have defined a default value
*/
Expand Down Expand Up @@ -235,6 +240,9 @@ public DCInput(Map<String, String> fieldMap, Map<String, List<String>> listMap,
if ("complex".equals(inputType)) {
complexDefinition = complexDefinitions.getByName((fieldMap.get(DCInputsReader.COMPLEX_DEFINITION_REF)));
}
if ("autocomplete".equals(inputType)) {
autocompleteCustom = fieldMap.get(DCInputsReader.AUTOCOMPLETE_CUSTOM);
}
hint = fieldMap.get("hint");
warning = fieldMap.get("required");
required = warning != null && warning.length() > 0;
Expand Down Expand Up @@ -725,6 +733,14 @@ public boolean isMetadataField() {
return isMetadataField;
}

public String getAutocompleteCustom() {
return autocompleteCustom;
}

public void setAutocompleteCustom(String autocompleteCustom) {
this.autocompleteCustom = autocompleteCustom;
}

/**
* Class representing a Map of the ComplexDefinition object
* Class is copied from UFAL/CLARIN-DSPACE (https://github.com/ufal/clarin-dspace) and modified by
Expand Down
10 changes: 10 additions & 0 deletions dspace-api/src/main/java/org/dspace/app/util/DCInputsReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public class DCInputsReader {
static final String COMPLEX_DEFINITION_REF = "complex-definition-ref";
public static final String TYPE_BIND_FIELD_ATTRIBUTE = "field";

/**
* Keyname for storing the name of the custom autocomplete input type
*/
static final String AUTOCOMPLETE_CUSTOM = "autocomplete-custom";


/**
* Reference to the forms definitions map, computed from the forms
Expand Down Expand Up @@ -552,6 +557,11 @@ private void handleInputTypeTagName(String formName, Map<String, String> field,
} else {
field.put(COMPLEX_DEFINITION_REF, definitionName);
}
} else if (value.equals("autocomplete")) {
String definitionName = getAttribute(nd, AUTOCOMPLETE_CUSTOM);
if (definitionName != null) {
field.put(AUTOCOMPLETE_CUSTOM, definitionName);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,28 @@ public void addDiscoveryFields(SolrInputDocument doc, Context context, Item item
}



// process item metadata
// just add _comp to local*
List<MetadataValue> mds = itemService.getMetadata(item, "local", Item.ANY, Item.ANY, Item.ANY);
for (MetadataValue meta : mds) {
String field = "local" + "." + meta.getMetadataField().getElement();
String value = meta.getValue();
if (value == null) {
continue;
}
String qualifier = meta.getMetadataField().getQualifier();
if (qualifier != null && !qualifier.isEmpty()) {
field += "." + qualifier;
}
doc.addField(field + "_comp", value);
}

// create handle_title_ac field
String title = item.getName();
String handle = item.getHandle();
doc.addField("handle_title_ac", handle + ":" + title);

log.debug(" Added Metadata");

try {
Expand Down
Loading

0 comments on commit 582906c

Please sign in to comment.