- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
根据 Mongodb 文档 “查询不能同时使用文本和地理空间索引”
意味着我们不能同时使用 $textSearch
和 $nearSphere
在单个 Spring Data Mongo 存储库方法中。
但我正在寻找一些解决方法,它可以让我同时使用 TextCriteria
和 nearSphere Pint
,我没有别的办法,我是真的想让这个工作。
我找到了 https://groups.google.com/forum/#!msg/mongodb-user/pzlYGKMYMVQ/O6P5S578Xx0J这表示他能够执行一些解决方法,但我不明白他是如何为后续查询编写 Repository 方法的?
find({"add.loc": {$near:{$geometry: {type: "Point",coordinates:
[116.425, -31.09]}, $maxDistance: 500000}},$text:{$search: "hello"}}
我的处境很糟糕
对于我的存储库方法,它提供:
Page<User> getAddress_PositionNear(TextCriteria tc,Point gpoint, Distance d, Pageable p);
"errmsg" : "text and geoNear not allowed in same query" , "code" : 2
最佳答案
在一个查询中组合 2 个特殊索引结构(在撰写本文时)不可能使用 MongoDB。这意味着文本索引不能与地理空间索引一起使用。
$near需要对 2d 或 2dsphere 索引进行操作,因此不能与文本搜索相结合。
但是可以使用 $geoWithin不需要地理空间索引。使用 Polygon
或 Circle
来构造类似
db.text_and_geo.find({
"loc": { "$geoWithin" : { "$geometry": { "type" : "Polygon" , "coordinates": [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ] ] ] }}},
"$text" : { "$search" : "spring"}
})
db.text_and_geo.find({
"loc": { "$geoWithin": { "$center": [ [1, 1], 10 ] } } ,
"$text" : { "$search" : "spring"}
})
几乎可以通过 MongoTemplate
Query queryWithPolygon = TextQuery.queryText(TextCriteria.forDefaultLanguage()
.matching("spring"))
.addCriteria(
where("loc")
.within(new GeoJsonPolygon(new Point(0, 0), new Point(3, 6), new Point(6, 1), new Point(0, 0)));
List<TextAndGeo> result = template.find(queryWithPolygon, TextAndGeo.class);
Query queryWithCircle = TextQuery.queryText(TextCriteria.forDefaultLanguage()
.matching("spring"))
.addCriteria(
where("loc")
.within(new Circle(new Point(0, 0), 10));
List<TextAndGeo> result = template.find(queryWithCircle, TextAndGeo.class);
使用 Repository
只需为您的派生查询使用 Within
关键字
Page<TextAndGeo> findByLocWithin(Circle circle, TextCriteria tc, Pageable page)
关于mongodb - 如何使用 Spring Data MongoDB 结合文本和地理查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33156106/
我有一张 Excel 表格,用于更新玩家评分。 播放器 配售 初始化 1 2 3 4 金融评级 一个 1 2.0 1.000 0.018 0.016 0.014 2.007 D 2 -2.0 54.5
我有一个 map = std::map ,其中 myItemModel继承QAbstractItemModel . 我现在要合并所有 myItemModel合一myItemModel (其他所有元素模
我大量使用“do.call”来生成函数调用。例如: myfun <- "rnorm"; myargs <- list(n=10, mean=5); do.call(myfun, myargs); 但是
想象一下 InputStream 的以下变体: trait FutureInputStream { //read bytes asynchronously. Empty array means E
这是我的 C 代码: #include void sum(); int newAlphabet; int main(void) { sum();
我只是想选择类“.last”之后的每个元素。 HTML: 1 2 Jquery
我正在为一个项目构建一个 XML 反序列化器,我经常遇到这种类型的代码情况: var myVariable = ParseNDecimal(xml.Element("myElement")) == n
这是来自 Selecting the highest salary 的继续问题 假设有一个表 'wagetable' name lowhours highhours wage pri
我正在为我的程序创建一个战舰程序;该程序运行良好,但我试图确保当用户将坐标超出范围时,程序会说他们输入的坐标不正确。这是代码: #include #include void
我有一个函数,它为每种情况返回不同的 DWORD 值,如果出现错误。所以我有以下定义: #define ERR_NO_DB_CONNECTION 0x90000 #define ERR_DB_N
在派生类中引发基类事件以下简单示例演示了在基类中声明可从派生类引发的事件的标准方法。此模式广泛应用于 .NET Framework 类库中的 Windows 窗体类。在创建可用作其他类的基类的类时,应
我只是想知道这是否可能: use Modern::Perl; my @list = ('a' .. 'j'); map { func($_) } each(@list); sub func { m
我一直在使用 =IF(L2="","Active",IF(K2I2,"Late"))) 有效,但现在我需要检查 F 上的多个条件 专栏 我试过了 OR 函数 =IF(OR(F2="Scheduled"
我有 2 个命令,如下所示。 在视频中添加介绍图片 ffmpeg -y -loop 1 -framerate 10 -t 3 -i intro.png -i video.mp4 -filter_com
好的,我有这个公式可以根据名字和姓氏列表生成用户名。现在,虽然这可行,但我希望单元格改为引用我自己的 VBA 函数。但是,由于代码少得多,我仍然想使用原始公式。 我有这个公式: =SUBSTITUTE
我有两个 HAProxy 实例。两个实例都启用了统计信息并且工作正常。 我正在尝试将两个实例的统计信息合并为一个,以便我可以使用单个 HAProxy 来查看前端/后端统计信息。我试图让两个 hapro
我有一个 Observable,其中每个新值都应该引起一个 HTTP 请求。在客户端,我只关心最新的响应值;但是,我希望每个请求都能完成以进行监控/等。目的。 我目前拥有的是这样的: function
我的网站上有 TinyMCE 插件。在 TinyMCE 插件的 textarea 中添加图像时,我希望这些图像包含延迟加载。我网站的缩略图具有特定类型的延迟加载,其中 src 图像是灰色背景。根据用户
我希望合并润滑间隔,以便如果它们重叠,则从内部第一个时间获取最小值和从内部最后一个时间获取最大值并总结以创建一个跨越整个时间段的新间隔。这是一个reprex: library(lubridate, w
我有一个应用程序,它本质上是一个页眉、主要内容和一个始终可见的页脚。页脚可以改变大小,我想在页脚上方的主内容面板上放置一些工具。主要布局是用 flex 完成的,我阅读文档的理解是绝对定位通过相对于最近
我是一名优秀的程序员,十分优秀!