我在使用 lucene 查询大于某个值的值时遇到问题。我的数据是动态的,所以 Linq 不是一个选项。
简而言之,问题是当我使用 WhereGreaterThan 进行查询时,即使我的 Asset.Data 的价格大于价值,我也得到零结果。这也适用于 WhereGreaterThanOrEquals、WhereLessThan 和 WhereLessThanOrEquals。
public class AssetDataSearch : AbstractIndexCreationTask<Asset>
{
public AssetDataSearch()
{
Map = (docs) =>
from d in docs
select new
{
DataType = d.DataType,
_ = d.SearchableParameters.Select(s => CreateField(s.Key, s.Value))
};
}
}
public class Test
{
public void TestMethod()
{
var assets = new []
{
new Asset()
{
ID = Guid.NewGuid().ToString(),
Data = new ListingData()
{
Beds = 5,
Baths = 5,
ListingType = ListingTypeEnum.Condo,
Price = 100
}
},
new Asset()
{
ID = Guid.NewGuid().ToString(),
Data = new ListingData()
{
LotSize = 55,
SqFeet = 89,
YearBuilt = 1965,
Price = 200
}
},
};
RavenHelper.InitTestingStore();
using (var session = RavenDB.RavenUtility.OpenSession())
{
foreach(var a in assets)
session.Store(a);
session.SaveChanges();
var assetsInDb = session.Advanced.LuceneQuery<Asset>().WaitForNonStaleResults().ToArray();
var n = session.Advanced.LuceneQuery<Asset, AssetDataSearch>().WhereEquals("Price", 100).ToArray(); // returns expected results
var gt = session.Advanced.LuceneQuery<Asset, AssetDataSearch>().WhereGreaterThan("Price", 60).ToArray(); // returns nothing
var lt = session.Advanced.LuceneQuery<Asset, AssetDataSearch>().WhereLessThan("Price", 60).ToArray(); // returns nothing
}
}
}
我究竟做错了什么?