0

我有一个函数photos-with-keyword-starting使用 monger 从 MongoDB 实例获取给定关键字的照片列表,另一个使用set/intersection.

(defn photos-with-keywords-starting [stems]
  (apply set/intersection
         (map set
              (map photos-with-keyword-starting stems))))

以前我认为这很好用,但是由于添加了更多记录,所以交集不能按预期工作——它错过了很多同时包含两个关键字的记录。

我注意到对该函数的调用photos-with-keyword-starting总是最多返回 256 个结果:

=> (count (photos-with-keyword-starting "lisa"))
256

这是该函数的代码:

(defn photos-with-keyword-starting [stem]
  (with-db (q/find {:keywords {$regex (str "^" stem)}})
    (q/sort {:datetime 1})))

因此,如果在 MongoDB 中查找记录的调用不会返回超过 256 条记录的所有记录,因此在指定多个关键字时我没有得到正确的子集。

如何提高此限制?

4

1 回答 1

0

如果可以的话,您可以简单地将函数photos-with-keyword-starting中的日期时间转换为字符串。

或者,您可以从输出中删除逻辑重复项,例如:

(->> 
  -your-result-  
  (group-by #(update % :datetime str)) 
  (map (comp first val)))
于 2018-04-02T13:17:39.560 回答