Sitecore + Lucene + QueryOccurance.不应返回期望的结果 [英] Sitecore + Lucene + QueryOccurance.Should not returning desired results
问题描述
我正在使用Alex Shybas Advanced DatabaseCrawler,它的运行非常漂亮...几乎... 我正在使用汽车销售应用程序,您可以在其中使用以下值搜索汽车
I Am using Alex Shybas Advanced DatabaseCrawler and it is working beautifully... almost... I Am using for a carsales application in which you can search for a car using the following values
型号 制作 汽油 里程 价格 年份(注册日期)
Model Make Fuel Mileage Price Year (Registration date)
我有多个NumericRange查询:
I have multiple NumericRange queryies:
- -1000-0(这是针对那些不希望在线价格的经销商.他们将价格写为-1)
- 自下而上,即. (10000-20000)这就是我要排序的依据
它们都在同一个NumericRangeSearchParam()中,请参见下面的代码. 问题出在Sitecore.Search.QueryOccurance.Such上,因为它使lucene完全无视价格限制.即
The are both in the same NumericRangeSearchParam() see code below. The problem is with the Sitecore.Search.QueryOccurance.Should as it makes lucene completely disregard the price limit. ie
我将在下面尝试说明返回的价格
I'll try to illustrate below with the prices returned
下限:1000 上限:2000
Bottom limit: 1000 Top limit: 2000
应 -1, 500, 1000, 25000
With Should -1, 500, 1000, 25000
必须 一无所获
是否应该只出现-1和1000?
Should i not be getting only -1 and 1000 with the should occurance?
我希望你们中的一个能帮助我,因为这使我发疯了!
I Hope one of you can help as this is driving me mad!
下面的代码:
public List<SkinnyItem> DoSearch(CarSearchParameters parameters, string sortby, bool reverse, string indexName)
{
Database db = Sitecore.Context.Database;
string id = db.GetItem(SitecoreHelper.GetBilSalgsItem().Paths.FullPath+"/"+ Helpers.URLEncoder.ToFriendlyUrl(parameters.Make) + (!string.IsNullOrEmpty(parameters.Model) ? "/" + Helpers.URLEncoder.ToFriendlyUrl(parameters.Model) : ""), LanguageManager.GetLanguage("da")).ID.ToString();
var param = new CombinedSearchParam()
{
FullTextQuery = "",
Language = "da",
LocationIds = id,
RelatedIds = "",
ShowAllVersions = false,
TemplateIds = ""
};
Item settings = Helpers.SitecoreHelper.GetSettings();
Sitecore.SharedSource.Search.Searcher searcher = new Sitecore.SharedSource.Search.Searcher(indexName);
var items = new List<SkinnyItem>();
//Tilføjer felter med værdier -Make -Model -Trim
var fields = new FieldValueSearchParam();
fields.Refinements.Add("Make", parameters.Make);
fields.Occurance = Sitecore.Search.QueryOccurance.Must;
if(parameters.Model != string.Empty)
fields.Refinements.Add("Model", parameters.Model);
if(parameters.Fuel != string.Empty)
fields.Refinements.Add("Fuel", parameters.Fuel);
//Tilføjer Numeriske ranges
var km = new NumericRangeSearchParam();
km.Ranges.Add(new NumericRangeSearchParam.NumericRangeField("KM", 0, parameters.MaxKM));
//Angivet som must fordi at den skal være mellem disse værdier
km.Occurance = Sitecore.Search.QueryOccurance.Must;
//Tilføjer 2 Ranges da bilen enten skal være mellem det valge range eller mindre end 0
var price = new NumericRangeSearchParam();
price.Ranges.Add(new NumericRangeSearchParam.NumericRangeField("Price", -1000, 0));
price.Ranges.Add(new NumericRangeSearchParam.NumericRangeField("Price", parameters.StartPrice, parameters.EndPrice));
//Should da den bare skal være en af dem (Svarer til ||, OR)
price.Occurance = Sitecore.Search.QueryOccurance.Should;
//Tilføjer datointervallet
var dates = new DateRangeSearchParam();
dates.Ranges.Add(new DateRangeSearchParam.DateRangeField("ModelDate", new DateTime(parameters.StartYear, 1, 1, 0, 0, 0), new DateTime(parameters.EndYear,12, 31, 23, 59, 59)));
dates.Occurance = Sitecore.Search.QueryOccurance.Must;
param.DateRanges.Add(dates);
param.NumericRanges.Add(price);
param.NumericRanges.Add(km);
param.FieldValues.Add(fields);
//Checker om der er angivet sortering
if (sortby != null)
items.AddRange(searcher.GetItems(param, new Sort(new SortField(sortby, reverse))));
else
items.AddRange(searcher.GetItems(param));
return items;
}
推荐答案
似乎Sitecore实现Lucene的方式存在错误,这就是我的查询采用这种方式的原因.
It seems there is a bug in the way that Sitecore implements Lucene, which is why my query is behaving this way.
这篇关于Sitecore + Lucene + QueryOccurance.不应返回期望的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!