我正在使用 Solandra 搜索某个日期之后的事件。为此,我索引自纪元以来的毫秒(作为长数据类型)并使用如下范围搜索:开始:[1348992000000 TO *]
很多时候这工作正常,但有时会出现奇怪的错误行为,即在日期 X 之后,没有任何东西被带回,但在日期 Y 之后(其中 X < Y < 日期)它被返回。
在玩了很多游戏之后,我设法想出了一些我可以持续复制的东西(至少在我这边)。以下是重新创建的步骤:
1)创建以下架构(如果您想要整个 xml 文件,请告诉我,我会发布):
<fields>
<field name="id" type="string" indexed="true" stored="true" required="true" />
<field name="title" type="text" indexed="true" stored="false"/>
<field name="start" type="slong" indexed="true" stored="false"/>
</fields>
2) 使用 SolrJ 运行以下 Java 程序:
public class IndexTest {
private static final SolrServer eventsServer = new HttpSolrServer("http://localhost:8983/solandra/events");
public static void main(String... args)
throws Exception {
save2(1350028800000L);
save2(1349424000000L);
save2(1348992000000L);
save2(1350028800000L);
save2(1350115200000L);
save2(1350374400000L);
save2(1348992000000L);
save2(1349424960000L);
save2(1349424000000L);
save1(1348992000000L);
save1(1348999200000L);
save1(1349431200000L);
save2(1349164800000L);
save2(1348992000000L);
save2(1349424000000L);
save1(1349444640000L);
save2(1350633600000L);
}
private static void save1(long time)
throws Exception {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "2ce011f0-0a80-11e2-bf94-b8f6b111caaf");
doc.addField("title", "Test");
doc.addField("start", time);
eventsServer.add(doc);
eventsServer.commit();
}
private static void save2(long time)
throws Exception {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "5d9e18f0-0a80-11e2-bf94-b8f6b111caaf");
doc.addField("title", "Test");
doc.addField("start", time);
eventsServer.add(doc);
eventsServer.commit();
}
}
3) 运行以下查询以查看没有返回结果:
q=开始:[1348992000000 TO *]
http://localhost:8983/solandra/events/select/?q=start:%5B1348992000000+TO+*%5D
4) 运行以下查询以查看返回结果:
q=开始:[1349049600177 TO *]
http://localhost:8983/solandra/events/select/?q=start:%5B1349049600177+TO+*%5D
注意事项:
删除 commit() 似乎修复了这个特定的示例,但是当在其他时间省略提交时,我目睹了它。据我从 Jake Luciani 所写的评论中了解到,commit() 应该没有任何效果,所以我很困惑为什么这种变化会一直影响结果。
它似乎只在我索引了多个事件时才会发生(但不能确定,因为问题似乎在最随机的时间出现)。
为什么我不使用数据类型日期?我最初是这样做的,但认为特定的数据类型导致了这个问题,所以切换了。尝试过数据类型 date、long、slong、string 和 text。所有都表现出相同的零星缺失结果行为。另请注意,切换到不同的数据类型可能会修复特定示例,但在其他示例中会很明显。
已尝试直接从 github 使用 Solandra 代码作为现成的 Solandra 以及嵌入到最新的 Cassandra 发行版中。
这让我发疯,所以任何帮助或建议将不胜感激!