#!/bin/env python # -*- coding: utf-8 -*- # クラウドサーチで検索してみる習作 # boto3 編 import boto3 cloudsearchdomain = boto3.client('cloudsearchdomain', endpoint_url='http://search-hogehoge.ap-northeast-1.cloudsearch.amazonaws.com') results = cloudsearchdomain.search(query=u'夏目漱石', size=10, highlight='{"body":{"format":"html"}}') print "found:", results["hits"]["found"] for hit in results["hits"]["hit"]: print "-----------------------------------" print "id:", hit["id"] print "title:", hit["fields"]["title"][0] print "author:", hit["fields"]["author"][0] for k, v in hit["highlights"].items(): print "hightlight:", v
found: 56 ----------------------------------- id: wagahaiwa_nekodearu.txt title: 吾輩は猫である author: 夏目漱石 hightlight: 一 <em>吾輩</em>は<em>猫</em>である。 ----------------------------------- id: neko_jyo.txt title: 『吾輩は猫である』上篇自序 author: 夏目漱石 hightlight: 「<em>吾輩</em>は<em>猫</em>である」は雑誌ホトトギスに連載した続き物である。 -----------------------------------