|
| 1 | +package documentation.guides.rule |
| 2 | + |
| 3 | +import com.algolia.search.dsl.query |
| 4 | +import com.algolia.search.dsl.rule.rules |
| 5 | +import com.algolia.search.model.ObjectID |
| 6 | +import com.algolia.search.model.rule.Anchoring |
| 7 | +import com.algolia.search.model.rule.Pattern |
| 8 | +import documentation.index |
| 9 | +import runBlocking |
| 10 | +import kotlin.test.Ignore |
| 11 | + |
| 12 | +@Ignore |
| 13 | +class GuidePromotingHits { |
| 14 | + |
| 15 | + /** API **/ |
| 16 | + fun snippet1() { |
| 17 | + runBlocking { |
| 18 | + val rules = rules { |
| 19 | + rule( |
| 20 | + objectID = "Promote Harry Potter Box Set", |
| 21 | + conditions = conditions { |
| 22 | + condition(anchoring = Anchoring.Contains, pattern = Pattern.Literal("Harry Potter")) |
| 23 | + }, |
| 24 | + consequence = consequence( |
| 25 | + promote = promotions { |
| 26 | + +ObjectID("HP-12345")(0) |
| 27 | + } |
| 28 | + ) |
| 29 | + ) |
| 30 | + } |
| 31 | + |
| 32 | + index.saveRules(rules) |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + /** API promote some results **/ |
| 37 | + fun snippet2() { |
| 38 | + runBlocking { |
| 39 | + val rules = rules { |
| 40 | + rule( |
| 41 | + objectID = "tomato fruit", |
| 42 | + conditions = conditions { |
| 43 | + condition(anchoring = Anchoring.Contains, pattern = Pattern.Literal("tomato")) |
| 44 | + }, |
| 45 | + consequence = consequence( |
| 46 | + query = query { |
| 47 | + filters = "food_group:fruit" |
| 48 | + } |
| 49 | + ) |
| 50 | + ) |
| 51 | + } |
| 52 | + |
| 53 | + index.saveRules(rules) |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + /** API promote newest **/ |
| 58 | + fun snippet3() { |
| 59 | + runBlocking { |
| 60 | + val rules = rules { |
| 61 | + rule( |
| 62 | + objectID = "Promote-iPhone-X", |
| 63 | + conditions = conditions { |
| 64 | + condition(anchoring = Anchoring.Contains, pattern = Pattern.Literal("iPhone")) |
| 65 | + }, |
| 66 | + consequence = consequence( |
| 67 | + promote = promotions { |
| 68 | + // objectID 'iPhone-12345' ==> iPhone X (newest release) |
| 69 | + +ObjectID("iPhone-12345")(0) |
| 70 | + } |
| 71 | + ) |
| 72 | + ) |
| 73 | + } |
| 74 | + |
| 75 | + index.saveRules(rules) |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments