【发布时间】:2016-09-14 21:01:28
【问题描述】:
我正在使用 Xamarin 6.1 开发适用于 iOS 和 Android 的应用,并且我正在使用 Xamarin.Forms 2.3.1 该应用程序使用包含 Guid Id 的 ZXing.Net.Mobile.Forms 2.1.4 扫描 QR,并将其作为字符串保存到我的 ElasticSearch 中。要连接 ElasticSearch,我使用的是 NEST 2.x
问题是,当我再次扫描相同的 QR 时(当我确定它已经被索引时)它被检测为新的,即使值相同(都作为字符串比较)。但是,我尝试在存储或比较它们之前从 id 中删除破折号( - )并且它可以工作。
这是我的模型:
public class Box
{
[String(Analyzer = "null")]
public string id { get; set; }
public string lastUpdate { get; set; }
}
result.Text 是我从 QR 得到的,我确定这是一个字符串,这就是我索引它的方式:
scannedQR = result.Text;
// INDEXING
var timeStamp = GetTimestamp(DateTime.Now);
var customBox = new Box {
id= scannedQR,
lastUpdate = timeStamp
};
var res = client.Index(customBox, p => p
.Index("airstorage")
.Type("boxes")
.Id(scannedQR)
.Refresh()
);
这就是我检查 QR 是否已经存在的方式:
var resSearch = client.Search<Box>(s => s
.Index("airstorage")
.Type("boxes")
.From(0)
.Size(10)
.Query(q => q
.Term(p => p.id, scannedQR)
)
);
if (resSearch.Documents.Count() > 0) {
Console.WriteLine("EXISTING");
}
else {
Console.WriteLine("NEW BOX");
}
按照here 中的建议创建它时,我还尝试将属性设置为 .NotAnalyse 到 ElasticSearch 中的索引,但仍然不起作用。
有人知道吗?欢迎一切!
谢谢!
【问题讨论】:
标签: elasticsearch xamarin xamarin.forms cross-platform nest