通过Haskell的mongodb:如何启用文本搜索
如何在Haskell中编写以下mongodb查询通过Haskell的mongodb:如何启用文本搜索,mongodb,haskell,Mongodb,Haskell,如何在Haskell中编写以下mongodb查询 db.quotes.runCommand( "text", { search: "tomorrow", filter: { speaker : "macbeth" } } ) ,及 更新 我需要使用以下命令运行mongod: mongod --setParameter textSearchEnabled=true 我还需要为我要搜索的集合创建索引。我尝试创建一个索引,但没有成功。这是我的
db.quotes.runCommand( "text", { search: "tomorrow",
filter: { speaker : "macbeth" } } )
,及
更新
我需要使用以下命令运行mongod
:
mongod --setParameter textSearchEnabled=true
我还需要为我要搜索的集合创建索引。我尝试创建一个索引,但没有成功。这是我的新问题:
下面的代码与我的新问题无关,但我将保留在这里,因为这是我构造查询的方式
mDoc <- run pipe dbName $ runCommand
["text" =: (docTypeToText docType),
"search" =: (unwords keywords),
"filter" =: (selector $ selection query)]
case mDoc of
Left failure -> do putStrLn $ show failure
return []
Right doc -> let Array results = valueAt "results" doc
ds = [d | Doc d <- results]
in return ds
mDoc do putStrLn$显示失败
返回[]
右单据->让数组结果=在“结果”单据上的值
ds=[d | Doc d我在最近的一个项目中与MongoDB合作,我们在MongoDB的“文本”中使用了runCommand
-搜索机制。您只需使用标签和相应的值重建JSON结构。为了简化文本
-字段的使用,语言扩展重载字符串
非常方便
可以找到一个简单的定义,下面的代码显示了一个带有“real”代码的示例
唯一“棘手”的部分是文本
-字段,因为您引用的MongoDB版本中没有标签,但当您深入挖掘时,您会发现一个版本具有相应的文本
-标签,正如我在另一篇文章中引用的那样。您需要使用该命令,请参阅示例。简化@ichistmeinname的答案:
{-# LANGUAGE OverloadedStrings #-}
search col term filter = runCommand [ "text" =: col
, "search" =: term
, "filter" =: filter
]
{-# LANGUAGE OverloadedStrings #-}
search col term filter = runCommand [ "text" =: col
, "search" =: term
, "filter" =: filter
]