[DEPRECATED] Ajaxfrancelabs Widgets and Modules
Ajaxfrancelabs is deprecated as of Datafari v6.0 aside from specific admin and search expert functionalities. Please refer to https://datafari.atlassian.net/wiki/spaces/DATAFARI/pages/1517813761 for any search UI related task.
DateSelectorFacet module
A module creating a <div> element into the provided element of his constructor, containing two text inputs with their labels, which implement the Datepicker widget from JQuery UI framework. One input represents a 'From' value and the other one represents a 'To' value. The combination of both values allows the user to select a range of dates. The module then provides a method that returns the range of dates as a string that is formatted as a Solr query filter: (fieldname):[(fromValue) TO (toValue)]. The used fieldname used in the Solr query filter is based on the 'field' parameter provided to the module instance.
The created div looks like this:
Prerequisites
In order to retrieve a proper Solr query filter value from the method getFilter(), the 'field' parameter of the module instance must be set with a valid Solr field name which is of date type !
Variables
elm : the jquery element, or the id of the element in which the module will build his <div>
field : Solr field name that will be used to construct the Solr query filter in the getFilter() method
manager : the AjaxFranceLabs Manager instance that rules every widgets and modules. Must only be set if the module is used with the 'Go' button activated (var 'hideGo' set to false) !
id : the id of the module, must be obviously unic
save : used internally by the module to make a save of himself and re-use it on page load/reload. Must not be manually set !
hideGo : set it to true to hide the 'Go' button or to false to display it (default false). The 'Go' button is a button that appears next to the 'To' input and that triggers the search if the user clicks on it. It is mostly used when the module is implemented into a facet widget as it is the only way the user can notify Datafari that he wants to use the range of dates selected
displayError : (default: false) set it to true to display an error message at the end of the <div> when a user enters a wrong date format. If you enable this option, make sure the HTML element into which the module is attached, has enough width, because the error message is long.
oldFilter : used internally by the module to keep the last used filter. it is used to detect it in the query and replace it by the new one if it has changed. This variable is only used when the 'Go' button is not hidden (var 'hideGo' set to false). Must not be manually set !
fromInitValue : set this variable if you want to display the module with an initial fromValue. The accepted format is "YYYY-MM-DDT00:00:00Z", if this format is not respected, the value will stay empty.
toInitValue : set this variable if you want to display the module with an initial toValue. The accepted format is "YYYY-MM-DDT00:00:00Z", if this format is not respected, the value will stay empty.
Methods
execFacet: method that retrieves the current filter value thanks to the getFilter() self method, save the module before the widgets are refreshed thanks to the selfSave() method, remove the old filter in the manager.store to replace it by the new one and execute the request. This method is exclusively executed by the 'Go' button
selfSave: makes a save of the module div into the 'save' variable, using the jQuery detach function
cleanValues: resets every from/to values
getFromVal: returns the fromValue which is a string formated like "YYYY-MM-DDT00:00:00Z" or a wildcard if the value is empty
getToVal: returns the toValue which is a string formated like "YYYY-MM-DDT00:00:00Z" or a wildcard if the value is empty
getFilter: returns the range of dates as a string that is formatted as a Solr query filter: (fieldname):[(fromValue) TO (toValue)]. For example: last_modified:[2000-01-01T00:00:00Z TO *]
hideGoButton: hide the 'Go' button
showGoButton: show the 'Go' button
isValidDate: Validates that the input string is a valid date formatted as "dd/mm/yyyy". Technically, it checks that the date is well formatted but also that it is a real date, even that the day of the month exists (for example the 29th of february only exists if the year is a leap year)
checkAndUpdateFromInputs: triggered when the focus of the 'From' input element is lost and use the isValidDate() self method to check if the date is correct or not. Displays the error message if the date is not valid and the 'displayError' variable is set to true
checkAndUpdateToInputs: triggered when the focus of the 'To' input element is lost and use the isValidDate() self method to check if the date is correct or not. Displays the error message if the date is not valid and the 'displayError' variable is set to true
createDateSelectorDiv: creates the <div> element (shown in the picture on top of this description)
convertAltDateFormatToDateFormat: converts a string date formated like "YYYY-MM-DDT00:00:00Z" into a string formated like "DD/MM/YYYY". If this format is not respected, the value will stay empty
beforeRequest: triggers the selfSave() self method
afterRequest: triggers the createDateSelectorDiv() self method
SearchBar widget
A widget displaying a search bar and search options.
It contains a link useful to switch to advanced search (if that widget is activated): : in this case a default query is performed and the inputs and URL reset.
Variables
autocomplete: can take 3 values:
false(default): no autocomplete.
true: autocomplete automaticaly created.
AutocomepleteWidget: an autocomplete widget.
autocompleteOptions: options for the autocomplete widget if autocomplete set to true. Check the code to see the default structure.
removeContentButton: if set to true, creates a button which appears when there is text in the search bar in order to remove it and execute a request (default: false).
noRequest: if true, inhibits the request to be sent to Solr (default: false).
updateBrowserAddressBar: if true, the address bar URL is updated with the query parameter,
e.g. ?searchType=AllWords&query=datafari (default: true).removeContentButton: if true, adds a button that clears the search bar (default: false).
Methods
buildWidget: an implementation of the parent class method. It contains the onClick event handler for the advanced search link.
beforeRequest: an implementation of the parent class method.
afterRequest: an implementation of the parent class method; closes the autocomplete menu.
reset: an implementation of the parent class method: it resets the inputs of the widget (useful when switching between basic and advanced search).
updateAddressBar: updates the address bar URL with the search term, e.g. ?searchType=AllWords&query=datafari
clean: resets the pagination and the fq and start parameters of the manager's store.
makeRequest: if the noRequest variable is false, cleans the results area and facets, updates the address bar and performs the search request.
Note that the Autocomplete widget is also an extension of the Autocomplete plugin from jQuery UI and so it has all its variables and methods too.
Result widget
A widget displaying the search result.
Variables
pagination: can take 3 values
false(default): no pagination.
true: pagination automaticaly created.
PagerWidget: a pager widget.
Methods
buildWidget: an implementation of the parent class method.
beforeRequest: an implementation of the parent class method.
afterRequest: an implementation of the parent class method.
SubClassResult widget
A widget that implements Datafari specific code and parameters the Result widget. We did not test this widget towards a direct Solr system. This widget displays the search result. It displays results differently depending on the activation of the LikesAndFavorites widget.
Variables
pagination: can take 3 values
false(default): no pagination.
true: pagination automaticaly created.
PagerWidget: a pager widget.
elmSelector: used to store the results to be displayed. Corresponds to the jQuery selector.
firstTimeWayPoint: used in the mobile mode, to know when we reach the bottom of the page, to trigger the spinner in order to load and display the further results.
isMobile: checks whether we are in mobile mode or not.
mutex_locked : is a variable used as a mutex for the mobile mode
Methods
buildWidget: an implementation of the parent class method.
beforeRequest: an implementation of the parent class method.
afterRequest: an implementation of the parent class method.
ResultIllustrated widget
A widget that extend Result Widget and that displays image in result.
Variables
pagination: can take 3 values
false(default): no pagination.
true: pagination automaticaly created.
PagerWidget: a pager widget.
Methods
buildWidget: an implementation of the parent class method.
beforeRequest: an implementation of the parent class method.
afterRequest: an implementation of the parent class method.
LikesAndFavorites Widget
Methods
buildWidget: an implementation of the parent class method.
beforeRequest: an implementation of the parent class method.
afterRequest: an implementation of the parent class method.
function that is runned after getting the likes and favorites of the user
showError: function that analyze the error and display the corresponding error message
SearchInformation widget
A widget displaying the search informations like the number of document found, the query execution time, ...
Methods
buildWidget: an implementation of the parent class method.
beforeRequest: an implementation of the parent class method.
afterRequest: an implementation of the parent class method.
Table widget
A widget displaying a facet values in a table.
Variables
name: a name for the facet to be displayed.
pagination: can take 3 values:
false(default): no pagination.
true: pagination automaticaly created.
PagerWidget: a pager widget.
nbElmToDisplay: the number of facets to display (default: 10).
sort: can take 3 values
occurences(default): sort the facets by the number of occurences.
AtoZ: sort the facets name by alphabetical order.
ZtoA: sort the facets name in a reversed akphabetical order.
maxDisplay: maximum number of facets (default: 40).
checkedOnTop: if set to true, the checked facets will be sorted on the top before the unchecked facets (default: true).
mappingValues (optional): used to override the values of the facet by custom ones. This variable has to be initialized in the constructor call (search.js) and respect the following format : {"originalFacetValue1" : "customValue1", "originalFacetValue2" : "customValue2", ... }
All the possible facet values don't have to be mapped to custom ones, you can fill this optional variable with the only needed ones, the other values will stay the same.modules: list of modules instances that need to be implemented to this widget.
When the widget is initialized, it will set the 'manager' varaible on each module of the list and create a specific <li> element in his <ul> for each module. The <li> element will be set to them as the 'elm' variable.
Then, the beforeRequest() and afterRequest() method of the widget will respectively call the beforeRequest() and afterRequest() of each module.
Methods
buildWidget: an implementation of the parent class method.
afterRequest: an implementation of the parent class method.
update: a method updating the content of the widget.
assocTags: a method maping the search query facets result.
sortBy: the method sorting the facets, takes the sort mode as parameter.
clickHandler: a callback called when a facet is selected or unslected.
FacetDuplicates widget :
This widget displays duplicate documents that are in the index. It is very specific, not recommended for instance if you have an ecommerce website. It is more useful in an intranet context, where you may be interested to know which documents are present several times in your repositories.
The class is of type « final ». For each hash of a given document, the widget retrieves the corresponding document name (the corresponding field name for the document name needs to be identified. By default in Datafari, it is title_en or title_fr). For more information, refer to the specific deduplication documentation.
Variables
name: a name for the facet to be displayed.
pagination: can take 3 values:
false(default): no pagination.
true: pagination automaticaly created.
PagerWidget: a pager widget.
nbElmToDisplay: the number of facets to display (default: 10).
sort: can take 3 values
occurences(default): sort the facets by the number of occurences.
AtoZ: sort the facets name by alphabetical order.
ZtoA: sort the facets name in a reversed akphabetical order.
maxDisplay: maximum number of facets (default: 40).
checkedOnTop: if set to true, the checked facets will be sorted on the top before the unchecked facets (default: true).
Methods
buildWidget: an implementation of the parent class method.
afterRequest: an implementation of the parent class method.
update: sends an ajax request for each hash to get the name of the document. It will also build the html that will be used to display the facet. If there is no duplicate document, the facet will not be displayed.
assocTags: a method maping the search query facets result.
sortBy: the method sorting the facets, takes the sort mode as parameter.
clickHandler: a callback called when a facet is selected or unslected.
HierarchicalFacet widget
A widget displaying a facet values in a hierarchical way. Available as of Datafari v2.2.
Prerequisites
In order to make this widget work, it is mandatory that the selected facet field represents a path tokenization where each value is prefixed by its depth level.
For example, the path '/home/france/labs' will be tokenized as this : 0/home, 1/home/france, 2/home/france/labs
The default field that is used by the widget is ‘urlHierarchy’. This field exists in the Solr index but it is not filled because the "tokenization" strongly dépends on the crawled source. It can be filled like in the above example during the indexation phase by modifying the DatafariUpdateProcessor.java class located in [DATAFARI_REPO]/datafari-updateprocessor/src/main/java/com/francelabs/datafari/updateprocessor/. In this class, a commented section of the code can be found, that is an example to fill this field, you can use it and adapt it. Once the modifications are done, generate the update processor jar with maven with the command ‘mvn install’ ( to run in the ‘[DATAFARI_REPO]/datafari-updateprocessor/’ folder) then shutdown Datafari, replace the current update processor located in '/opt/datafari/solr/solrcloud/FileShare/lib/custom/' by the new one and restart Datafari.
Finally perform a complete crawl of the repository on which you want to use this widget (must be a full crawl/re-crawl, not a delta one).
Variables
name: a name for the facet to be displayed.
pagination: can take 3 values:
false(default): no pagination.
true: pagination automaticaly created.
PagerWidget: a pager widget.
nbElmToDisplay: the number of facets to display (default: 10).
sort: can take 3 values
occurences(default): sort the facets by the number of occurences.
AtoZ: sort the facets name by alphabetical order.
ZtoA: sort the facets name in a reversed akphabetical order.
maxDisplay: maximum number of facets (default: 40).
checkedOnTop: if set to true, the checked facets will be sorted on the top above the unchecked facets (default: true).
rootLevel: the root depth level of the hierarchical tree (default: 0)
maxDepth: the maximum depth to be displayed, starting from the rootLevel (default: 3)
separator: the separator used between each depth level ( default '/' )
Methods
buildWidget: an implementation of the parent class method.
afterRequest: an implementation of the parent class method.
update: a method updating the content of the widget.
assocTags: a method mapping the search query facets result.
sortBy: the method sorting the facets, takes the sort mode as parameter.
clickHandler: a callback called when a facet is selected or unslected.
selectNoRequest: a method that does the same as the selectHandler parent class method but that doesn't perform the request at the end
unselectNoRequest: a method that does the same as the unselectHandler parent class method but that doesn't perform the request at the end
displayLevel: a method which constructs the hierarchy tree with the search query facets result
PrevisualizeResult widget
A widget that extend Result Widget and that displays a preview window at mousover on the document.
Starting from Datafari 4.1 :
- By default, the previsualize window displays the first 1000 characters of the content of the document.
Prerequisites
In order to make this widget work, you have to customize the content that you want in the window and to activate the widget.
To activate the widget :
in datafari/WebContent/js/search.js :
Uncomment the line :
Manager.addWidget(new AjaxFranceLabs.PrevisualizeResultWidget());in datafari/WebContent/searchView.jsp
Uncomment the lines :
<script type="text/javascript" src="js/AjaxFranceLabs/widgets/PrevisualizeResult.widget.js" charset="utf-8"></script>and
<div id="previsualize"></div>To customize the information displayed :
Go to datafari/WebContent/js/AjaxFranceLabs/widgets/PrevisualizeResult.widget.js and edit the line to display whatever you want instead of the ID of the document :
$($('.doc_list .previsualizetemplate')[index]).append('<div id="previsualizeid">ID : '+docs[index].id+' </div>' );Methods
buildWidget: an implementation of the parent class method.
beforeRequest: an implementation of the parent class method.
afterRequest: an implementation of the parent class method.
showError: function that analyze the error and display the corresponding error message
ExternalResult widget
A widget that allows to have a federated search in Datafari ie display results from another search engine (Solr, Sharepoint for example) and display below the normal results from Datafari.
Prerequisites
In order to make this widget work, you have to parse the response from your external datasource.
To activate the widget :
in datafari/WebContent/js/search.js :
Uncomment the line :
Manager.addWidget(new AjaxFranceLabs.ExternalResultWidget());in datafari/WebContent/searchView.jsp
Uncomment the lines :
<script type="text/javascript" src="js/AjaxFranceLabs/widgets/ExternalResult.widget.js" charset="utf-8"></script>and
<div id="external"></div>to select the data to parse :
in datafari/WebContent/js/AjaxFranceLabs/widgets/ExternalResult.widget.js
Edit the line :
var urldatasource = 'http://localhost:8080/Datafari/externaldata.json';Change the url for the data you want to parse.
Adapt the code in the file to parse the information that you want in the JSON file.
By default the code is adapted to parse the file externaldata.json. Adapt this section :
$.getJSON(urldatasource,querySolr, function(result){
$.each(result.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results,
function(j, docu) {
var highlightingvalues = docu.Cells.results[10].Value;
highlightingvalues = replaceAll(highlightingvalues,"<c0>","<span class='em'>");
highlightingvalues = replaceAll(highlightingvalues,"</c0>","</span>");
elm.find('.externalresults').append(
'<div class="external sp'+ j +'"></div>');
var extension = docu.Cells.results[17].Value;
elm.find('.external:last').append(
'<div class="externaltitle"><a class="externallinktitle" target="_blank" href="'+docu.Cells.results[6].Value+'">'+docu.Cells.results[3].Value+'</a>');
elm.find('.external:last').append('<p class="externalhighlight">'+highlightingvalues);
elm.find('.external:last').append('<p class="externalurl">'+docu.Cells.results[6].Value);
})
});We provide some example data into Datafari if you want to test it out of the box :
Copy datafari/dev-tools/example-data/externaldata.json into datafari/WebContent
Methods
buildWidget: an implementation of the parent class method.
beforeRequest: an implementation of the parent class method.
afterRequest: an implementation of the parent class method.
showError: function that analyze the error and display the corresponding error message
Table Facet Queries widget
A widget displaying facet queries in a table.
Variables
name: a name for the facet to be displayed.
field: the field that will be used in the queries
queries: the list of queries
pagination: can take 3 values:
false(default): no pagination.
true: pagination automaticaly created.
PagerWidget: a pager widget.
nbElmToDisplay: the number of facets to display (default: 10).
maxDisplay: maximum number of facets (default: 40).
modules: list of modules instances that need to be implemented to this widget.
When the widget is initialized, it will set the 'manager' varaible on each module of the list and create a specific <li> element in his <ul> for each module. The <li> element will be set to them as the 'elm' variable.
Then, the beforeRequest() and afterRequest() method of the widget will respectively call the beforeRequest() and afterRequest() of each module.
Spellcheck widget
A widget spellchecking a query string. (eg: can offer you to correct constellia in constellio).
This widget works with both basic and advanced search.
Note: this requires enabling a spellchecker component in the searchhandler of Solr (done in the xml config files), whether you use a pure Solr or a Constellio Solr.
Variables
There are no specific variables: only the ones inherited from AjaxFranceLabs.AbstractWidget.
Methods
buildWidget: an implementation of the parent class method: builds the widget.
beforeRequest: an implementation of the parent class method.
afterRequest: an implementation of the parent class method: here there is the logic of the spellchecker itself. It checks whether the result of the search query has some suggestions and, if so, it calls doSpellCheckerQuery to perform a new search with the spellchecked input, contained in the collations array.
doSpellcheckerQuery: performs a new search with the spellchecked input.
AdvancedSearch widget - new version (v3.2 of Datafari and above)
A widget enabling you to specify on which fields to perform a search.
The result of the search query is spellchecked by SpellChecker widget (if that widget is activated).
It contains a link useful to switch to basic search (if that widget is activated): in this case a default query is performed and the inputs and URL reset.
The AdvancedSearch widget is built with one other classe:
AdvancedSearchField: which are the different fields provided by the advanced search.
Variables
mappingFieldNameValues: a map containing labels associated to fieldNames. This is usefull if you want to display a different label in the advancesSearch than the default solr fieldName which can be non human friendly.
The format of this parameter is the following: {"fieldName":"Custom label","fieldName2":"Custom label 2",...}
External variables
The advanced search widget is using external variables defined in the advanced-search.properties file located in DATAFARI_HOME/tomcat/conf
Here are the available variables in this file:
DENIEDFIELDLIST: list of Solr fields that you don't want to appear in the advanced search fields list. In this variable, fieldNames are separated by coma ( ex: DENIEDFIELDLIST=field1,field2,.... )
EXACTFIELDS: list of Solr fields that have associated exact fields in Solr. For each Solr field specified in this list, the advanceSearchWidget will use its associated exact field to perform exact expression search.
In this variable, fieldNames are separated by coma ( ex: EXACTFIELDS=field1,field2,.... )
As you cannot (for the moment) specify the name of the associated exact fields, the associated exact fields must respect the following naming rule for the advancedSearchWidget to be able to automaticaly use them : exact_fieldName
Methods
buildWidget: an implementation of the parent class method: builds the widget.
reinitVariables: cleans all the fields selected in the advanced search and their filters values
buildStartingUI: builds the advanced search UI according to the last executed query in the search UI. This function parses the last executed query in the standard search UI to build every required elements in the advanced search (the fields and their filters values)
extractFilterFromText: computes the values entered by the user for a specific field, in order to create the corresponding filters which can be processed as a query by Solr
addField: adds a new field and its filters elements to the advanced search UI