Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

RealEstateMapper.cs 1.6 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  1. namespace RealEstateBot
  2. {
  3. using System.Linq;
  4. using Microsoft.Azure.Search.Models;
  5. using Search.Azure.Services;
  6. using Search.Models;
  7. public class RealEstateMapper : IMapper<DocumentSearchResult, GenericSearchResult>
  8. {
  9. public GenericSearchResult Map(DocumentSearchResult documentSearchResult)
  10. {
  11. var searchResult = new GenericSearchResult();
  12. searchResult.Results = documentSearchResult.Results.Select(r => ToSearchHit(r)).ToList();
  13. searchResult.Facets = documentSearchResult.Facets?.ToDictionary(kv => kv.Key, kv => kv.Value.Select(f => ToFacet(f)));
  14. return searchResult;
  15. }
  16. private static GenericFacet ToFacet(FacetResult facetResult)
  17. {
  18. return new GenericFacet
  19. {
  20. Value = facetResult.Value,
  21. Count = facetResult.Count.Value
  22. };
  23. }
  24. private static SearchHit ToSearchHit(SearchResult hit)
  25. {
  26. return new SearchHit
  27. {
  28. Key = (string)hit.Document["listingId"],
  29. Title = GetTitleForItem(hit),
  30. PictureUrl = (string)hit.Document["thumbnail"],
  31. Description = (string)hit.Document["description"]
  32. };
  33. }
  34. private static string GetTitleForItem(SearchResult result)
  35. {
  36. var beds = result.Document["beds"];
  37. var baths = result.Document["baths"];
  38. var city = result.Document["city"];
  39. var price = result.Document["price"];
  40. return $"{beds} bedroom, {baths} bath in {city}, ${price:#,0}";
  41. }
  42. }
  43. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...