/// <summary> /// This constructor is used while retrieving the hit from the dump /// </summary> /// <param name="ixr">The dump indexer this Wiki topic belongs to</param> /// <param name="hit">The Lucene Hit object</param> public PageInfo(Indexer ixr, Hit hit) { indexer = ixr; Document doc = hit.GetDocument(); TopicId = Convert.ToInt64(doc.GetField("topicid").StringValue()); Name = doc.GetField("title").StringValue(); Beginnings = new long[doc.GetFields("beginning").Length]; Ends = new long[doc.GetFields("end").Length]; int i = 0; foreach (byte[] binVal in doc.GetBinaryValues("beginning")) { Beginnings[i] = BitConverter.ToInt64(binVal, 0); i++; } i = 0; foreach (byte[] binVal in doc.GetBinaryValues("end")) { Ends[i] = BitConverter.ToInt64(binVal, 0); i++; } Array.Sort(Beginnings); Array.Sort(Ends); }
public ProgressDialog(Indexer indexer) { InitializeComponent(); ixr = indexer; ixr.ProgressChanged += new ProgressChangedEventHandler(ixr_ProgressChanged); }
private void LoadIndexer(string file) { if (!File.Exists(file)) { MessageBox.Show(this, "Dump file " + file + " does not exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Indexer ixr = new Indexer(file); if (!ixr.IndexExists) { if (new ProgressDialog(ixr).ShowDialog(this) != DialogResult.OK) { return; } } indexes.Add(file.ToLowerInvariant(), ixr); }
/// <summary> /// Initialize the wiki index. /// </summary> /// <returns>True or false for success or not.</returns> public bool InitializeWikiIndex() { // check if the file exists if (!File.Exists(_dumpFile)) { return false; } // check if the index exists Indexer ixr = new Indexer(_dumpFile); if (!ixr.IndexExists) { return false; } // load the index _wikiIndices.Add(_dumpFile.ToLowerInvariant(), ixr); return true; }
/// <summary> /// Gets called whenever the browser control requests a URL from the web server /// </summary> /// <param name="sender">Web server instance</param> /// <param name="e">Request parameters</param> private void Web_UrlRequested(object sender, UrlRequestedEventArgs e) { string response = "Not found"; string redirect = String.Empty; if (!String.IsNullOrEmpty(e.TeXEquation)) { return; } string topic = e.TopicName.Replace('_', ' ').Trim(); if (topic.Contains("#")) { topic = topic.Substring(0, topic.IndexOf('#')).Trim(); } PageInfo page = hitsBox.SelectedItem as PageInfo; if (page != null && topic.Equals(page.Name, StringComparison.InvariantCultureIgnoreCase) && e.IndexName.Equals(page.Indexer.File, StringComparison.InvariantCultureIgnoreCase) && !IsCircularRedirect(page)) { response = page.GetFormattedContent(); redirect = page.RedirectToTopic; } else { List <Indexer> searchArea = new List <Indexer>(); // This is an internal link if (String.IsNullOrEmpty(e.IndexName)) { if (page != null) { searchArea.Add(page.Indexer); } else { foreach (Indexer ixr in indexes.Values) { searchArea.Add(ixr); } } } else { foreach (Indexer ixr in indexes.Values) { if (ixr.File.Equals(e.IndexName, StringComparison.InvariantCultureIgnoreCase)) { searchArea.Add(ixr); break; } } } if (searchArea.Count > 0) { HitCollection hits = Indexer.Search(topic, searchArea, 100); bool exactTopicLocated = false; foreach (PageInfo pi in hits) { if (pi.Name.Trim().Equals(topic, StringComparison.InvariantCultureIgnoreCase) && !IsCircularRedirect(pi)) { response = pi.GetFormattedContent(); redirect = pi.RedirectToTopic; exactTopicLocated = true; break; } } if (hits.Count > 0 && !exactTopicLocated) { foreach (PageInfo pi in hits) { if (String.IsNullOrEmpty(pi.RedirectToTopic)) { response = pi.GetFormattedContent(); redirect = pi.RedirectToTopic; exactTopicLocated = true; break; } } if (!exactTopicLocated) { foreach (PageInfo pi in hits) { if (!IsCircularRedirect(pi)) { response = pi.GetFormattedContent(); redirect = pi.RedirectToTopic; break; } } } } } } e.Redirect = !String.IsNullOrEmpty(redirect); e.RedirectTarget = redirect; e.Response = Encoding.UTF8.GetBytes(response); e.MimeType = "text/html"; if (String.IsNullOrEmpty(redirect)) { autoRedirects.Clear(); } else { autoRedirects.Push(redirect); } }
private void LoadIndexer(string file) { if (!File.Exists(file)) { MessageBox.Show(this, String.Format(Properties.Resources.DumpFileDoesNotExist, file), Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Indexer ixr = new Indexer(file); if (!ixr.IndexExists) { if (new ProgressDialog(ixr).ShowDialog(this) != DialogResult.OK) { return; } } indexes.Add(ixr.File, ixr); }