Nov 03 2018
Nov 03

Team AdWeb has worked for a distinctive list of industries counting from hospitability to technology and retailers to an online lottery purchase system based website. Yes, we recently collaborated with a Japan-based company to build their website with lottery purchase system, using Drupal 8. We’ve been Drupal-ing even before our inception and have been an active member of the Drupal community, globally. Our association and experience of Drupal were the base of the client’s immense faith in us and we knew that we’re going to stand true to that.

About the Project
The project requirement of the client was to build a website for them in Drupal 8. The website is basically an online lottery purchase system. Due to confidential reasons, we can not share the name of the company/client but would like to share that the experience of working on this project was new and enriching.

 

Major Features/Functionalities
We personally love experimenting and implementing innovative features to enhance the client’s website. Plus, we get a little more excited when its a Drupal 8 website. We integrated a host of futuristic features to this very website too. But since, it’s an online lottery purchase system we knew that the integration of the Payment Gateway is going to be one of an integral part. Hence, we created three types of Payment Gateway, as follows:\

 

  • GMO Payment

  • Coins Payment

  • WebMoney Payment

 

The user is an integral part of this entire online lottery system and hence several functionalities are crafted around them. Like, a user can purchase coins by WebMoney Payment method and can also buy lottery from choosing any product bundle. A user also has an option to select the quantity of the product or go for the complete set. The payment for either of it can be done by the coins, GMO credit card or points.

Draw system is used for the selection of the lottery winner. Other than the lottery prize, the user also stands a chance to win the Kiriban Product as a prize. The Kiriban Product is based on the product bundle configuration, which is an additional product that a user gets as defined by an admin user.

The Problem

Any e-commerce website will definitely have multiple users buying for the same product. In this situation, the backend technicalities should be as such that it updates the quantity left of the product after the last purchase is made. Issues occur when two or more users place the order at the same time. This is an issue that is involved in concurrent shopping. In this case, the lottery opened for some specific time. Hence, the issue occurred in showcasing the updated quantity. This problem came to our notice when the site went live and around 7-8 users made the transaction at one specific time. We immediately started working on the issue.

Challenges Faced:

We quickly picked up the problem and started searching for the resolution. We have had several times, prior to this, created an e-commerce website. Hence, we used multiple methods to resolve the issues, mentioned below, but none of them worked in this particular case.

  • Initially, we tried using a Drupal lock to resolve the issue, but in vain.

  • We, later on, used the MySQL lock but this too didn’t work, due to the involvement of multiple quantities inside for loop.

  • The usage of sleep time with random sleep time also did not work, because it created the nearby value and not the exact one.

Though the method of random sleep time did not work in this case, it gave birth to the final resolution that worked. And hence, we did a minor modification to the same and divided the sleep time in a range of 3. Also, to avoid the possibility of any further clash, we adopted a table of 100.

The Final Resolution:

After trying out a handful of methods, we finally came up with a method that did work out in our favor. Let us share what steps did finally help us in addressing the problem of concurrent shopping that we faced:

  • A table consisting of 1 to 100 numbers was taken, with the sleep time by a range of 3.

  • Later, a random number was picked and a flag value for the same was set

  • Then, a greater number from those numbers with the range of 3 was picked

Below is the table that was created to bring out the final solution:

How it works:

  • At the beginning of the transaction, the max sleep_time will be checked where flag=1

  • The sleep_time for the first user will be 0

  • After this, a random number from max sleep_time is selected with a range of 3

  • The first user’s range is 1-3

  • In the case of the second user, one number will be skipped after the max time and will be started after that number

  • In case a user gets the max sleep_time in 3 then the range for the random number will be 5-7

  • If the second user gets the random number as 6 then the random number range for the third user will be 8-10

  • The flag value will be updated as 1 for this random number

  • In the end, the flag value of the transaction will be updated with 0

The Final Say:

“All is well, that ends well.” And that’s exactly we have to say for this particular project. Yes, though we had coded and created many e-commerce websites before, this was the first time that we picked up a project to create a Drupal 8 website with an online lottery system. And believe us, it was a monumental success for us and satisfying project for the client.

Feb 14 2018
Feb 14

In one of our project, we have to list all post of a content type with search and sort functionality. And the main thing was search form was in the header whereas sort fields were a location in another region.
              
Therefore when we explore search and sort fields from view, both the fields were coming up together.
              
There are two options to overcome this situation:
         

  • Block Clone module

There is one contrib module “Block Clone” is available.
Using this module you can set single block at multiple places.
To solve our above problem we can set expose fields block at two places. and using CSS/jQuery we need to hide/show relative fields as per the block position (like for search block, hide sort fields).
              

  • Search API Sorts

As we already have used Search API module, we go with Search API Sorts contrib plugin.

This module is dependent on Search API module. This module creates a separate block only for sort fields.

  • We need to follow below steps to configure this module:
  • Install and activate this module
  • After activating this module, you can able see link in admin i.e. configuration >> Search and Metadata >> Search API. Select it.
  • You need to create an index first over there.
  • After creating Index, there will be a tab named "SORTS".
  • In that tab, you can able to select fields which you want to make it sortable.

              
By doing this, it will create a separate block for sorting fields & you can place that block where you actually need it.

Hope this helps you well, feel free to add your comments/feedbacks. Need more assistance regarding Custom Drupal Development Get in touch today!

Mar 16 2016
Mar 16

Solr is a standalone enterprise search server with a REST-like API. It is a Java-based application that provides an API for interacting with Apache Lucene via HTTP to facilitate the creation of excellent applications for performing full-text content searches, with a special focus on internet-based search applications.

It offers,

  • Powerful Extensions
  • Faceted Search and Filtering
  • Advanced Configurable Text Analysis
  • Performance Optimization
  • Advanced Storage Options

It becomes an obvious choice because compared to Drupal’s default modules, it’s insanely fast. It helps you improve both speed and relevancy of search result for Drupal site. I will now present a step-by-step guide on how to install necessary tools and integrate Solr with Drupal 7.

-2. Install Java on Ubuntu with Apt-Get

First, update the package index:

sudo apt-get update

Then, check if Java is not already installed:

java -version

If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:

sudo apt-get install default-jre

This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA execute the following command:

sudo apt-get install default-jdk

-1. Install Solr using apt-get (easy way) on Ubuntu 14.04

sudo apt-get -y install openjdk-7-jdk

mkdir /usr/java

ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/java/default

We can now start the real installation of Solr. First, download all files and uncompress them:

cd /opt

wget http://archive.apache.org/dist/lucene/solr/4.7.2/solr-4.7.2.tgz

tar -xvf solr-4.7.2.tgz

cp -R solr-4.7.2/example /opt/solr

cd /opt/solr

java -jar start.jar

Check if it works by visiting http://YOUR_IP:8983/solr

0. How to setup Search API with Apache Solr

Setup Search API

To get Search API working with solr there are a few thing we'll have to configure with solr. First go and download the following modules from drupal.org and place them into sites/all/modules:

  1. Entity
  2. Search API
  3. Search API Solr search

drush dl entity search_api search_api_solr

Configure solr

Copy the schema.xml and solrconfig.xml that ships in search_api_solr and paste it into /solr/conf. It's fine to override the existing xml files just make sure you create a backup.

Now go ahead and test solr with the new xml files.

java -jar start.jar

Go to see if solr is working with the new XML files.

Download SolrPhpClient

Go here and download (Only works with r22 Solr PHP Client (Built 11/09/09 from r22) ) the php solr library and place it in the seach_api_solr directory.

Modules

Go to the modules page and enable the Search API, Search pages and Solr search.

Configure Search API

Go to Configuration >> Search and metadata and click on Search API.

There are three steps involved with setting up a solr search page. First we setup the server, then index and finally the search page.

Setup server

From the Search API configuration page click on the Add server link.

Enter in the Server name and Server description then select Solr service from the Service class select box.

Adjust the Solr service details below if you have any specific requirements.

Once you have finished filling out the form click on Save settings.

Setup Index

Once the server has been setup, the next thing we have to do is configure the index. Click on the Add index from the Search API configuration page.

In the Add index form fill out the Index name and select which entity type you want to index and select Solr from the Server select box.

Once you have created the index you'll have to select which fields will get indexed. This could take some trial and error depending on your data. In the example that I'm using I have add the "main body text" and "Tags" from the Add related fields.

After you have selected which fields get to be indexed, you'll be directed to the Workflow page. On this page you can specify extra data alterations and processors to the index data. For this example we'll keep that page empty.

The final item for the index is to actually add data into the solr index. Click on the Status tab and click on the Index now button.

1. Faceted Search

Another great feature that the Search API gives you is faceted search.

To get started go and enable the Search facets module.

Once the module has been enabled go back and edit the index that you created. Then select Facets from the dropdown.

For this example I enabled the Content type and Tags > Name block. But you can select any facet blocks.

Once the blocks are enabled don't forget to assign them to a region.

Go back to your search page and test out the facets.

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web