I’m having an issue querying for values that are greater than a certain value with lucene. My data is dynamic, so Linq is not an option.
The problem, in short, is when I query with WhereGreaterThan I get zero results even though my Asset.Data has a price greater than a value. This applies to WhereGreaterThanOrEquals, WhereLessThan, and WhereLessThanOrEquals as well.
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
}
}
}
What am I doing wrong?
I found the answer in the Raven Google group. It turns out I have to query with the same data type as the data. So, in this case since “Price” is a decimal, I have to pass in 60M to the where clause: