public indexMessage buildIndex(indexMessage message) { if (_archive == null) { _archive = getVideoArchive(); } buildIndex(_archive, message); return(message); }
private void buildIndex(videoArchive archive, indexMessage message) { Lucene.Net.Index.IndexWriter writer; try { writer = new Lucene.Net.Index.IndexWriter(videoIndex, analyser, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED); foreach (videoCategory cat in archive.categories) { foreach (videoItem video in cat.videos) { string title = ""; if (!string.IsNullOrEmpty(video.name)) { title = video.name; } string bcid = ""; if (!string.IsNullOrEmpty(video.id)) { bcid = video.id; } string shortDescription = ""; if (!string.IsNullOrEmpty(video.shortDescription)) { shortDescription = video.shortDescription; } string longDescription = ""; if (!string.IsNullOrEmpty(video.longDescription)) { longDescription = video.longDescription; } string imageURL = ""; if (!string.IsNullOrEmpty(video.thumbnailURL)) { imageURL = video.videoStillURL; } addVideoToIndex(bcid, title, shortDescription, longDescription, imageURL, writer, message); } } message.success = true; writer.Optimize(); message.message = "Index built and optimized!"; writer.Dispose(); } catch (Exception ex) { message.success = false; message.message = ex.Message; } }
protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.QueryString["index"])) { string indexString = HttpUtility.UrlDecode(Request.QueryString.GetValues("index").GetValue(0).ToString()); if (indexString == "create") { indexMessage message = new indexMessage(); searcher.buildIndex(message); Response.Clear(); Response.ClearHeaders(); Response.ContentType = "application/json"; Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Write(JsonConvert.SerializeObject(message)); Response.End(); } } if (!string.IsNullOrEmpty(Request.QueryString["query"])) { //searchString = Uri.EscapeUriString(Request.QueryString.GetValues("query").GetValue(0).ToString()); searchString = HttpUtility.UrlDecode(Request.QueryString.GetValues("query").GetValue(0).ToString()); } if (!string.IsNullOrEmpty(searchString)) { Response.Clear(); Response.ClearHeaders(); Response.ContentType = "application/json"; Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Write(doSearch(searchString)); Response.End(); } else { Response.Clear(); Response.ClearHeaders(); Response.ContentType = "application/json"; Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Write("[]"); Response.End(); } }
private void addVideoToIndex(string bcid, string title, string shortDescription, string longDescription, string imageURL, Lucene.Net.Index.IndexWriter writer, indexMessage message) { Lucene.Net.Documents.Document video = new Lucene.Net.Documents.Document(); video.Add(new Lucene.Net.Documents.Field("title", title, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED, Lucene.Net.Documents.Field.TermVector.YES)); video.Add(new Lucene.Net.Documents.Field("shortDescription", shortDescription, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED, Lucene.Net.Documents.Field.TermVector.YES)); video.Add(new Lucene.Net.Documents.Field("longDescription", longDescription, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED, Lucene.Net.Documents.Field.TermVector.YES)); video.Add(new Lucene.Net.Documents.Field("bcid", bcid, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NOT_ANALYZED)); video.Add(new Lucene.Net.Documents.Field("imageURL", imageURL, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NOT_ANALYZED)); if (videoExistsInIndex(bcid)) { writer.UpdateDocument(new Lucene.Net.Index.Term("bcid", video.Get("bcid")), video); message.updatedVideo++; } else { writer.AddDocument(video); message.newVideo++; } }