I'm creating a search functionality for my website and I'm using Parse.com for storing data. I have a class Posts with a "plainContent" column which stores the content of my article in plain text format. I've found this article:
http://blog.parse.com/learn/engineering/implementing-scalable-search-on-a-nosql-backend/
which is very useful. I've added the cloud code which splits my plain text into single words and puts them into an array. Now I have my Posts with an extra column "words" which stores an array with all the single words for article's content. I got the the step of retrieving data now but the problem is the following code:
curl -v -X GET
-H "X-Parse-Application-Id: ${APPLICATION_ID}"
-H "X-Parse-REST-API-Key: ${REST_API_KEY}"
-G
--data-urlencode 'where={"hashtags":{"$all":["#parse", "#ftw"]}}'
"https://api.parse.com/1/classes/Post"
precisely the --data-urlencode row which in my case would be:
--data-urlencode 'where={"words":{"$all":["word1", "word2"]}}'
I can't create the curl query with PHP. What exactly is the $all variable in the example? Here's my php script:
$url = 'https://api.parse.com/1/classes/Posts?';
$headers = array(
"Content-Type: application/json",
"X-Parse-Application-Id: " . $MyApplicationId,
"X-Parse-REST-API-Key: " . $MyParseRestAPIKey
);
$query = urlencode('where={"words":{"$all":["parseobjectcontains", "compatible"]}}');
$ch = curl_init($url.$query);
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($handle);
curl_close($handle);
$array = json_decode($data);
var_dump($array);
This script returns all results without filtering.
The question is how to build this sentence to reflect the example in the article from the link? What should be that $all variable?
$query = urlencode('where={"words":{"$all":["parseobjectcontains", "compatible"]}}');
EDIT
I had an error in my script:
$ch = curl_init($url.$query);
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
Correction:
$handle = curl_init($url.$query);
//$handle = curl_init();
//curl_setopt($handle, CURLOPT_URL, $url);
$allis not a php variable, its just a string with a dollar sign in it, used as part of the query syntax for mongodb