Example #1
0
        private static void AddToLuceneIndex(KiaFeedModel item, IndexWriter writer)
        {
            // remove older index entry
            var searchQuery = new TermQuery(new Term("Id", item.Id));

            writer.DeleteDocuments(searchQuery);

            // add new index entry
            var doc = new Document();

            // add lucene fields mapped to db fields
            doc.Add(new Field("Id", item.Id, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("BodyType", item.BodyType, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("CarCategory", item.CarCategory, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("DrivetrainType", item.DrivetrainType, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Engine", item.Engine, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("EquipmentType", item.EquipmentType, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("ExteriorColor", item.ExteriorColor, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("FuelType", item.FuelType, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("ImageUrl", item.ImageUrl, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("InteriorColor", item.InteriorColor, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("KiaModel", item.KiaModel, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("ModelUrl", item.ModelUrl, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("MPG", item.MPG, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Price", item.Price, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("SalePrice", item.SalePrice, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Transmission", item.Transmission, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Year", item.Year, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Condition", item.Condition, Field.Store.YES, Field.Index.ANALYZED));

            // add entry to index
            writer.AddDocument(doc);
        }
Example #2
0
        public static IList <KiaFeedModel> GetModels()
        {
            var feeds = new List <KiaFeedModel>();

            foreach (var type in new[] { FeedType.New, FeedType.Used })
            {
                var url    = FeedUrls[type];
                var xml    = new XmlSerializer(typeof(Rss));
                var reader = XmlReader.Create(url);
                var rss    = xml.CanDeserialize(reader) ? (Rss)xml.Deserialize(reader) : new Rss();

                foreach (var item in rss.Channel.Items)
                {
                    var feed = new KiaFeedModel
                    {
                        Id             = item.Id,
                        KiaModel       = item.Model.ExtractFeedString(),
                        Year           = item.Year,
                        CarCategory    = item.Body.ExtractFeedString().SplittingWhiteSpaceLastElement(),
                        EquipmentType  = item.Trim.ExtractFeedString().SplittingWhiteSpaceElementAt(0).Replace("+", "").Replace("!", ""),
                        DrivetrainType = item.Trim.ExtractFeedString().SplittingWhiteSpaceElementAt(1),
                        BodyType       = item.Body.ExtractFeedString(),
                        Engine         = item.Engine.ExtractFeedString(),
                        FuelType       = "",
                        MPG            = "",
                        Transmission   = item.Transmission.ExtractFeedString(),
                        ExteriorColor  = item.Color.ExtractFeedString(),
                        InteriorColor  = item.InteriorColor.ExtractFeedString(),
                        SalePrice      = item.SalePrice.Replace(".00 USD", ""),
                        Price          = item.Price.Replace(".00 USD", ""),
                        ModelUrl       = item.Link.ExtractFeedString(),
                        ImageUrl       = item.ImageLink,
                        Condition      = item.Condition
                    };

                    feeds.Add(feed);
                }
            }

            return(feeds);
        }