Connecting the Query Builder to DataSift
Once your implementation of the Query Builder is fully operational, it is time to connect it to our platform. You need to capture the JCSDL code generated by your users working with the Query Builder, pass it on to DataSift, capture the results and send them back to the person who created the filter. Remember that you have full freedom to implement your own solution here and you have full freedom of user management. That also means it is your responsibility to write the code that glues it all together.
It is not a difficult task, but there are a few things you need to be aware of and a simple example like the one we present in this document will help you understand what is going on.
We will be building a page that lets the user construct filters using the Query Builder and see the results without having to reload the page. We need the following components:
A server connected to the internet.
An AWS EC2 micro instance will do just fine. In this example we will assume that you are running Ubuntu Linux, but the principles apply to any operating system.
Open ports 22, 80, and 8888 on your server.
If you are using the Amazon AWS EC2 service, you will need to modify the inbound rules for the security group associated with your EC2 instance. You can do that via the AWS EC2 Management Console.
$ sudo apt-get install apache2
Install PHP5 along with the Apache PHP5 module, cURL, and JSON.
$ sudo apt-get install php5 libapache2-mod-php5 php5-curl php5-json
$ sudo apachectl restart
$ sudo apt-get install python2.7
Instal the Tornado HTTP server framework.
See the TornadoWeb site for the installation instructions.
Copy our sample HTTP connector receiver code to your server.
You will find a discussion of what that code does on our HTTP connector page.
Start the HTTP connector receiver in a separate terminal window.
$ python ./connector-http-server.py
The server prints out some basic debugging information when it receives interactions from DataSift. It is a handy sanity check and that is why it make sense to start it in a separate terminal window.
Copy the Query Builder source code archive to the document root directory of your HTTP server.
In case of Apache running on Ubuntu it will be located in /var/www:
$ cd /var/www
$ sudo unzip editor-master.zip
$ sudo mv editor-master/minified jcsdl
Copy index.html to the document root.
Make sure to change the value of the yourHTTPServerURL variable to the actual URL of your server.
Copy call.php to the document root.
Change the value of httpServer to the URL that the HTTP connector receiver is listening on. Do not forget to set your DataSift username and API key. This script makes two calls to the /compile and /push/create endpoints. Do not forget to call /push/delete when you are done experimenting. You will need the ids of the Push subscription you want to delete, use /push/get to obtain them.
Copy read.php to the document root.
Load index.html into your favorite web browser.
Create a new filter.
Click Save and Preview.
Wait five seconds and the interactions you filter for should appear under the Query Builder.