Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

Deprecated since Datafari 4.3

This documentation is deprecated at least since Datafari 4.3

Problematic :

Starting with Datafari 2.0, users have the possibility to store pointers to documents shown in results list.

...

That means we have dedicated to likes and favorites (which is distinct from the collection dedicated to user authentication and authorization).

The request :

The aim is to get for the connected user the list of documents he liked out of the ones which are currently displayed. After the standard search query, we send only one http request which contains only the username . In return, we get all the documents in the index that are liked, as well as the list of favorites.

On the browser side, we go through this documents list and pick the ones that match the currently displayed documents to identify the favorites and the liked.

In order to display the total number of likes per documents, we use Solr and its External File Fields mechanism ( https://cwiki.apache.org/confluence/display/solr/Working+with+External+Files+and+Processes).

Every time a connected user like or unlikes a document, we increment or decrement the counter of the document in the file located in SOLR_HOME/FileShare/data/externalk_nbLikes.

Image Removed

The Implementation :

There are two parts: Frontend and backend. For the frontend, we added a widget that builds the inteface and makes all the Ajax Requests. For the backend, we created two classes: Like and Favorite. We created the corresponding servlets that use these two classes and send back the result.

Frontend :

The widget is called LikesAndFavoritesWidget. This widget inherits from ResultWidget and is only included in SearchView.jsp if the functionality of likes was activated by the admin.

This inheritance is important because we need to execute first the code of the ResultWidget and then the LikesAndFavoriteWidget.

Once the buildWidget is executed, we execute the beforeRequest which will add the fl nbLikes:field(nbLikes) in the Solr query so we can retrieve as part of the results the number of likes per document.

...

)

...

Next, we put a listener to the “Like” button and a listener for saving a favorite. Depending on which button is clicked, we send a request to add/delete the favorite or the like from the server and from the lists saved in the global variable window of javascript.

Image Removed

Illustration 1: State Diagram of AfterRequest of LikesAndFavoritesWidget

     2. Backend :

We use two major classes which are Like And Favorite. They provide the method that will get, delete and add a Favorite or a Like by querying the Cassandra database. Whenever a change is needed to likes and favorites, we use directly these classes.

Like.class and Favorite.class belong to the package com.francelabs.datafari.user which also contains UserConstants.class where we put all the constant Strings used in this package.

We also use the following servlets:

  • AddFavorite: add a document to favorites,

  • AddLikes: add document to likes,

  • DeleteFavorite: delete a document from favorites,

  • Unlike: delete a document from the likes,

  • GetLikesAndFavorites: gets all the likes and the favorites of a user,,, .

...

.

...

Image Removed

Illustration 2: Sequence Diagram of AddLike for a normal Behaviour

Here is the sequence diagram that involves the LikesAndFavoritesWidget to retrieve the likes and favorites of a user :

Image Removed

Illustration 3: Sequence Diagram of getting the likes and favorites from server