Beispiel #1
0
 /**
  * Creates a part of the elastica query class 
  * 
  * @return string Part of the elastica query class
  */
 private function elastica_create_main($data, $keys)
 {
     $query = new query();
     $output = "\t/**\n";
     $output .= "\t * The main searching function\n";
     $output .= "\t * @return resultset A Elastica Resultset Object\n";
     $output .= "\t */\n";
     $output .= "\tpublic function search()\n";
     $output .= "\t{\n";
     $json = json_encode($data);
     foreach ($keys as $key) {
         $parts = explode('|-|', $key);
         if (substr($parts[0], -6) == '_array') {
             $vals = explode('/-/', $parts[1]);
             $replacepattern = array();
             foreach ($vals as $val) {
                 if (substr($val, -1) != '$') {
                     $val .= '$';
                 }
                 $replacepattern[] = $parts[0] . '|-|' . $val;
             }
             $key = implode('","', $replacepattern);
             $json = str_replace('["' . $key . '"]', "' . json_encode(\$this->" . str_replace('$', '', $parts[0]) . ") . '", $json);
         } else {
             $json = str_replace($key, "' . \$this->" . str_replace('$', '', $parts[0]) . " . '", $json);
         }
     }
     $json = $query->prettyJson($json);
     $output .= "\t\t\$json = '{$json}';\n\n";
     $output .= "\t\t\$queryBuilder = new \\Elastica\\Query\\Builder(\$json);\n\n";
     $output .= "\t\t\$queryBuilder = new \\Elastica\\Query(\$queryBuilder->toArray());\n\n";
     $output .= "\t\t\$search = new \\Elastica\\Search(new \\Elastica\\Client());\n\n";
     $output .= "\t\treturn \$search->search(\$queryBuilder);\n";
     $output .= "\t}\n";
     return $output;
 }