First, enable the Cloud Search Service.
Go to NHN Cloud Console and click Select Service.
Click Cloud Search.
Do as follows to check if service is enabled:
Services can be created as follows:
Enter Service ID on Create Services.
Click Save.
Check the result of service creation.
Fields can be added as follows:
Click Set Fields.
Click Add Fields.
Enter field name.
Click Save.
Do as follows to create and index files.
Create Index Files
[
{
"action": "add",
"id": "id-1",
"fields": {
"title": "[Free Shipping] 195 types of Nike shoes!!",
"body":"The one and only Nike shoes are best selling for good reasons. Nike's 195 Hot-selling shoes★ Guess you need at least one pair of them??"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"title": "[Super Low Prices]109 types of Nike shoes",
"body": "Just 7-day Opportunities! [Super Low Prices] for 109 types of Addidas shoes. Hesiation only pushes early sold-out"
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"title": "[Addidas] 114 types of new sneakers/slides",
"body": "[Collection of Addidas Shoes ♥] Free Shipping [Addidas] Get 114 types of new slides/Superstar Stan Smith/Tubular and more!"
}
}
]
How to Indexing
Click Indexing.
Click Select File.
Select a file to indexing.
Click Open.
Indexing command comes as REST API.
Click Indexing.
Check indexing results.
REST API
REST APIs are available like below:
curl -XPOST 'https://api-7ab1617e2df0f1d1-search.cloud.toast.com/indexing/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/indexing' -H 'Accept-Language:en' -H 'Content-Type:multipart/form-data; charset=UTF-8' -F 'file=@documents.json'
curl -XPOST 'https://api-7ab1617e2df0f1d1-search.cloud.toast.com/indexing/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/indexing' -H 'Accept-Language:en' -H 'Content-Type:application/json; charset=UTF-8' -d '
[
{
"action": "add",
"id": "id-1",
"fields": {
"title": "[Free Shipping] 195 types of Nike shoes!!",
"body": "The one and only Nike shoes are best selling for good reasons. Nike'\''s 195 Hot-selling shoes★ Guess you need at least one pair of them??"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"title": "[Super Low Prices]109 types of Nike shoes",
"body": "Just 7-day Opportunities! [Super Low Prices] for 109 types of Addidas shoes. Hesiation only pushes early sold-out"
}
}
]'
{
"id" : 1
}
curl -i -XGET 'https://api-7ab1617e2df0f1d1-search.cloud.toast.com/indexing/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/indexing_log?id=1' -H 'Accept-Language:en'
{
"request_time" : "2017-10-23T12:36:43",
"file_name" : "documents.json",
"file_size" : 1185,
"status" : 4
}
Do as follows to search:
Click Search.
Check field name to search.
Set weighted value for each field to search.
Check a field for output on the search result.
Set the length of search result.
Set the highlighted pre tag.
Set the highlighted post tag.
Specify the priority order for an output from search result.
Specify the number of search results.
Select a search operator.
Enter a word to search.
Click a search icon.
Settings from 2 to 11 come as REST API.
The search result shows.
REST API
Use REST APIs as below:
curl -G -XGET 'https://api-7ab1617e2df0f1d1-search.cloud.toast.com/search/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/search?start=1&size=10&q_option=and,body*1.0,title*1.0&return=&passage.body=180&passage.title=180' --data-urlencode q='Nike shoes' --data-urlencode highlight='<b>,</b>' -H 'Accept-Language:en'
{
"message" : {
"meta" : {
"timezone" : "+09:00"
},
"result" : {
"status" : {
"code" : 200,
"message" : "OK"
},
"query" : "Nike shoes",
"start" : 1,
"itemCount" : 1,
"total" : 1,
"itemList" : {
"item" : [
{
"_RELEVANCE" : 0.15993541,
"_RANK" : 1,
"_ID" : "id-1",
"title" : "[Free Shipping] 195 types of <b>Nike</b> <b>shoes</b>!!",
"body" : "The one and only <b>Nike</b> <b>shoes</b> are best selling for good reasonsreasons. Nike's 195 Hot-selling <b>shoes</b>★ Guess you need at least one"
},
{
"_RELEVANCE" : 0.07575758,
"_RANK" : 2,
"_ID" : "id-2",
"title" : "[Super Low Prices]109 types of <b>Nike</b> <b>shoes</b>",
"body" : "Prices] for 109 types of Addidas <b>shoes</b>. Hesiation only pushes early"
}
]
}
}
}
}
Do as follows to check statistics:
Click Statistics.
Select Total Query Count or Query Count with No Results.
Enter start date.
Enter end date.
Click Query and statistical graph comes as output.
Click Download Data to download statistical data for each query.
Select Total Document Count or Total Index Size.
Enter start date.
Enter end date.
Click Query and statistical graph comes as output.
REST API
curl -i -XGET 'http://api-7ab1617e2df0f1d1-search.cloud.toast.com/stats/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/stats?kind=total_query_count&date=2020-03-09' -H 'Accept-Language:en'
[ [ "Nike", 8 ], [ "Addidas", 4 ] ]
IPs may be restricted for equipment which may call index and search REST APIs.
How to Set ACL
The example regards to setting which allows indexing only when the IP address is 202.179.177.21, while search requests are available from all IPs.
Click ACL.
Enter IP address for Enable below Indexing.
Enter 'all' for Enable Statistics.
Enter 'all ' for Enable Search.
Click Save.
Do as follows to delete fields:
Editing is not supported. To edit, delete a field and add again.
Set Fields
Indexing
To test, index request data as below:
[
{
"action": "add",
"id": "id-1",
"fields": {
"name" : "Nike Air Max",
"category" : 1
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name" : "Nike Cheyenne Solid",
"category" : 2
}
}
]
Search
Enter filtering values like below:
Set Fields
Indexing
To test, index data as below:
[
{
"action": "add",
"id": "id-1",
"fields": {
"name" : "FX Math Academy",
"location" : [10.1, 10.1]
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name" : "Tree Thinking Math Academy",
"location" : [10.3, 10.4]
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"name" : "Morning of Math Academy",
"location" : [10.4, 10.3]
}
}
]
Search
Set Fields
Indexing
To test, index data as below:
[
{
"action": "add",
"id": "id-1",
"fields": {
"name" : "Nike Air Max",
"popular" : 10,
"price" : 84180
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name" : "Nike Air Zoom",
"popular" : 5,
"price" : 97200
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"name" : "Nike Air Force",
"popular" : 5,
"price" : 74680
}
}
]
Search
Specify the sorting type.
Specify the sorting order.
Set Fields
Indexing
To test, index data as below:
[
{
"action": "add",
"id": "id-1",
"fields": {
"name" : "Nike Air Max",
"category" : "Shoes"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"name" : "Nike Air Zoom",
"category" : "Shoes"
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"name" : "Nike Swoosh short sleeve t-shirt",
"category" : "Clothing"
}
}
]
Search
Summary Result
"summary": {
"category": {
"Shoes": 2,
"Clothing": 1
}
}
Set Fields
Indexing
To test, index data as below:
[
{
"action": "add",
"id": "id-1",
"fields": {
"title" : "Nike Shoes"
}
},
{
"action": "add",
"id": "id-2",
"fields": {
"title" : "Nike Shoes"
}
},
{
"action": "add",
"id": "id-3",
"fields": {
"title" : "Nike Bags"
}
}
]
Search
Select 'boolean'.
Enter boolean query by using &, |, (, ), or !.
Set Fields
Indexing
To test, index data as below:
[
{
"action": "add",
"id": "id-1",
"weight": 0.1,
"fields": {
"title" : "Nike"
}
},
{
"action": "add",
"id": "id-2",
"weight": 0.9,
"fields": {
"title" : "Nike"
}
}
]
Search
Search Results
"itemList": {
"item": [
{
"_RELEVANCE": 0.45151517,
"_RANK": 1,
"_ID": "id-2",
"title": "<b>Nike</b>"
},
{
"_RELEVANCE": 0.18484849,
"_RANK": 2,
"_ID": "id-1",
"title": "<b>Nike</b>"
}
]
}
Adjust Weight Ratio
curl -G -XGET 'https://api-7ab1617e2df0f1d1-search.cloud.toast.com/search/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/search?start=1&size=10&q_option=and,title*1.0&return=&passage.title=180&doc_weight_ratio=0.1' --data-urlencode q='Nike' --data-urlencode highlight='<b>,</b>' -H 'Accept-Language:en'
Adjust Similarity Ratio Between User-input Search Word and Document
curl -G -XGET 'https://api-7ab1617e2df0f1d1-search.cloud.toast.com/search/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/search?start=1&size=10&q_option=and,title*1.0&return=&passage.title=180&similarity_ratio=0.1' --data-urlencode q='Nike' --data-urlencode highlight='<b>,</b>' -H 'Accept-Language:en'
Tip
Set Fields
Indexing
To test, index data as below:
[
{
"action": "add",
"id": "id-1",
"ranking": 2,
"fields": {
"title" : "Nike"
}
},
{
"action": "add",
"id": "id-2",
"ranking": 1,
"fields": {
"title" : "Nike"
}
}
]
Search
Search Results
"itemList": {
"item": [
{
"_RELEVANCE": 10000.151,
"_RANK": 1,
"_ID": "id-2",
"title": "<b>Nike</b>"
},
{
"_RELEVANCE": 9999.151,
"_RANK": 2,
"_ID": "id-1",
"title": "<b>Nike</b>"
}
]
}
Download Setting
Upload Setting
To re-index the entire data, use Full Indexing API.
curl -i -XPOST 'http://api-7ab1617e2df0f1d1-search.cloud.toast.com/indexing/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/indexing/full/begin'
curl -XPOST 'http://api-7ab1617e2df0f1d1-search.cloud.toast.com/indexing/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/indexing/full' -H 'Content-Type:multipart/form-data; charset=UTF-8' -F 'file=@documents-001.json'
curl -i -XPOST 'http://api-7ab1617e2df0f1d1-search.cloud.toast.com/indexing/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/indexing/full/end'
curl -i -XPOST 'http://api-7ab1617e2df0f1d1-search.cloud.toast.com/indexing/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/indexing/full/cancel'
Field type can be selected like below.
Morpheme analyzer can be selected as below:
ACL can be set on the below page:
Following shows the file-uploading type index example codes.
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.6'
package com.toast.cloud.cloudsearch.client;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
public class IndexingClient {
public static void main(String[] args) throws IOException {
String documents = ""
+ "[\n"
+ " {\n"
+ " \"action\": \"add\",\n"
+ " \"id\": \"id-1\",\n"
+ " \"fields\": {\n"
+ " \"title\": \"[Free Shipping]195 types of Nike shoes!!\",\n"
+ " \"body\": \"The one and only Nike shoes are best selling for good reasons. Nike's 195 Hot-selling shoes★ Guess you need at least one pair of them??"\"\n"
+ " }\n"
+ " }\n"
+ "]";
File tempFile = File.createTempFile("documents-",".json", new File("/tmp/"));
tempFile.deleteOnExit();
PrintWriter printWriter = new PrintWriter(tempFile);
printWriter.println(documents);
printWriter.close();
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
// build multipart upload request.
HttpEntity data = MultipartEntityBuilder.create()
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
.addBinaryBody("file", tempFile, ContentType.DEFAULT_BINARY, tempFile.getName())
.build();
// build http request and assign multipart upload data.
HttpUriRequest request = RequestBuilder
.post("https://api-7ab1617e2df0f1d1-search.cloud.toast.com/indexing/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/indexing")
.setEntity(data)
.build();
System.out.println("Executing request " + request.getRequestLine());
// Create a custom response handler.
ResponseHandler<String> responseHandler = response -> {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
} else {
throw new ClientProtocolException("Unexpected response status: " + status);
}
};
String responseBody = httpclient.execute(request, responseHandler);
System.out.println(responseBody);
}
}
}
<?php
$documents = ""
. "[\n"
. " {\n"
. " \"action\": \"add\",\n"
. " \"id\": \"id-1\",\n"
. " \"fields\": {\n"
. " \"title\": \"[Free Shipping]195 types of Nike shoes!!\",\n"
. " \"body\": \"The one and only Nike shoes are best selling for good reasons. Nike's 195 Hot-selling shoes★ Guess you need at least one pair of them??"\"\n"
. " }\n"
. " }\n"
. "]";
$file = DIRECTORY_SEPARATOR.trim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.ltrim("documents.json", DIRECTORY_SEPARATOR);
file_put_contents($file, $documents);
register_shutdown_function(function() use($file) {
unlink($file);
});
$data = array(
'file' => curl_file_create($file, "application/json", basename($file))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api-7ab1617e2df0f1d1-search.cloud.toast.com/indexing/v1.0/appkeys/EMKPutYozUttWVY2/serviceids/test/indexing");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data; charset=UTF-8"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch) or die(curl_error($ch));
print_r($response);
curl_close($ch);
?>