Exemple #1
0
        void AddDocuments(IndexWriter writer, Node node)
        {
            string url         = node.URL;
            Stream file_stream = GetHelpStream(url.Substring(9));

            if (file_stream == null) //Error
            {
                return;
            }
            XmlDocument xdoc = new XmlDocument();

            xdoc.Load(new XmlTextReader(file_stream));

            //Obtain the title
            XmlNode nelem = xdoc.DocumentElement;
            string  title = nelem.Attributes["number"].Value + ": " + nelem.Attributes["title"].Value;

            //Obtain the text
            StringBuilder s = new StringBuilder();

            GetTextNode(nelem, s);
            string text = s.ToString();

            //Obatin the examples
            StringBuilder s2 = new StringBuilder();

            GetExamples(nelem, s2);
            string examples = s2.ToString();

            //Write to the Lucene Index all the parts
            SearchableDocument doc = new SearchableDocument();

            doc.title    = title;
            doc.hottext  = title.Substring(title.IndexOf(':'));
            doc.url      = url;
            doc.text     = text;
            doc.examples = examples;
            writer.AddDocument(doc.LuceneDoc);

            if (node.IsLeaf)
            {
                return;
            }

            foreach (Node n in node.Nodes)
            {
                AddDocuments(writer, n);
            }
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
	//
	// Create list of documents for searching
	//
	public override void PopulateSearchableIndex (IndexWriter writer)
	{
		StringBuilder text;
		foreach (Node ns_node in Tree.Nodes) {
			Message (TraceLevel.Info, "\tNamespace: {0} ({1})", ns_node.Caption, ns_node.Nodes.Count);
			foreach (Node type_node in ns_node.Nodes) {
				string typename = type_node.Caption.Substring (0, type_node.Caption.IndexOf (' '));
				string full = ns_node.Caption + "." + typename;
				string doc_tag = GetKindFromCaption (type_node.Caption);
				string url = "T:" + full;
				string rest;
				XmlDocument xdoc = GetXmlFromUrl (type_node.URL, out rest);
				if (xdoc == null)
					continue;
				
				// 
				// For classes, structures or interfaces add a doc for the overview and
				// add a doc for every constructor, method, event, ...
				// 
				if (doc_tag == "Class" || doc_tag == "Structure" || doc_tag == "Interface"){
					
					// Adds a doc for every overview of every type
					SearchableDocument doc = new SearchableDocument ();
					doc.title = type_node.Caption;
					doc.hottext = typename;
					doc.url = url;
					doc.fulltitle = full;
					
					XmlNode node_sel = xdoc.SelectSingleNode ("/Type/Docs");
					text  = new StringBuilder ();
					GetTextFromNode (node_sel, text);
					doc.text = text.ToString ();

					text  = new StringBuilder ();
					GetExamples (node_sel, text);
					doc.examples = text.ToString ();
					
					writer.AddDocument (doc.LuceneDoc);
					var exportParsable = doc_tag == "Class" && (ns_node.Caption.StartsWith ("MonoTouch") || ns_node.Caption.StartsWith ("MonoMac"));

					//Add docs for contructors, methods, etc.
					foreach (Node c in type_node.Nodes) { // c = Constructors || Fields || Events || Properties || Methods || Operators
						
						if (c.Element == "*")
							continue;
						int i = 1;
						const float innerTypeBoost = 0.2f;

						foreach (Node nc in c.Nodes) {
							// Disable constructors indexing as it's often "polluting" search queries
							// because it has the same hottext than standard types
							if (c.Caption == "Constructors")
								continue;
							//xpath to the docs xml node
							string xpath;
							if (c.Caption == "Constructors")
								xpath = String.Format ("/Type/Members/Member[{0}]/Docs", i++);
							else if (c.Caption == "Operators")
								xpath = String.Format ("/Type/Members/Member[@MemberName='op_{0}']/Docs", nc.Caption);
							else
								xpath = String.Format ("/Type/Members/Member[@MemberName='{0}']/Docs", nc.Caption);
							//construct url of the form M:Array.Sort
							string urlnc;
							if (c.Caption == "Constructors")
								urlnc = String.Format ("{0}:{1}.{2}", c.Caption[0], ns_node.Caption, nc.Caption);
							else
								urlnc = String.Format ("{0}:{1}.{2}.{3}", c.Caption[0], ns_node.Caption, typename, nc.Caption);

							//create the doc
							SearchableDocument doc_nod = new SearchableDocument ();
							doc_nod.title = LargeName (nc);
							switch (c.Caption[0]) {
							case 'M':
								doc_nod.title += " Method";
								break;
							case 'P':
								doc_nod.title += " Property";
								break;
							case 'E':
								doc_nod.title += " Event";
								break;
							case 'O':
								doc_nod.title += " Operator";
								break;
							default:
								break;
							}
							doc_nod.fulltitle = string.Format ("{0}.{1}::{2}", ns_node.Caption, typename, nc.Caption);
							//dont add the parameters to the hottext
							int ppos = nc.Caption.IndexOf ('(');
							if (ppos != -1)
								doc_nod.hottext =  nc.Caption.Substring (0, ppos);
							else
								doc_nod.hottext = nc.Caption;

							doc_nod.url = urlnc;

							XmlNode xmln = xdoc.SelectSingleNode (xpath);
							if (xmln == null) {
								Error ("Problem: {0}, with xpath: {1}", urlnc, xpath);
								continue;
							}

							text = new StringBuilder ();
							GetTextFromNode (xmln, text);
							doc_nod.text = text.ToString ();

							text = new StringBuilder ();
							GetExamples (xmln, text);
							doc_nod.examples = text.ToString ();

							Document lucene_doc = doc_nod.LuceneDoc;
							lucene_doc.SetBoost (innerTypeBoost);
							writer.AddDocument (lucene_doc);

							// MonoTouch/Monomac specific parsing of [Export] attributes
							if (exportParsable) {
								try {
									var exports =
										xdoc.SelectNodes (string.Format ("/Type/Members/Member[@MemberName='{0}']/Attributes/Attribute/AttributeName[contains(text(), 'Foundation.Export')]", nc.Caption));
									foreach (XmlNode exportNode in exports) {
										var inner = exportNode.InnerText;
										var parts = inner.Split ('"');
										if (parts.Length != 3) {
											Console.WriteLine ("Export attribute not found or not usable in {0}", inner);
											continue;
										}
										
										var export = parts[1];
										var export_node = new SearchableDocument ();
										export_node.title = export + " Export";
										export_node.fulltitle = string.Format ("{0}.{1}::{2}", ns_node.Caption, typename, export);
										export_node.url = urlnc;
										export_node.hottext = export + ":";
										export_node.text = string.Empty;
										export_node.examples = string.Empty;
										lucene_doc = export_node.LuceneDoc;
										lucene_doc.SetBoost (innerTypeBoost);
										writer.AddDocument (lucene_doc);
									}
								} catch (Exception e){
									Console.WriteLine ("Problem processing {0} for MonoTouch/MonoMac exports\n\n{0}", e);
								}
							}
						}
					}
				//
				// Enumerations: add the enumeration values
				//
				} else if (doc_tag == "Enumeration"){
										
					XmlNodeList members = xdoc.SelectNodes ("/Type/Members/Member");
					if (members == null)
						continue;

					text = new StringBuilder ();
					foreach (XmlNode member_node in members) {
						string enum_value = member_node.Attributes ["MemberName"].InnerText;
						text.Append (enum_value);
						text.Append (" ");
						GetTextFromNode (member_node["Docs"], text);
						text.Append ("\n");
					}
					SearchableDocument doc = new SearchableDocument ();

					text = new StringBuilder ();
					GetExamples (xdoc.SelectSingleNode ("/Type/Docs"), text);
					doc.examples = text.ToString ();

					doc.title = type_node.Caption;
					doc.hottext = xdoc.DocumentElement.Attributes["Name"].Value;
					doc.fulltitle = full;
					doc.url = url;
					doc.text = text.ToString();
					writer.AddDocument (doc.LuceneDoc);
				//
				// Add delegates
				//
				} else if (doc_tag == "Delegate"){
					SearchableDocument doc = new SearchableDocument ();
					doc.title = type_node.Caption;
					doc.hottext = xdoc.DocumentElement.Attributes["Name"].Value;
					doc.fulltitle = full;
					doc.url = url; 
					
					XmlNode node_sel = xdoc.SelectSingleNode ("/Type/Docs");

					text = new StringBuilder ();
					GetTextFromNode (node_sel, text);
					doc.text = text.ToString();

					text = new StringBuilder ();
					GetExamples (node_sel, text);
					doc.examples = text.ToString();

					writer.AddDocument (doc.LuceneDoc);
				}
			}
		}
	}
Exemple #4
0
		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);
			}
		}
Exemple #5
0
	//
	// Create list of documents for searching
	//
	public override void PopulateSearchableIndex (IndexWriter writer)
	{
		StringBuilder text;
		foreach (Node ns_node in Tree.Nodes) {
			Message (TraceLevel.Info, "\tNamespace: {0} ({1})", ns_node.Caption, ns_node.Nodes.Count);
			foreach (Node type_node in ns_node.Nodes) {
				string typename = type_node.Caption.Substring (0, type_node.Caption.IndexOf (' '));
				string full = ns_node.Caption + "." + typename;
				string doc_tag = GetKindFromCaption (type_node.Caption);
				string url = "T:" + full;
				string rest;
				XmlDocument xdoc = GetXmlFromUrl (type_node.URL, out rest);
				if (xdoc == null)
					continue;
				
				// 
				// For classes, structures or interfaces add a doc for the overview and
				// add a doc for every constructor, method, event, ...
				// 
				if (doc_tag == "Class" || doc_tag == "Structure" || doc_tag == "Interface"){
					
					// Adds a doc for every overview of every type
					SearchableDocument doc = new SearchableDocument ();
					doc.title = type_node.Caption;
					doc.hottext = typename;
					doc.url = url;
					
					XmlNode node_sel = xdoc.SelectSingleNode ("/Type/Docs");
					text  = new StringBuilder ();
					GetTextFromNode (node_sel, text);
					doc.text = text.ToString ();

					text  = new StringBuilder ();
					GetExamples (node_sel, text);
					doc.examples = text.ToString ();
					
					writer.AddDocument (doc.LuceneDoc);

					//Add docs for contructors, methods, etc.
					foreach (Node c in type_node.Nodes) { // c = Constructors || Fields || Events || Properties || Methods || Operators
						
						if (c.Element == "*")
							continue;
						int i = 1;
						foreach (Node nc in c.Nodes) {
							//xpath to the docs xml node
							string xpath;
							if (c.Caption == "Constructors")
								xpath = String.Format ("/Type/Members/Member[{0}]/Docs", i++);
							else if (c.Caption == "Operators")
								xpath = String.Format ("/Type/Members/Member[@MemberName='op_{0}']/Docs", nc.Caption);
							else
								xpath = String.Format ("/Type/Members/Member[@MemberName='{0}']/Docs", nc.Caption);
							//construct url of the form M:Array.Sort
							string urlnc;
							if (c.Caption == "Constructors")
								urlnc = String.Format ("{0}:{1}.{2}", c.Caption[0], ns_node.Caption, nc.Caption);
							else
								urlnc = String.Format ("{0}:{1}.{2}.{3}", c.Caption[0], ns_node.Caption, typename, nc.Caption);

							//create the doc
							SearchableDocument doc_nod = new SearchableDocument ();
							doc_nod.title = LargeName (nc);
							//dont add the parameters to the hottext
							int ppos = nc.Caption.IndexOf ('(');
							if (ppos != -1)
								doc_nod.hottext =  nc.Caption.Substring (0, ppos);
							else
								doc_nod.hottext = nc.Caption;

							doc_nod.url = urlnc;

							XmlNode xmln = xdoc.SelectSingleNode (xpath);
							if (xmln == null) {
								Error ("Problem: {0}, with xpath: {1}", urlnc, xpath);
								continue;
							}

							text = new StringBuilder ();
							GetTextFromNode (xmln, text);
							doc_nod.text = text.ToString ();

							text = new StringBuilder ();
							GetExamples (xmln, text);
							doc_nod.examples = text.ToString ();

							writer.AddDocument (doc_nod.LuceneDoc);
						}
					}
				//
				// Enumerations: add the enumeration values
				//
				} else if (doc_tag == "Enumeration"){
										
					XmlNodeList members = xdoc.SelectNodes ("/Type/Members/Member");
					if (members == null)
						continue;

					text = new StringBuilder ();
					foreach (XmlNode member_node in members) {
						string enum_value = member_node.Attributes ["MemberName"].InnerText;
						text.Append (enum_value);
						text.Append (" ");
						GetTextFromNode (member_node["Docs"], text);
						text.Append ("\n");
					}
					SearchableDocument doc = new SearchableDocument ();

					text = new StringBuilder ();
					GetExamples (xdoc.SelectSingleNode ("/Type/Docs"), text);
					doc.examples = text.ToString ();

					doc.title = type_node.Caption;
					doc.hottext = xdoc.DocumentElement.Attributes["Name"].Value;
					doc.url = url;
					doc.text = text.ToString();
					writer.AddDocument (doc.LuceneDoc);
				//
				// Add delegates
				//
				} else if (doc_tag == "Delegate"){
					SearchableDocument doc = new SearchableDocument ();
					doc.title = type_node.Caption;
					doc.hottext = xdoc.DocumentElement.Attributes["Name"].Value;
					doc.url = url; 
					
					XmlNode node_sel = xdoc.SelectSingleNode ("/Type/Docs");

					text = new StringBuilder ();
					GetTextFromNode (node_sel, text);
					doc.text = text.ToString();

					text = new StringBuilder ();
					GetExamples (node_sel, text);
					doc.examples = text.ToString();

					writer.AddDocument (doc.LuceneDoc);
				} 
			}
		}
	}
Exemple #6
0
	void AddDocuments (IndexWriter writer, Node node) 
	{
		string url = node.URL;
		Stream file_stream = GetHelpStream (url.Substring (9));
		if (file_stream == null) //Error
			return;
		XmlDocument xdoc = new XmlDocument ();
		xdoc.Load (new XmlTextReader (file_stream));

		//Obtain the title
		XmlNode nelem = xdoc.DocumentElement;
		string title = nelem.Attributes["number"].Value + ": " + nelem.Attributes["title"].Value;

		//Obtain the text
		StringBuilder s = new StringBuilder ();
		GetTextNode (nelem, s);
		string text = s.ToString ();

		//Obatin the examples
		StringBuilder s2 = new StringBuilder ();
		GetExamples (nelem, s2);
		string examples = s2.ToString ();

		//Write to the Lucene Index all the parts
		SearchableDocument doc = new SearchableDocument ();
		doc.title = title;
		doc.hottext = title.Substring (title.IndexOf (':')); 
		doc.url = url;
		doc.text = text;
		doc.examples = examples;
		writer.AddDocument (doc.LuceneDoc);
		
		if (node.IsLeaf)
			return;

		foreach (Node n in node.Nodes)
			AddDocuments (writer, n);
	}