RangeQueryParameter change

Feb 26, 2010 at 11:52 AM

Hi,

2 changes to this. Are they acceptable?

1-

i had some problem using range queries with int values. As it happened in Lucene you must pad the string with equal char number. So i modified

RangeQueryParameter.cs, function "private void SetStartEndValues(string startvalue, string endvalue)" to:

        private void SetStartEndValues(string startvalue, string endvalue)
        {
            string start = "";
            string end = "";
            if (startvalue.StartsWith("-") && endvalue.StartsWith("-"))
            {
                start = (startvalue.CompareTo(endvalue) > 0 ? startvalue : endvalue);
                end = (startvalue.CompareTo(endvalue) > 0 ? endvalue : startvalue);
            }
            else if (endvalue.StartsWith("*"))
            {
                start = startvalue;
                end = endvalue;
            }
            else
            {
                start = (startvalue.PadLeft(15, '0').CompareTo(endvalue.PadLeft(15, '0')) > 0 ? endvalue : startvalue);
                end = (startvalue.PadLeft(15, '0').CompareTo(endvalue.PadLeft(15, '0')) > 0 ? startvalue : endvalue);
            }
            this.Value = "[" + start + " TO " + end + "]";
        }

2-

I also didn't find a way to range queries with '*'. I added a new constructor:

 public RangeQueryParameter(string field, int startvalue)
            : this(field, startvalue.ToString(), "*")
        {
        }

and the "else if" you can see in the previous function (SetStartEndValues)

BR,

Frederico

 

 

Mar 3, 2010 at 2:18 PM
Edited Mar 3, 2010 at 2:31 PM

I had the same problem, and did just like you, works fine now!

BR

Anderson

Oct 15, 2010 at 7:29 PM
Edited Oct 15, 2010 at 7:31 PM

Hi,

May you try to help me? I'm trying to implement a conceptual query sample for SolrSharp, using a query with a RangeQueryParameter for the "price" field. Is my implementation correct?

 

SolrSearcher solrSearcher = SolrSearchers.GetSearcher(Mode.Read);

Product.ProductList objProductList = new Product.ProductList();
FastQueryBuilder queryBuilder = new FastQueryBuilder(QueryText);

FastCategoryFacet catFacet = new FastCategoryFacet();
queryBuilder.AddFacet(catFacet);

queryBuilder.AddSearchParameter("price","[10 TO 100]",true);

       
FastSearchResults searchResults = new FastSearchResults(queryBuilder);

foreach (FastSearchRecord record in searchResults.SearchRecords)
{
 Product.ProductEntity product = new Product.ProductEntity();
product.SKU = record.Id;
product.Title = record.Name;
product.Price = record.Price;
objProductList.Add(product);
}
return (objProductList);