@dhruvdutt/

Appbase.io - PHP - search - date

PHP (Legacy)

Date query to get houses that are available between certain dates

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.062112586947188575","path":"main.php","file":{"path":"main.php","content":{"asEncoding":{"base64":"JGN1cmwgPSBjdXJsX2luaXQoKTsKICAKY3VybF9zZXRvcHRfYXJyYXkoJGN1cmwsIGFycmF5KAogIENVUkxPUFRfVVJMID0+ICJodHRwczovL3NjYWxyLmFwaS5hcHBiYXNlLmlvL2hvdXNpbmctZGVtby9saXN0aW5nL19zZWFyY2giLAogIENVUkxPUFRfUkVUVVJOVFJBTlNGRVIgPT4gdHJ1ZSwKICBDVVJMT1BUX0VOQ09ESU5HID0+ICIiLAogIENVUkxPUFRfTUFYUkVESVJTID0+IDEwLAogIENVUkxPUFRfVElNRU9VVCA9PiAzMCwKICBDVVJMT1BUX0hUVFBfVkVSU0lPTiA9PiBDVVJMX0hUVFBfVkVSU0lPTl8xXzEsCiAgQ1VSTE9QVF9DVVNUT01SRVFVRVNUID0+ICJQT1NUIiwKICBDVVJMT1BUX1BPU1RGSUVMRFMgPT4ganNvbl9lbmNvZGUoYXJyYXkoCiAgICAicXVlcnkiID0+IGFycmF5KAogICAgICAiYm9vbCIgPT4gYXJyYXkoCiAgICAgICAgIm11c3QiID0+IGFycmF5KAogICAgICAgICAgYXJyYXkoCiAgICAgICAgICAgICJyYW5nZSIgPT4gYXJyYXkoCiAgICAgICAgICAgICAgImRhdGVfZnJvbSIgPT4gYXJyYXkoCiAgICAgICAgICAgICAgICAiZ3QiID0+IDIwMTcwMTAxCiAgICAgICAgICAgICAgKQogICAgICAgICAgICApICAKICAgICAgICAgICksCiAgICAgICAgICBhcnJheSgKICAgICAgICAgICAgInJhbmdlIiA9PiBhcnJheSgKICAgICAgICAgICAgICAiZGF0ZV90byIgPT4gYXJyYXkoCiAgICAgICAgICAgICAgICAibHQiID0+IDIwMTcwNDMwCiAgICAgICAgICAgICAgKQogICAgICAgICAgICApICAKICAgICAgICAgICkKICAgICAgICApCiAgICAgICkgICAgIAogICAgKQogICkpLAogIENVUkxPUFRfSFRUUEhFQURFUiA9PiBhcnJheSgKICAgICJBdXRob3JpemF0aW9uOiBCYXNpYyBXVzVEWjFaM2IzcFdPbVU1WldNMVkySXdMVFU0WkRndE5HSmlNQzFpWVdSakxXRmpZV1kzTWpZMk5qRm1NUT09IiwKICAgICJDb250ZW50LVR5cGU6IGFwcGxpY2F0aW9uL2pzb24iCiAgKSwKKSk7CgokcmVzcG9uc2UgPSBjdXJsX2V4ZWMoJGN1cmwpOwokZXJyID0gY3VybF9lcnJvcigkY3VybCk7CgpjdXJsX2Nsb3NlKCRjdXJsKTsKCmlmICgkZXJyKSB7CiAgZWNobyAiY1VSTCBFcnJvciAjOiIgLiAkZXJyOwp9IGVsc2UgewogICRqc29uID0ganNvbl9kZWNvZGUoJHJlc3BvbnNlLCB0cnVlKTsKICBwcmludF9yKCJAc2VhcmNoIGhpdHM6ICIpOwogIHByaW50X3IoJGpzb25bJ2hpdHMnXVsnaGl0cyddKTsKfQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$curl = curl_init();
  
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://scalr.api.appbase.io/housing-demo/listing/_search",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode(array(
    "query" => array(
      "bool" => array(
        "must" => array(
          array(
            "range" => array(
              "date_from" => array(
                "gt" => 20170101
              )
            )  
          ),
          array(
            "range" => array(
              "date_to" => array(
                "lt" => 20170430
              )
            )  
          )
        )
      )     
    )
  )),
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic WW5DZ1Z3b3pWOmU5ZWM1Y2IwLTU4ZDgtNGJiMC1iYWRjLWFjYWY3MjY2NjFmMQ==",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  $json = json_decode($response, true);
  print_r("@search hits: ");
  print_r($json['hits']['hits']);
}
PHP 7.0.8 (Legacy: use the following for new features: Command-line PHP: https://repl.it/languages/php_cli PHP Web Server: https://repl.it/languages/php7