Skip to content

Instantly share code, notes, and snippets.

@dmitry
Created October 4, 2016 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitry/76c5b429052022506c425a2861f4dce5 to your computer and use it in GitHub Desktop.
Save dmitry/76c5b429052022506c425a2861f4dce5 to your computer and use it in GitHub Desktop.
9flats
var value = 1;
var c = days.length;
for (var i = 0; i < c; i++) {
var v = _source.minimum_stays[days[i]];
if (v && value < v) {
value = v;
}
}
if (value == 1) {
value = _source.minimum_nights
}
c >= value;
# days.map do |date|
# {
# or: [
# {
# and: [
# {
# and: days.map do |d|
# {
# bool: {
# must: {
# not: {
# exists: {
# field: "minimum_stays.#{d}"
# }
# }
# }
# }
# }
# end
# },
# {
# bool: {
# must: {
# range: {
# minimum_nights: {
# lte: days.size
# }
# }
# }
# }
# }
# ]
# },
# {
# and: [
# {
# bool: {
# must: {
# exists: {
# field: "minimum_stays.#{date}"
# }
# }
# }
# },
# {
# bool: {
# must: {
# range: {
# "minimum_stays.#{date}" => {
# lte: days.size
# }
# }
# }
# }
# }
# ]
# },
# {
# and: [
# {
# or: days.map do |d|
# {
# bool: {
# must: {
# exists: {
# field: "minimum_stays.#{d}"
# }
# }
# }
# }
# end
# },
# bool: {
# must: {
# not: {
# exists: {
# field: "minimum_stays.#{date}"
# }
# }
# }
# }
# ],
# },
# ]
# }
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment