Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for TonyTonyKun TonyTonyKun
December 10, 2017

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

Go (5) JAZUG / JAZUG5周年総会 の LT 資料です。

Avatar for TonyTonyKun

TonyTonyKun

December 10, 2017
Tweet

More Decks by TonyTonyKun

Other Decks in Technology

Transcript

  1. ⾃⼰紹介 • 名前 • Twitter : @TonyTonyKun(トニー) • 仕事 •

    C#で業務アプリケーションを開発しています。 • Azure と ASP.NET を使っています。 • XAML も書いたりします。 • Blog • ROMANCE DAWN for the new world • http://gooner.hateblo.jp/
  2. きっかけ • MADOSMA • この微妙な時期に Windows Phone を⽇本で発売したマウスコンピュータ の漢気に応えたかった •

    おでコン(Windows Phone ⾮公式アプリコンテスト) • 個⼈でアプリコンテストを開催すると聞いて、応援したくなった • あと、賞品もかなり豪華だった • Xamarin のライセンス • 無料で Xamarin のライセンスが取得できるらしい
  3. Azure Search • Search as a Service(検索エンジンのサービス) • 検索キーワード候補のリアルタイム表⽰ •

    この商品を買った⼈はこんな商品を買っています • この記事に関連した記事があります • ここから 5 km 以内にあるレストランを検索する • 価格体系 • Free と Standard • 2015年7⽉に、⽇本にもデプロイされた • ⻄⽇本のみ • ⽇本語の精度は、改善中?
  4. インデックスを作成 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 は、今はまだプレビュー版です。
  5. 緯度経度のデータをインポート 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 } })); } }
  6. 地理空間検索 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, }); }