Пример #1
0
        public static ProductFTS GetProductFTS(this SqlDataReader dataReader)
        {
            var objs   = new object[dataReader.FieldCount];
            var result = dataReader.GetValues(objs);

            try
            {
                if (dataReader.FieldCount != EXP_READER_FIELDS)
                {
                    throw new Exception(dataReader.FieldCount + " fields exists in DataReader instead of " + EXP_READER_FIELDS);
                }

                var product = new ProductFTS
                {
                    Name            = dataReader.GetString(dataReader.GetOrdinal("name")),
                    Category        = dataReader.GetString(dataReader.GetOrdinal("category")),
                    ID              = dataReader.GetString(dataReader.GetOrdinal("id")),
                    RetailPrice     = dataReader.GetInt32(dataReader.GetOrdinal("retail_price")),
                    DiscountedPrice = dataReader.GetInt32(dataReader.GetOrdinal("discounted_price")),
                    Description     = dataReader.GetString(dataReader.GetOrdinal("description")),
                    ImageUrl        = dataReader["images"].GetImageUrl(),
                };

                return(product);
            }
            catch (Exception exp)
            {
                Console.WriteLine(objs[4]);
                throw exp;
            }
        }
Пример #2
0
        public static ProductFTS GetProductFTS(this Document document)
        {
            try
            {
                if (document.Fields.Count < EXP_DOC_FIELDS)
                {
                    throw new Exception(document.Fields.Count + " fields exists in DataReader instead of " + EXP_DOC_FIELDS);
                }

                var product = new ProductFTS
                {
                    Description     = document.Get("description"),
                    Category        = document.Get("category"),
                    ID              = document.Get("id"),
                    Name            = document.Get("name"),
                    RetailPrice     = int.Parse(document.Get("retail_price")),
                    DiscountedPrice = int.Parse(document.Get("discounted_price")),
                    ImageUrl        = document.Get("image"),
                };

                return(product);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
Пример #3
0
        public static Document GetLuceneDocument(this ProductFTS product)
        {
            try
            {
                Document doc = null;
                if (product != null)
                {
                    doc = new Document
                    {
                        new TextField("name", product.Name, Field.Store.YES),
                        new TextField("description", product.Description, Field.Store.YES),
                        //StringField store as is without perfroming the tokanization on this value
                        new StringField("category", product.Category, Field.Store.YES),
                        //StoreField stored but not anaylized & indexed
                        new StoredField("id", product.ID),
                        new StoredField("retail_price", product.RetailPrice),
                        new StoredField("discounted_price", product.DiscountedPrice),
                    };
                    if (product.ImageUrl != null)
                    {
                        doc.Add(new StoredField("image", product.ImageUrl));
                    }
                }

                return(doc);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }