This section explains how you can extract the searched keyword from the referrer URL. Suppose a referrer URL is https://www.google.co.in/#q=learning+storm
. We will pass this referrer URL to our KeywordGenerator
class and the output will be learning storm
. By extracting the keyword to be searched, we can easily identify the search keyword that users are using to reach our site. Let's perform the following steps to extract the keyword from the referrer URL:
We will create a
KeywordGenerator
class in thecom.learningstorm.stormlogprocessing
package. This class contains the logic to generate the keyword from the referrer URL. The following is the source code of theKeywordGenerator
class:/** * This class takes the referrer URL as the input, * analyzes the URL and returns the * keyword to be searched as the output. */ public class KeywordGenerator { public String getKeyword(String referer) { String[] temp; Pattern pat = Pattern.compile("[?&#]q...