15
Azure Search を使って、 Windows Phone 8.1 アプリを作った話

Azure Search を使って Windows Phone 8.1 アプリを作った話

Embed Size (px)

Citation preview

Page 1: Azure Search を使って Windows Phone 8.1 アプリを作った話

Azure Search を使って、Windows Phone 8.1 アプリを作った話

Page 2: Azure Search を使って Windows Phone 8.1 アプリを作った話

自己紹介

• 名前• Twitter : @TonyTonyKun(トニー)

• 仕事• C#で業務アプリケーションを開発しています。

• Azure と ASP.NET を使っています。

• XAML も書いたりします。

• Blog• ROMANCE DAWN for the new world

Page 3: Azure Search を使って Windows Phone 8.1 アプリを作った話

きっかけ

•MADOSMA• この微妙な時期に Windows Phone を日本で発売したマウスコンピュータ

の漢気に応えたかった

•おでコン(Windows Phone 非公式アプリコンテスト)• 個人でアプリコンテストを開催すると聞いて、応援したくなった

• あと、賞品もかなり豪華だった

• Xamarin のライセンス• 無料で Xamarin のライセンスが取得できるらしい

Page 4: Azure Search を使って Windows Phone 8.1 アプリを作った話

アプリのネタは?

Season 5 キター!!!

Page 5: Azure Search を使って Windows Phone 8.1 アプリを作った話

こんなアプリを作りました

https://www.microsoft.com/store/apps/9NBLGGH35LZ6

Page 6: Azure Search を使って Windows Phone 8.1 アプリを作った話

DEMO

Page 7: Azure Search を使って Windows Phone 8.1 アプリを作った話

DEMO

Page 8: Azure Search を使って Windows Phone 8.1 アプリを作った話

DEMO

Page 9: Azure Search を使って Windows Phone 8.1 アプリを作った話

アーキテクチャ

Page 10: Azure Search を使って Windows Phone 8.1 アプリを作った話

Azure Search

• Search as a Service(検索エンジンのサービス)• 検索キーワード候補のリアルタイム表示

• この商品を買った人はこんな商品を買っています

• この記事に関連した記事があります

• ここから 5 km 以内にあるレストランを検索する

•価格体系• Free と Standard

• 2015年7月に、日本にもデプロイされた• 西日本のみ

• 日本語の精度は、改善中?

Page 11: Azure Search を使って Windows Phone 8.1 アプリを作った話

インデックスを作成

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 は、今はまだプレビュー版です。

Page 12: Azure Search を使って Windows Phone 8.1 アプリを作った話

緯度経度のデータをインポート

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 } }));

}

}

Page 13: Azure Search を使って Windows Phone 8.1 アプリを作った話

地理空間検索

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,

});

}

Page 14: Azure Search を使って Windows Phone 8.1 アプリを作った話

まとめ

•クラウドは、ちょっとしたアイディアを低コストで実現できます。

•日本でも Windows Phone を盛り上げていきましょう。

•これから作るなら、UWPで。

Page 15: Azure Search を使って Windows Phone 8.1 アプリを作った話

ご清聴ありがとうございました。