Upload
tonytonykun
View
1.249
Download
7
Embed Size (px)
Citation preview
Azure Search を使って、Windows Phone 8.1 アプリを作った話
自己紹介
• 名前• Twitter : @TonyTonyKun(トニー)
• 仕事• C#で業務アプリケーションを開発しています。
• Azure と ASP.NET を使っています。
• XAML も書いたりします。
• Blog• ROMANCE DAWN for the new world
きっかけ
•MADOSMA• この微妙な時期に Windows Phone を日本で発売したマウスコンピュータ
の漢気に応えたかった
•おでコン(Windows Phone 非公式アプリコンテスト)• 個人でアプリコンテストを開催すると聞いて、応援したくなった
• あと、賞品もかなり豪華だった
• Xamarin のライセンス• 無料で Xamarin のライセンスが取得できるらしい
アプリのネタは?
Season 5 キター!!!
こんなアプリを作りました
https://www.microsoft.com/store/apps/9NBLGGH35LZ6
DEMO
DEMO
DEMO
アーキテクチャ
Azure Search
• Search as a Service(検索エンジンのサービス)• 検索キーワード候補のリアルタイム表示
• この商品を買った人はこんな商品を買っています
• この記事に関連した記事があります
• ここから 5 km 以内にあるレストランを検索する
•価格体系• Free と Standard
• 2015年7月に、日本にもデプロイされた• 西日本のみ
• 日本語の精度は、改善中?
インデックスを作成
using (var connection = ApiConnection.Create("<Service Name>", "<API Key>"))
using (var client = new IndexManagementClient(connection))
{
var createResponse = await client.CreateIndexAsync(new Index("<Index Name>")
.WithStringField("id",
f => f.IsKey().IsSearchable().IsRetrievable())
.WithStringField("title", f => f.IsSearchable().IsRetrievable())
.WithStringField("restaurant",
f => f.IsSearchable().IsRetrievable())
.WithGeographyPointField("location",
p => p.IsFilterable().IsSortable().IsRetrievable()));
}
RedDog.Search(https://www.nuget.org/packages/RedDog.Search/)※ Microsoft Azure Search Library は、今はまだプレビュー版です。
緯度経度のデータをインポート
using (var connection = ApiConnection.Create("<Service Name>", "<API Key>"))
using (var client = new IndexManagementClient(connection))
{
var json = File.ReadAllText(@"C:¥Gourmet.json", Encoding.UTF8);
var targets = JsonConvert.DeserializeObject<List<Gourmet>>(json);
foreach (var target in targets.Select((v, i) => new { value = v, index = i }))
{
var populateResponse = await client.PopulateAsync("<Index Name>",
new IndexOperation(IndexOperationType.Upload,
"id", (target.index + 1).ToString())
.WithProperty("title", target.value.Title)
.WithProperty("restaurant", target.value.Restaurant)
.WithProperty("location", new { type = "Point",
coordinates = new[] { target.value.Location.lng, target.value.Location.lat } }));
}
}
地理空間検索
using (var connection = ApiConnection.Create("<Service Name>", "<API Key>"))
using (var client = new IndexQueryClient(connection))
{
var query = new SearchQuery()
.OrderBy(String.Format("geo.distance(location, geography'POINT({0} {1})')",
139.766084, 35.681382)).Top(10);
var response = await client.SearchAsync("<Index Name>", query);
return response.Body.Records.Select(x => new Gourmet
{
Id = int.Parse(x.Properties["id"] as string),
Season = (int)(long)x.Properties["season"],
Episode = (int)(long)x.Properties["episode"],
Title = x.Properties["title"] as string,
Restaurant = x.Properties["restaurant"] as string,
});
}
まとめ
•クラウドは、ちょっとしたアイディアを低コストで実現できます。
•日本でも Windows Phone を盛り上げていきましょう。
•これから作るなら、UWPで。
ご清聴ありがとうございました。