[英]How can I combine multiple Import.io search engine connectors into one search engine with PHP?
I have PHP API codeblocks from a data extraction tool/website ( http://import.io ) in the form below. 我在下面的表单中有来自数据提取工具/网站( http://import.io )的PHP API代码块。 I want to have a search box that returns the result from not one, but multiple of these "connector" codeblocks (they are called connectors because they connect your search queries with the results piped through import.io, presumably).
我想要一个搜索框,它不是一个,而是多个这些“连接器”代码块返回结果(它们被称为连接器,因为它们将搜索查询与通过import.io传输的结果连接起来,大概是)。
I'm a noob at PHP, so I'm not sure how to go about this. 我是PHP的菜鸟,所以我不知道如何解决这个问题。
<?php
$userGuid = "kjnjkn-32d2-4b1c-a9c5-erferferferferf";
$apiKey = "APIKEY";
function query($connectorGuid, $input, $userGuid, $apiKey) {
$url = "https://api.import.io/store/connector/" . $connectorGuid . "/_query?_user=" . urlencode($userGuid) . "&_apikey=" . urlencode($apiKey);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("input" => $input)));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
}
// Query for tile WEBSEARCH
$result = query("98c9bac2-e623-4e31-8a3e-erferferferf", array(
"search_query" => "term1",
), $userGuid, $apiKey);
var_dump($result);
// Query for tile WEBSEARCH
$result = query("98c9bac2-e623-4e31-8a3e-bferfreferfe", array(
"search_query" => "term2",
), $userGuid, $apiKey);
var_dump($result);
I think the first thing you will want is some kind of HTML form that POSTs to your PHP script. 我认为你想要的第一件事就是发布到PHP脚本的某种HTML表单。 I haven't tested this but something like it will do:
我没有测试过这个,但它会做的事情:
<form action="path/to/myscript.php" method="POST">
<input type="text" name="search" placeholder="query">
<input type="submit" value="Search">
</form>
This will issue an HTTP POST request to your script (call it myscript.php or change the HTML to match your filename) with the input term in the $_POST data array . 这将向您的脚本发出HTTP POST请求(称之为myscript.php或更改HTML以匹配您的文件名)与$ _POST数据数组中的输入术语。
This means you can get the search term typed in using $_POST["search"]
, and use it as the input to the query: 这意味着您可以使用
$_POST["search"]
输入搜索词,并将其用作查询的输入:
$result = query("98c9bac2-e623-4e31-8a3e-erferferferf", array(
"search_query" => $_POST["search"],
), $userGuid, $apiKey);
var_dump($result);
Notes: 笔记:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.