使用地图时,收藏顺序相反,但使用mapv可以

时间:2019-02-18 15:00:04

标签: clojure

所以我从我的elasticsearch实例中获得了结果,如下所示:

{:data
 {:total 21,
  :max_score 27.479528,
  :hits
  [{:_index "statements",
    :_type "statement",
    :_id "aggregator:8888_50_1",
    :_score 27.479528,
    :_source
    {:content
     {:text "this is the only park in our city",
      :created nil,
      :author {:dgep-native true, :name "anonymous", :id 1}},
     :identifier
     {:aggregate-id "aggregator:8888", :entity-id "50", :version 1},
     :predecessors [],
     :delete-flag false,
     :references []}}
   {:_index "statements",
    :_type "statement",
    :_id "aggregator:8888_26_1",
    :_score 11.498559,
    :_source
    {:content
     {:text
      "this is based on the cats race and a little bit on the breeding",
      :created nil,
      :author {:dgep-native true, :name "anonymous", :id 1}},
     :identifier
     {:aggregate-id "aggregator:8888", :entity-id "26", :version 1},
     :predecessors [],
     :delete-flag false,
     :references []}}
   {:_index "statements",
    :_type "statement",
    :_id "aggregator:8888_52_1",
    :_score 10.234065,
    :_source
    {:content
     {:text "the city is planing a new park in the upcoming month",
      :created nil,
      :author {:dgep-native true, :name "Christian", :id 3}},
     :identifier
     {:aggregate-id "aggregator:8888", :entity-id "52", :version 1},
     :predecessors [],
     :delete-flag false,
     :references []}}
   {:_index "statements",
    :_type "statement",
    :_id "aggregator:8888_57_1",
    :_score 8.616559,
    :_source
    {:content
     {:text "the police cannot patrol in the park for 24/7",
      :created nil,
      :author {:dgep-native true, :name "anonymous", :id 1}},
     :identifier
     {:aggregate-id "aggregator:8888", :entity-id "57", :version 1},
     :predecessors [],
     :delete-flag false,
     :references []}}
   {:_index "statements",
    :_type "statement",
    :_id "aggregator:8888_56_1",
    :_score 8.005469,
    :_source
    {:content
     {:text "the rate of non-swimmers is too high",
      :created nil,
      :author {:dgep-native true, :name "anonymous", :id 1}},
     :identifier
     {:aggregate-id "aggregator:8888", :entity-id "56", :version 1},
     :predecessors [],
     :delete-flag false,
     :references []}}
   {:_index "statements",
    :_type "statement",
    :_id "aggregator:8888_29_1",
    :_score 7.8948164,
    :_source
    {:content
     {:text "this is just a claim without any justification",
      :created nil,
      :author {:dgep-native true, :name "anonymous", :id 1}},
     :identifier
     {:aggregate-id "aggregator:8888", :entity-id "29", :version 1},
     :predecessors [],
     :delete-flag false,
     :references []}}
   {:_index "statements",
    :_type "statement",
    :_id "aggregator:8888_24_1",
    :_score 5.9939632,
    :_source
    {:content
     {:text
      "the fact, that cats are capricious, is based on the cats race",
      :created nil,
      :author {:dgep-native true, :name "anonymous", :id 1}},
     :identifier
     {:aggregate-id "aggregator:8888", :entity-id "24", :version 1},
     :predecessors [],
     :delete-flag false,
     :references []}}
   {:_index "statements",
    :_type "statement",
    :_id "aggregator:8888_8_1",
    :_score 5.77637,
    :_source
    {:content
     {:text
      "you have to take the dog for a walk every day, which is tedious",
      :created nil,
      :author {:dgep-native true, :name "anonymous", :id 1}},
     :identifier
     {:aggregate-id "aggregator:8888", :entity-id "8", :version 1},
     :predecessors [],
     :delete-flag false,
     :references []}}
   {:_index "statements",
    :_type "statement",
    :_id "aggregator:8888_49_1",
    :_score 4.9624176,
    :_source
    {:content
     {:text "the number of police patrols has been increased recently",
      :created nil,
      :author {:dgep-native true, :name "anonymous", :id 1}},
     :identifier
     {:aggregate-id "aggregator:8888", :entity-id "49", :version 1},
     :predecessors [],
     :delete-flag false,
     :references []}}
   {:_index "statements",
    :_type "statement",
    :_id "aggregator:8888_37_1",
    :_score 3.8809054,
    :_source
    {:content
     {:text "we should shut down University Park",
      :created nil,
      :author {:dgep-native true, :name "Christian", :id 3}},
     :identifier
     {:aggregate-id "aggregator:8888", :entity-id "37", :version 1},
     :predecessors [],
     :delete-flag false,
     :references []}}]},
 :status :ok,
 :message "21 hit(s)"}

然后我最终通过剥离了不需要的信息 result (get-in response [:data :hits])

这给了我所有结果,仍然是有序的。

现在,我使用(map :_source res),所有元素的顺序都相反。 如果我使用(mapv :_source res),一切都很好。

我想念什么?当我尝试使用repl中的简单示例重现行为时,一切都按预期工作。


编辑:我在REPL中尝试了相同的数据。在那里,它按预期工作。 我的应用程序唯一要做的就是传递要呈现的数据。因此,可能是渲染和Lazyseq出现了问题,从而导致了该错误。


Edit2:

这似乎是由于compojure.api库中的错误所致。 (https://github.com/metosin/compojure-api/issues/412)我现在将结束问题。

0 个答案:

没有答案