Add C# errors to search index so that it can be accessed by search tools (like webdoc...
authorJeremie Laval <jeremie.laval@gmail.com>
Sat, 26 Nov 2011 14:30:45 +0000 (15:30 +0100)
committerJeremie Laval <jeremie.laval@gmail.com>
Sat, 26 Nov 2011 14:30:45 +0000 (15:30 +0100)
mcs/tools/monodoc/Monodoc/error-provider.cs

index 9758d25b9e6070cf98bef8d4b36d5f00e28e7f6e..d7575240ef1135bc2354bb0a291bbef408dfc582 100644 (file)
@@ -15,6 +15,9 @@ using System.IO;
 using System.Text;
 using System.Xml;
 using System.Xml.Serialization;
+using System.Linq;
+using Mono.Lucene.Net.Index;
+using Mono.Lucene.Net.Documents;
 
 namespace Monodoc {
 
@@ -270,6 +273,21 @@ namespace Monodoc {
                                index_maker.Add (n.Caption, n.Caption, n.Element);
                }
 
+               public override void PopulateSearchableIndex (IndexWriter writer) 
+               {
+                       foreach (Node n in Tree.Nodes) {
+                               XmlSerializer reader = new XmlSerializer (typeof (ErrorDocumentation));
+                               ErrorDocumentation d = (ErrorDocumentation)reader.Deserialize (GetHelpStream (n.Element.Substring (6)));
+                               SearchableDocument doc = new SearchableDocument ();
+                               doc.title = d.ErrorName;
+                               doc.url = n.Element;
+                               doc.text = d.Details != null ? d.Details.ToString () : string.Empty;
+                               doc.examples = d.Examples.Cast<string> ().Aggregate ((e1, e2) => e1 + Environment.NewLine + e2);
+                               doc.hottext = d.ErrorName;
+                               writer.AddDocument (doc.LuceneDoc);
+                       }
+               }
+
                public static string css_error_code = @"
                                                                 #error_ref { 
                                                                    background: #debcb0;