public ActionResult Upload(UploadTrack trackInfo)
        {
            Track track = new Track();
            track.TrackName = trackInfo.TrackName;
            track.Author = trackInfo.Author;
            track.UserName = WebSecurity.CurrentUserName;
            track.FileName = fileName;
            track.Like = 0;
            track.Listenings = 0;
            track.Description = new Markdown().Transform(trackInfo.Description);
            TrackRepository trackRepository = new TrackRepository();
            trackRepository.InsertOrUpdate(track);
            var tagList = trackInfo.Tags.Split(',');
            TagRepository tagRepository = new TagRepository();
            TagsInTracks tagsInTracks;
            Tag tag;
            TagsInTracksRepository tagInTrackRepository = new TagsInTracksRepository();
            foreach(var tagName in tagList)
            {
                tagsInTracks = new TagsInTracks();
                tagsInTracks.Track = track;
                if (tagRepository.TagExist(tagName))
                {
                    tagsInTracks.TagId = tagRepository.TagSearchId(tagName);
                }
                else
                {
                    tag = new Tag();
                    tag.TagName = tagName;
                    tagRepository.InsertOrUpdate(tag);
                    tagsInTracks.Tag = tag;
                }
                tagInTrackRepository.InsertOrUpdate(tagsInTracks);
                tagInTrackRepository.Save();

            }
            TrackData trackIndex = new TrackData();
            trackIndex.Author = trackInfo.Author;
            trackIndex.Id = track.TrackId;
            trackIndex.Tags = trackInfo.Tags;
            trackIndex.TrackName = trackInfo.TrackName;
            trackIndex.TrackPath = fileName;
            AddToIndex(trackIndex);

            return RedirectToAction("Index", "Home");
        }
示例#2
0
 public static void AddUpdateLuceneIndex(TrackData trackData)
 {
     AddUpdateLuceneIndex(new List<TrackData> { trackData });
 }
 public void AddToIndex(TrackData trackData)
 {
     GoLucene.AddUpdateLuceneIndex(trackData);
 }
示例#4
0
        private static void _addToLuceneIndex(TrackData trackData, IndexWriter writer)
        {
            // remove older index entry
            var searchQuery = new TermQuery(new Term("Id", trackData.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", trackData.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Author", trackData.Author, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("TrackName", trackData.TrackName, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Tags", trackData.Tags, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("TrackPath", trackData.TrackPath, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Like", trackData.Like.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            // add entry to index
            writer.AddDocument(doc);
        }