Ejemplo n.º 1
0
        private static void _addToLuceneIndex(string language, Product entireProduct, IndexWriter writer)
        {
            // remove older index entry
            var searchQuery = new TermQuery(new Term("Id", entireProduct.ProductID.ToString(CultureInfo.InvariantCulture)));

            writer.DeleteDocuments(searchQuery);

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

            var allContent = entireProduct.Name + " " + entireProduct.EDI + " " + entireProduct.SKU
                             + " " + entireProduct.Year.ToString(CultureInfo.InvariantCulture) + " " + entireProduct.Material
                             + " " + entireProduct.Size;

            // add lucene fields mapped to db fields
            doc.Add(new Field("Id", entireProduct.ProductID.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Language", language, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Name", entireProduct.Name, Field.Store.YES, Field.Index.ANALYZED));

            if (!string.IsNullOrEmpty(entireProduct.EDI))
            {
                doc.Add(new Field("Edi", entireProduct.EDI, Field.Store.YES, Field.Index.ANALYZED));
            }

            if (!string.IsNullOrEmpty(entireProduct.SKU))
            {
                doc.Add(new Field("Sku", entireProduct.SKU, Field.Store.YES, Field.Index.ANALYZED));
            }

            doc.Add(new Field("Year", entireProduct.Year.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED));

            if (!string.IsNullOrEmpty(entireProduct.Material))
            {
                doc.Add(new Field("Material", entireProduct.Material, Field.Store.YES, Field.Index.ANALYZED));
            }

            if (!string.IsNullOrEmpty(entireProduct.Size))
            {
                doc.Add(new Field("Size", entireProduct.Size, Field.Store.YES, Field.Index.ANALYZED));
            }

            if (entireProduct.Season != null)
            {
                allContent += " " + LanguageString.GetStringForCurrentLanguage(language, entireProduct.Season.Name);
                doc.Add(new Field("SeasonId", entireProduct.SeasonID.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.ANALYZED));
            }

            if (entireProduct.Gender != null)
            {
                allContent += " " + LanguageString.GetStringForCurrentLanguage(language, entireProduct.Gender.Name);
                doc.Add(new Field("GenderId", entireProduct.GenderID.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.ANALYZED));
            }

            if (entireProduct.Category != null)
            {
                allContent += " " + LanguageString.GetStringForCurrentLanguage(language, entireProduct.Category.Name);
                doc.Add(new Field("CategoryId", entireProduct.CategoryID.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.ANALYZED));
            }

            if (entireProduct.Collection != null)
            {
                allContent += " " + entireProduct.Collection.Name;
                doc.Add(new Field("CollectionId", entireProduct.CollectionID.ToString(), Field.Store.YES, Field.Index.ANALYZED));
            }

            if (entireProduct.Brand != null)
            {
                allContent += " " + entireProduct.Brand.Name;
                doc.Add(new Field("BrandId", entireProduct.CollectionID.ToString(), Field.Store.YES, Field.Index.ANALYZED));
            }

            doc.Add(new Field("Created", entireProduct.created.ToString("yyyyMMdd"), Field.Store.YES, Field.Index.NOT_ANALYZED));

            // add lucene field for all fields
            doc.Add(new Field("AllContent", allContent, Field.Store.YES, Field.Index.ANALYZED));

            // add entry to index
            writer.AddDocument(doc);
        }
Ejemplo n.º 2
0
        public IEnumerable <KeyValuePair <int, string> > GetGendersAndMapToSelectList()
        {
            var gendersList = new List <KeyValuePair <int, string> >();

            try
            {
                using (var db = new Entities())
                {
                    var genders = db.Genders.OrderBy(i => i.Name)
                                  .ToList();
                    if (genders.Any())
                    {
                        gendersList.AddRange(genders.Select(gender => new KeyValuePair <int, string>(gender.GenderID, LanguageString.GetStringForCurrentLanguage(gender.Name))));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("GetGendersAndMapToSelectList - error [{0}] - - \r\n {1} \r\n\r\n", ex.Message, ex.StackTrace);
            }

            return(gendersList);
        }