range search logic