Advertisement
Guest User

Untitled

a guest
Nov 15th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.96 KB | None | 0 0
  1.  
  2.     def add_dynamics(word, dynamic) do
  3.       dynamic([c], like(c.search_index, ^("%#{word}%")) and ^dynamic )
  4.     end
  5.  
  6.     def profile_search(map) do
  7.       pagination = if map[:pagination_clause], do: dynamic([p], p.id > ^map[:pagination_clause] ), else: true
  8.  
  9.       ###
  10.       query = Enum.reduce(String.split(map[:q]), true, fn (x,acc) -> add_dynamics(x, acc) end)
  11.       IO.inspect query
  12.       ###
  13.  
  14.  
  15.  
  16.  
  17.       birth_date_between = if map[:birth_date_between] do
  18.         [date1, date2] = map[:birth_date_between]
  19.         dynamic([p], p.birth_date > ^Tools.string_to_dbdate(date1) and p.birth_date < ^Tools.string_to_dbdate(date2) )
  20.       else
  21.         true
  22.       end
  23.  
  24.       Repo.all(from p in Alfayda.Profile,
  25.                where: ^map[:equal_clauses],
  26.                where: ^pagination,
  27.                where: ^birth_date_between,
  28.                where: ^query,
  29.                where: p.public_profile == ^true,
  30.                limit: 50 )
  31.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement