Sitecore + Lucene + QueryOccurance.Should not returning desired results

北慕城南 提交于 2019-12-24 03:31:30

问题


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)

I have multiple NumericRange queryies:

  1. -1000 - 0 (this is for those dealers, that do not want the price online. They write the price as -1)
  2. bottom to top ie. (10000 - 20000) This is what i want to sort by

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

Bottom limit: 1000 Top limit: 2000

With Should -1, 500, 1000, 25000

With must Nothing (as expected)

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!

Code below:

    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;
    }

回答1:


I suspect it might have to do with the generated boolean logic. I'd drop a breakpoint in the searcher after it has composed its internal lucene query and take a look at the generated query value. Then look at the balancing of the parenthesis to make sure there's not a Must in the wrong place.

You can also use Luke to execute the same queries against the raw index.




回答2:


It seems there is a bug in the way that Sitecore implements Lucene, which is why my query is behaving this way.



来源:https://stackoverflow.com/questions/10384823/sitecore-lucene-queryoccurance-should-not-returning-desired-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!