Exemplo n.º 1
0
        public static void AddCreative(Creative creative, string tags)
        {
            var entity = new CreativeNetworkEntities();
            if (tags != null)
            {
                string[] tagList = tags.Split(new Char[] { ' ', ',' });

                foreach (var item in tagList.Distinct())
                {
                    if (string.IsNullOrEmpty(item) || item.Length > 50) continue;
                    var tag = new Tag
                    {
                        Name = item,
                    };
                    tag.Name = tag.Name.TrimEnd().ToLower();
                    if (entity.Tag.FirstOrDefault(a => a.Name == tag.Name) != null)
                    {
                        tag = entity.Tag.FirstOrDefault(a => a.Name == tag.Name);
                    }
                    else
                    {
                        entity.Tag.Add(tag);
                    }
                    creative.Tag.Add(tag);
                    var ers = entity.GetValidationErrors();
                    entity.SaveChanges();
                }
            }
            entity.Creative.Add(creative);
            var s = entity.GetValidationErrors();
            entity.SaveChanges();
        }
Exemplo n.º 2
0
        public static Creative[] GetCreatives(Tag tag)
        {
            var entity = new CreativeNetworkEntities();

            return entity.Creative.Where(a => a.Tag.FirstOrDefault(t => t.Name == tag.Name) != null).ToArray();
        }
Exemplo n.º 3
0
        private static void _addToLuceneIndex(Tag tag, IndexWriter writer)
        {
            // remove older index entry
            var searchQuery = new TermQuery(new Term("Id", tag.Id.ToString()));
            writer.DeleteDocuments(searchQuery);

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

            // add lucene fields mapped to db fields
            doc.Add(new Field("Id", tag.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Name", tag.Name, Field.Store.YES, Field.Index.ANALYZED));

            // add entry to index
            writer.AddDocument(doc);
        }