Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andrew Bright 84 posts 244 karma points
    Mar 09, 2017 @ 13:23
    Andrew Bright
    0

    Price searching

    How do I get this to work for price searching I have followed the demo at:

    https://github.com/base33/LinqToExamine-Demo

    and have changed to date from - to fields to price and trying to search on :

    PriceFrom = 180000 - PriceTo = 200000

    But just receiving this error:

    Encountered " "TO" "TO "" at line 1, column 36. Was expecting one of:

    can you please advise.

  • Craig Noble 41 posts 584 karma points c-trib
    Mar 10, 2017 @ 00:01
    Craig Noble
    0

    Hi Andrew,

    I haven't been able to check, but is there a IsWithinRange method or something along them lines on the decimal?

    I think it might be an extension. If not, I'll add it in

    Thanks!

    Craig

  • Andrew Bright 84 posts 244 karma points
    Mar 10, 2017 @ 18:26
    Andrew Bright
    0

    Hi Craig,

    Thanks for coming back it has to be int values to work anyway so managed to get to working but have strange result:

    Updated Models:

    public int PriceFrom { get; set; }
    public int PriceTo { get; set; }
    
    public PatientListSearchModel()
    {
        Query = "";
        DOBFrom = null;
        DOBTo = null;
        UKCitizenOnly = false;
        PriceFrom = 0;
        PriceTo = 0;
    }
    
        [Field("price")]
        public int Price { get; set; }
    
        [Field("createDate")]
        public DateTime CreatedDate { get; set; }
    
        public PatientQueryModel()
        {
    
        }
    
        public PatientQueryModel(IPublishedContent content)
        {
            FirstName = content.GetPropertyValue<string>("firstName");
            LastName = content.GetPropertyValue<string>("lastName");
            Title = content.GetPropertyValue<string>("title");
            Gender = content.GetPropertyValue<string>("gender");
            Email = content.GetPropertyValue<string>("email");
            DateOfBirth = content.GetPropertyValue<DateTime>("dateOfBirth");
            IsUKCitizen = content.GetPropertyValue<bool>("isUKCitizen");
            Price = content.GetPropertyValue<int>("price");
        }
    
    if (Model.PriceFrom > 0)
    {
        indexQuery = indexQuery.Where(p => p.Price > Model.PriceFrom);
    }
    

    Added the following prices: Price 29950 200000 250000

    Yet when performing a search and setting the PriceFrom = 200000 for some reason 29950 is included in the results??

    Can you advise on this please.

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Mar 10, 2017 @ 23:48
    Robert Foster
    0

    Hi Andrew,

    It's quite likely due to the way Examine indexes and compares the fields - effectively, when you compare numeric ranges, you must format them as a string with leading zeros so that the length (number of characters) is identical. This is because Lucene (which Examine is based on) index sorting is done lexicographically. See http://stackoverflow.com/a/6810681/2843504 for an explanation.

    So what you probably want to do, is format your prices like this:

    indexQuery = indexQuery.Where(p => p.Price.ToString("00000000") > Model.PriceFrom.ToString("00000000"));
    

    Hope this helps!

    Rob.

  • Andrew Bright 84 posts 244 karma points
    Mar 11, 2017 @ 09:40
    Andrew Bright
    0

    Hi Robert,

    Thanks for coming back to me afraid it wont allow me to compare strings this way however I was aware that padding needs to be applied I am using:

     IBooleanOperation Range(string fieldName, int start, int end);
     IBooleanOperation Range(string fieldName, int start, int end, bool includeLower, bool includeUpper);
     IBooleanOperation Range(string fieldName, string start, string end);
     IBooleanOperation Range(string fieldName, string start, string end, bool includeLower, bool includeUpper);
    

    And have tried various implementations :

    query.And().Range("price", model.MinPrice.ToString("00000000"), model.MaxPrice.ToString("00000000"));

    no results

    query.And().Range("price", model.MinPrice.ToString("D6"), model.MaxPrice.ToString("D6"));
    

    no results

    query.And().Range("price", model.MinPrice.ToString(), model.MaxPrice.ToString());
    

    results but including lower values that shouldnt be there, what am I missing do I need to pad the price value somehow?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies