Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search operation, the total_count that is taken is not in conformity with the actual #69

Closed
wgclk opened this issue Apr 11, 2018 · 0 comments

Comments

@wgclk
Copy link

wgclk commented Apr 11, 2018

To do query operation, the value of total_count is not the expected result.
The following is the IEX operation:

iex(4)rummage = %{
...(4)>       search: %{name:  %{search_type: :like, search_term: "c"}},
...(4)>       sort: %{field: :name, order: :asc},
...(4)>       paginate: %{page: 1}
...(4)>     }
%{paginate: %{page: 1},
search: %{name: %{search_term: "c", search_type: :like}},
sort: %{field: :name, order: :asc}}

iex(5)> {queryable, rummage} = ZergApi.Base.Exchange.rummage(rummage)
[debug] QUERY OK source="exchanges" db=0.1ms
SELECT count(DISTINCT e0.`id`) FROM `exchanges` AS e0 []
{#Ecto.Query<from e in subquery(from e in subquery(from e in ZergApi.Base.Exchange),
where: like(e.name, ^"%c%")),
order_by: [asc: e.name], limit: ^10, offset: ^0>,
%{paginate: %{max_page: 1, page: 1, per_page: 10, total_count: 10},
 search: %{name: %{assoc: [], search_expr: :where, search_term: "c",
     search_type: :like}},
 sort: %{assoc: [], field: :name, order: :asc}}}

To do query operation, the value of total_countde is not the expected result.
The following is the IEX operation
There are ten pieces of data in this table. After the search operation, three data should be returned, that is, total_count=3, and the actually returned total_count =10, and the following is the actual data.
and the following is the actual data

iex(6)> exchanges = queryable |> ZergApi.Repo.all
[debug] QUERY OK db=0.4ms
SELECT s0.`id`, s0.`name`, s0.`cn_name`, s0.`home_page`, s0.`timezone`, s0.`inserted_at`, s0.`updated_at` FROM (SELECT s0.`id` AS `id`, s0.`name` AS `name`, s0.`cn_name` AS `cn_name`, s0.`home_page` AS `home_page`, s0.`timezone` AS `timezone`, s0.`inserted_at` AS `inserted_at`, s0.`updated_at` AS `updated_at` FROM (SELECT e0.`id` AS `id`, e0.`name` AS `name`, e0.`cn_name` AS `cn_name`, e0.`home_page` AS `home_page`, e0.`timezone` AS `timezone`, e0.`inserted_at` AS `inserted_at`, e0.`updated_at` AS `updated_at` FROM `exchanges` AS e0) AS s0 WHERE (s0.`name` LIKE ?)) AS s0 ORDER BY s0.`name` LIMIT ? OFFSET ? ["%c%", 10, 0]
[%ZergApi.Base.Exchange{__meta__: #Ecto.Schema.Metadata<:loaded, "exchanges">,
  cn_name: "", home_page: "", id: 5,
  inserted_at: ~N[2018-04-10 14:02:17.000000], name: "",
  products: #Ecto.Association.NotLoaded<association :products is not loaded>,
  timezone: "Asia/Shanghai", updated_at: ~N[2018-04-10 14:02:17.000000]},
 %ZergApi.Base.Exchange{__meta__: #Ecto.Schema.Metadata<:loaded, "exchanges">,
  cn_name: "", home_page: "", id: 6,
  inserted_at: ~N[2018-04-10 14:02:17.000000], name: "",
  products: #Ecto.Association.NotLoaded<association :products is not loaded>,
  timezone: "Asia/Shanghai", updated_at: ~N[2018-04-10 14:02:17.000000]},
 %ZergApi.Base.Exchange{__meta__: #Ecto.Schema.Metadata<:loaded, "exchanges">,
  cn_name: "", home_page: "", id: 4,
  inserted_at: ~N[2018-04-10 14:02:17.000000], name: "",
  products: #Ecto.Association.NotLoaded<association :products is not loaded>,
  timezone: "Asia/Shanghai", updated_at: ~N[2018-04-10 14:02:17.000000]}]

Can you tell me how to solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants