AdvancedSearch Autocomplete - Technical Doc
Valid from Datafari 6.2
When the Advanced Search window is opened, the AdvancedSearchModal
component sends the query "/Datafari/rest/v1.0/fields/autocomplete" to find out which fields have autocomplete available. This request calls the Autocomplete
Rest Controller to retrieve the fields on which autocomplete must be enabled.
The controller simply returns the json defined in the /opt/datafari/tomcat/conf/advanced-search.properties
. See this doc for more details: https://datafari.atlassian.net/wiki/spaces/DATAFARI/pages/482148378
Here is an example of this json:
{
"content": {
"autocompleteFields": {
"author_search": "suggestAuthors"
}
},
"status": "OK"
}
The returned json is stored as an object by the AdvancedSearchModal
component in the Redux store autocomplete
key. It's done in the Redux Slice "advancedSearchSlice", in the "fetchAdvancedSearch" switch case.
Then the list of “field:suggester“ pairs, contained in the autocompleteFields
attribute of the autocomplete
object, is passed to the SpecificSearchField
component (see in the rendering part of the AdvancedSearchModal
component). This component allows you to select a field here:
Then using the selected field, the SpecificSearchField
component passes the corresponding suggester to the Autocomplete
component (if the field allows autocomplete). Example:
{isFocusedAllWords && Object.keys(autocomplete).includes(selectedField.trim()) && (
<Autocomplete
queryText={allWords}
type={'allWords'}
suggestType={autocomplete[selectedField.trim()]}
updateQueryText={handleUpdateQueryText}
/>
)}
The Autocomplete
component displays the drop-down list of suggestions by sending the suggest query using the suggester passed by SpecificSearchField
.
Not implemented from Datafari 5.0 up to Datafari 6.1
Valid up to Datafari 4.3
The AdvancedSearch.widget.js
, during init, calls the GetAutocompleteAdvancedFields
servlet to retrieve the fields on which autocomplete must be enabled.
The GetAutocompleteAdvancedFields
servlet simply returns the json defined in the /opt/datafari/tomcat/conf/advanced-search.properties
. See this doc for more details: https://datafari.atlassian.net/wiki/spaces/DATAFARI/pages/482148378
The returned json is stored by the AdvancedSearch.widget.js
in the parameter 'autocompleteFields
'
When the AdvancedSearch.widget.js
constructs the selected fields thanks to the AjaxFranceLabs.AdvancedSearchField
constructor, if the field name is referenced in the 'autocompleteFields
' parameter, then the Solr suggester to use is passed as the 'autocompleteSuggester
' parameter
In the AdvancedSearchField.js
, on the call of the buildTextFieldFilterUI
method, if the 'autocompleteSuggester
' parameter is set, then an AjaxFranceLabs.AdvancedAutocompleteModule
is instancied with the autocompleteSuggester
passed as the 'servlet
' parameter, and the HTML element on which to apply the autocomplete is passed as the 'elm
' parameter.
The AdvancedAutocomplete.module.js
instantiate a jquery autocomplete module on the 'elm
' parameter and override the 'source
' method of the jquery module (which is called each time the user press a keyboard key on the 'elm
') to call the 'servlet
' (Solr suggester) and create the autocomplete list with each suggestion that have results (it checks that the numFound
is more than 0)