public List <IndexableEntity> SubtitlesTextGetByIds(string ids, string userId = "") { List <IndexableEntity> subtitlesTextList = null; using (SqlConnection conn = GetNewConnection()) { List <SqlParameter> paramColl = new List <SqlParameter>(); paramColl.Add(new SqlParameter() { ParameterName = "@Ids", Value = ids }); if (!string.IsNullOrWhiteSpace(userId)) { paramColl.Add(new SqlParameter() { ParameterName = "@UserIdentification", Value = userId }); } using (SqlCommand command = BuildCommand(usp_SubtitlesText_SelectByIds, CommandType.StoredProcedure, paramColl)) { command.Connection = conn; command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { IndexableEntity subtitlesText = new IndexableEntity() { Id = reader.GetValueOrDefault <long>("Id"), SubtitleTextId = reader.GetValueOrDefault <long>("SubtitleTextId"), StartTime = reader.GetValueOrDefault <TimeSpan>("StartTime"), EndTime = reader.GetValueOrDefault <TimeSpan>("EndTime"), SubtitleText = reader.GetValueOrDefault <string>("SubtitleText"), TitleName = reader.GetValueOrDefault <string>("Title"), TitleId = reader.GetValueOrDefault <long>("TitleId") //, //Rating = reader.GetValueOrDefault<byte>("Rating"), //RatingId = reader.GetValueOrDefault<long>("RatingId") }; subtitlesText.UrlFriendlyQuoteText = subtitlesText.SubtitleText.UrlFriendlyString(); if (subtitlesTextList == null) { subtitlesTextList = new List <IndexableEntity>(); } subtitlesTextList.Add(subtitlesText); } reader.Close(); } } return(subtitlesTextList); }
private static void _addToLuceneIndex(IndexableEntity sampleData, IndexWriter writer) { // remove older index entry var searchQuery = new TermQuery(new Term("Id", sampleData.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", sampleData.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("TitleName", sampleData.TitleName, Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field("SubtitleText", sampleData.SubtitleText, Field.Store.NO, Field.Index.ANALYZED)); // add entry to index writer.AddDocument(doc); }
public List <IndexableEntity> SubtitlesTextGetByTitleId(long titleId) { List <IndexableEntity> subtitlesTextForTitle = null; using (SqlConnection conn = GetNewConnection()) { List <SqlParameter> paramColl = new List <SqlParameter>(); paramColl.Add(new SqlParameter() { ParameterName = "@TitleId", Value = titleId }); using (SqlCommand command = BuildCommand(usp_SubtitlesText_SelectByTitleId, CommandType.StoredProcedure, paramColl)) { command.Connection = conn; command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { IndexableEntity subtitlesText = new IndexableEntity() { Id = reader.GetValueOrDefault <long>("Id"), SubtitleTextId = reader.GetValueOrDefault <long>("SubtitleTextId"), StartTime = reader.GetValueOrDefault <TimeSpan>("StartTime"), EndTime = reader.GetValueOrDefault <TimeSpan>("EndTime"), SubtitleText = reader.GetValueOrDefault <string>("SubtitleText"), TitleName = reader.GetValueOrDefault <string>("Title") }; if (subtitlesTextForTitle == null) { subtitlesTextForTitle = new List <IndexableEntity>(); } subtitlesTextForTitle.Add(subtitlesText); } reader.Close(); } } return(subtitlesTextForTitle); }
public IndexableEntity RandomSubtitleGet(string userIdentification) { IndexableEntity subtitlesText = null; using (SqlConnection conn = GetNewConnection()) { List <SqlParameter> paramColl = new List <SqlParameter>(); paramColl.Add(new SqlParameter() { ParameterName = "@userId", Value = NullSafeGetter.IsDefault <string>(userIdentification) }); using (SqlCommand command = GetCommand(usp_RandomSubtitleId_Get, CommandType.StoredProcedure)) { command.Connection = conn; command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); if (reader.Read()) { subtitlesText = new IndexableEntity() { Id = reader.GetValueOrDefault <long>("Id"), SubtitleTextId = reader.GetValueOrDefault <long>("SubtitleTextId"), StartTime = reader.GetValueOrDefault <TimeSpan>("StartTime"), EndTime = reader.GetValueOrDefault <TimeSpan>("EndTime"), SubtitleText = reader.GetValueOrDefault <string>("SubtitleText"), TitleName = reader.GetValueOrDefault <string>("Title"), Rating = reader.GetValueOrDefault <byte>("Rating"), RatingId = reader.GetValueOrDefault <int>("UserFavoriteId") }; subtitlesText.UrlFriendlyQuoteText = subtitlesText.SubtitleText.UrlFriendlyString(); } reader.Close(); } } return(subtitlesText); }
public static List <IndexableEntity> ParseIt(Title title, TitleSubtitle titleSubtitle) { string[] theWholeSubtitleFileTextLines = titleSubtitle.SubtitleText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); List <IndexableEntity> parsedSubtitles = null; IndexableEntity currentParsedSubtitle = null; TimeSpan startTime = TimeSpan.MinValue; TimeSpan endTime = TimeSpan.MinValue; bool isPreviousCaptureReadyToInsert = false; for (int i = 0; i < theWholeSubtitleFileTextLines.Length; i++) { string thisLine = theWholeSubtitleFileTextLines[i]; int n; // Check if this line is not empty and not a number if (!string.IsNullOrWhiteSpace(thisLine) && !int.TryParse(thisLine.Trim(), out n)) { if (currentParsedSubtitle == null || currentParsedSubtitle.EndTime != TimeSpan.Zero) { currentParsedSubtitle = new IndexableEntity(); } // This means its a start time and end time indicator if (thisLine.Contains("-->")) { // If the capture for the current dialog is marked complete, add the object in the list and set the object to null. //if (isPreviousCaptureReadyToInsert) //{ // currentParsedSubtitle.EndTime = endTime; // if (parsedSubtitles == null) { parsedSubtitles = new List<IndexableEntity>(); } // currentParsedSubtitle.TitleName = title.TitleName; // currentParsedSubtitle.TitleId = title.Id; // currentParsedSubtitle.SubtitleTextId = titleSubtitle.Id; // parsedSubtitles.Add(currentParsedSubtitle); // currentParsedSubtitle = null; //} // Capture start time and end time string[] timesSplit = thisLine.Split(new string[] { "-->" }, System.StringSplitOptions.RemoveEmptyEntries); if (timesSplit.Length == 2) { if (!string.IsNullOrWhiteSpace(timesSplit[0])) { string startTimeString = timesSplit[0]; startTimeString = startTimeString.Remove(startTimeString.IndexOf(",")); startTime = TimeSpan.Parse(startTimeString); } if (!string.IsNullOrWhiteSpace(timesSplit[1])) { string endTimeString = timesSplit[1]; endTimeString = endTimeString.Remove(endTimeString.IndexOf(",")); endTime = TimeSpan.Parse(endTimeString); } } } else // NOW this means its a logical correct text line to capture as a quote { if (currentParsedSubtitle.StartTime == TimeSpan.Zero) { currentParsedSubtitle.StartTime = startTime; } thisLine = CleanItOfAllSpecialCharcters(thisLine); if (!string.IsNullOrWhiteSpace(currentParsedSubtitle.SubtitleText)) { currentParsedSubtitle.SubtitleText += " "; } currentParsedSubtitle.SubtitleText += thisLine; if ((thisLine.EndsWith(".") || thisLine.EndsWith("?")) && !thisLine.EndsWith("...")) // the last part is just to make sure the statement is not continued { isPreviousCaptureReadyToInsert = true; currentParsedSubtitle.EndTime = endTime; if (parsedSubtitles == null) { parsedSubtitles = new List <IndexableEntity>(); } currentParsedSubtitle.TitleName = title.TitleName; currentParsedSubtitle.TitleId = title.Id; currentParsedSubtitle.SubtitleTextId = titleSubtitle.Id; parsedSubtitles.Add(currentParsedSubtitle); currentParsedSubtitle = null; } else { isPreviousCaptureReadyToInsert = false; } } } } return(parsedSubtitles); }
// add/update/clear search index data public static void AddUpdateLuceneIndex(IndexableEntity sampleData) { AddUpdateLuceneIndex(new List <IndexableEntity> { sampleData }); }