static public ArrayList NormalizeWordsSet(string[] words) { ArrayList normalizedWord = new ArrayList(); foreach (string word in words) { string n = WebIndex.Normalize(word); if (!n.Equals("")) { normalizedWord.Add(n); } } return(normalizedWord); }
static private string BoldSearchedWords(string showText, SearchWords searchWords) { string result = ""; bool atWord = false; string currentWord = ""; string currentOutOfWord = ""; int count = showText.Length; for (int i = 0; i < count; i++) { char c = WebIndex.Normalize(showText[i]); if (WebIndex.GoodChar(c)) { if (!atWord) { currentWord = ""; atWord = true; result += HttpUtility.HtmlEncode(currentOutOfWord); } currentWord += c; } else { if (atWord) { currentOutOfWord = ""; atWord = false; result += FormatSearchWord(currentWord, searchWords); } currentOutOfWord += c; } } if (atWord) { result += FormatSearchWord(currentWord, searchWords); } else { result += HttpUtility.HtmlEncode(currentOutOfWord); } return(result); }
protected void Page_Load(object sender, EventArgs e) { DateTime start = DateTime.Now; txtResult.Text = ""; string queryText = Request["q"]; int startPage = 0; if( Request["s"] != null ) try { startPage = Int32.Parse(Request["s"]); } catch { }; if (queryText != null) { char[] tokens = { ' ' }; string[] words = queryText.Split(tokens); string webDirectory = Path.GetDirectoryName(Request.PhysicalPath); string pathDB = webDirectory + Path.DirectorySeparatorChar + "fullsearchdb.db3"; WebIndex idx = null; ArrayList results = null; SearchWords searchWords = null; try { idx = new WebIndex(); idx.Connect(pathDB); //results = idx.Search(words); searchWords = idx.PrepareRealWords(words); if (searchWords == null) // Some word not found: results = new ArrayList(0); else results = idx.Search(searchWords); } finally { if (idx != null) idx.Disconnect(); } //ArrayList normalizedWords = WebIndex.NormalizeWordsSet(words); string textFilesDir = webDirectory + Path.DirectorySeparatorChar + "textFiles"; int startResult = startPage * NRESULTSBYPAGE; int lastResult = (startPage + 1) * NRESULTSBYPAGE; if (lastResult > results.Count) lastResult = results.Count; txtSearchText.Text = ""; foreach (string word in words) txtSearchText.Text += word + " "; txtShowResults.Text = (startResult + 1) + " - " + lastResult; txtTotalResults.Text = results.Count.ToString(); txtResult.Text += "<p>"; for (int i = startResult; i < lastResult; i++) { Result result = (Result)results[i]; txtResult.Text += result.GoogleTextFormat(textFilesDir, searchWords) + "\n"; } txtResult.Text += "</p>"; if (results.Count > NRESULTSBYPAGE) { int nPages = results.Count / NRESULTSBYPAGE; if ((results.Count % NRESULTSBYPAGE) > 0) nPages++; if (startPage != 0) lnkPrevious.NavigateUrl = HRef(queryText, startPage - 1); else lnkPrevious.Visible = false; for (int i = 0; i < nPages; i++) { if (startPage != i) { int number = i + 1; txtResultLinks.Text += " " + Link(queryText, i, number.ToString()); } else txtResultLinks.Text += " <font color=\"red\">" + (i + 1) + "</font>"; } if (startPage != (nPages - 1)) lnkNext.NavigateUrl = HRef(queryText, startPage + 1); else lnkNext.Visible = false; } else { txtMoreResults.Visible = false; lnkPrevious.Visible = false; lnkNext.Visible = false; } } else { txtSearchText.Text = ""; txtShowResults.Text = "0 - 0"; txtTotalResults.Text = "0"; txtMoreResults.Visible = false; lnkPrevious.Visible = false; lnkNext.Visible = false; } DateTime end = DateTime.Now; TimeSpan span = end.Subtract(start); double roundMs = Math.Round(span.TotalMilliseconds, 2); txtMiliseconds.Text = roundMs.ToString(); }
private ArrayList GuardarDocumentos(string directory, string header, string footer, WebIndex indexer ) { // Intentar unificar nodos que quedarian vacios, con solo el titulo de la seccion: foreach( NodoArbol nodo in tree.Raiz.Hijos ) UnificarNodos( nodo ); // Recorrer el arbol en busca de nodos con cuerpo ArrayList archivosGenerados = new ArrayList(); foreach (NodoArbol nodo in tree.Raiz.Hijos) GuardarDocumentos(directory , header , footer , nodo, archivosGenerados , indexer ); return archivosGenerados; }
private void GuardarDocumentos( string directory , string header , string footer , NodoArbol nodo , ArrayList archivosGenerados , WebIndex indexer ) { if( nodo.body != null ) { string texto = ""; if( nodo.body.innerText != null ) texto = nodo.body.innerText.Trim(); if( !texto.Equals("") ) { bool guardar = true; string titulo = ""; IHTMLElement seccion = null; seccion = SearchFirstCutNode( nodo.body ); if( seccion != null && seccion.innerText != null ) { titulo = seccion.innerText.Trim() ; if( titulo.Length == 0 ) guardar = false; } if( guardar ) { // hacer un preproceso de TODOS los nodos del cuerpo: IHTMLElementCollection col = (IHTMLElementCollection)nodo.body.children; foreach( IHTMLElement nodoBody in col ) PreProcesarNodo( nodoBody , null); // Generar el documento a guardar: IHTMLDOMNode domNode = (IHTMLDOMNode)nodo.body; IHTMLElement clonedBody = (IHTMLElement)domNode.cloneNode(true); // Si hay pie o cabecera, añadirlos al body: if (header != null && !header.Equals("")) clonedBody.insertAdjacentHTML("afterBegin", header); if (footer != null && !footer.Equals("")) clonedBody.insertAdjacentHTML("beforeEnd", footer); iDoc.title = titulo; AntesYDespuesBody(); string archivo = directory + Path.DirectorySeparatorChar + nodo.Archivo; Encoding encoding = Encoding.GetEncoding( iDoc.charset ); StreamWriter writer = new StreamWriter( archivo , false , encoding ); writer.WriteLine( textoAntesBody ); texto = clonedBody.outerHTML; // Parece que hay un bug por el cual pone about:blank en los links. Quitarlos: texto = texto.Replace( "about:blank" , "" ).Replace("about:" , "" ); writer.WriteLine( texto ); writer.WriteLine( textoDespuesBody ); writer.Close(); // Clean the files using Tidy TidyOutputFile(archivo); if (FirstChapterContent == null) { // This is the first chapter of the document. Store it clean, because // we will need after. FirstChapterContent = nodo.body.innerHTML.Replace("about:blank", "").Replace("about:", ""); } archivosGenerados.Add( archivo ); if (indexer != null) // Store the document at the full text search index: indexer.AddPage(nodo.Archivo, nodo.Title , clonedBody ); } } } foreach( NodoArbol hijo in nodo.Hijos ) GuardarDocumentos( directory , header , footer , hijo , archivosGenerados , indexer ); }
/// <summary> /// Generated the help web site /// </summary> /// <param name="archivosGenerados">List of all files of the help content.</param> /// <param name="index">Index help information</param> /// <param name="cssFile">File that contains extracted CSS styles</param> private void GenerateWebSite( ArrayList archivosGenerados, Index index, string cssFile ) { try { // Crear el directorio web y copiar archivos adicionales: string dirWeb; //if( DirectorioWeb.Equals("") ) if (Project.WebDirectory.Equals("")) dirWeb = Project.HelpProjectDirectory + Path.DirectorySeparatorChar + "web"; else dirWeb = Project.WebDirectory; GenerarDirDestino(dirWeb); // Copy the css file if was generated: if (cssFile != null) File.Copy(cssFile, dirWeb + Path.DirectorySeparatorChar + Path.GetFileName(cssFile)); // Check if we can copy the generated files or we must to regenerate with other header // Copy generated chapter files: //if (ArchivoCabecera.Equals(HtmlHeaderFile) && ArchivoPie.Equals(HtmlFooterFile) && !Configuration.FullTextSearch ) if (Project.ChmHeaderFile.Equals(Project.WebHeaderFile) && Project.ChmFooterFile.Equals(Project.WebFooterFile) && !Project.FullTextSearch) { // Copy files generated for the CHM help foreach (string file in archivosGenerados) { string archivoDst = dirWeb + Path.DirectorySeparatorChar + Path.GetFileName(file); File.Copy(file, archivoDst); } } else { // Prepare the indexing database: WebIndex indexer = null; try { if (Project.FullTextSearch) { indexer = new WebIndex(); string dbFile = dirWeb + Path.DirectorySeparatorChar + "fullsearchdb.db3"; string dirTextFiles = dirWeb + Path.DirectorySeparatorChar + "textFiles"; indexer.Connect(dbFile); indexer.CreateDatabase(System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "searchdb.sql", dirTextFiles); indexer.StoreConfiguration(Project.WebLanguage); } // Create new files for the web help: GuardarDocumentos(dirWeb, HtmlHeaderCode, HtmlFooterCode, indexer); } finally { if (indexer != null) indexer.Disconnect(); } } // Copy base files for web help: string keywordsMeta = "", descriptionMeta = ""; //if( !WebKeywords.Trim().Equals( "" ) ) if (!Project.WebKeywords.Trim().Equals("")) //keywordsMeta = "<meta name=\"keywords\" content=\"" + WebKeywords + "\" >"; keywordsMeta = "<meta name=\"keywords\" content=\"" + Project.WebKeywords + "\" >"; //if( !WebDescription.Trim().Equals( "" ) ) if (!Project.WebDescription.Trim().Equals("")) //descriptionMeta = "<meta name=\"description\" content=\"" + WebDescription + "\" >"; descriptionMeta = "<meta name=\"description\" content=\"" + Project.WebDescription + "\" >"; // Convert title to windows-1252 enconding: string title = HtmlEncode(Project.HelpTitle); // Generate search form HTML code: string textSearch = ""; if (Project.FullTextSearch) { textSearch = "<form name=\"searchform\" method=\"post\" action=\"search.aspx\" id=\"searchform\" onsubmit=\"doFullTextSearch();return false;\" >\n"; textSearch += "<p><img src=\"system-search.png\" align=middle alt=\"Search image\" /> <b>%Search Text%:</b><br /><input type=\"text\" id=\"searchText\" style=\"width:80%;\" name=\"searchText\"/>\n"; textSearch += "<input type=\"button\" value=\"%Search%\" onclick=\"doFullTextSearch();\" id=\"Button1\" name=\"Button1\"/></p>\n"; } else { textSearch = "<form name=\"searchform\" method=\"post\" action=\"search.aspx\" id=\"searchform\" onsubmit=\"doSearch();return false;\" >\n"; textSearch += "<p><img src=\"system-search.png\" align=middle alt=\"Search image\" /> <b>%Search Text%:</b><br /><input type=\"text\" id=\"searchText\" style=\"width:80%;\" name=\"searchText\"/><br/>\n"; textSearch += "<input type=\"button\" value=\"%Search%\" onclick=\"doSearch();\" id=\"Button1\" name=\"Button1\"/></p>\n"; textSearch += "<select id=\"searchResult\" style=\"width:100%;\" size=\"20\" name=\"searchResult\">\n"; textSearch += "<option></option>\n"; textSearch += "</select>\n"; } textSearch += "</form>\n"; string[] variables = { "%TEXTSEARCH%" , "%TITLE%", "%TREE%", "%TOPICS%", "%FIRSTPAGECONTENT%", "%WEBDESCRIPTION%", "%KEYWORDS%" , "%HEADER%" , "%FOOTER%" }; //string[] newValues = { textSearch , title, arbol.GenerarArbolHtml(NivelMaximoTOC, "contentsTree", string[] newValues = { textSearch , title, tree.GenerarArbolHtml(Project.MaxHeaderContentTree, "contentsTree", "contentTree"), index.GenerateWebIndex(), FirstChapterContent, descriptionMeta, keywordsMeta , HtmlHeaderCode , HtmlFooterCode }; string baseDir = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "webFiles"; string[] extensions = { ".htm", ".html" }; Replacements replacements = new Replacements(variables, newValues); string translationFile = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "webTranslations" + Path.DirectorySeparatorChar + Project.WebLanguage + ".txt"; try { replacements.AddReplacementsFromFile(translationFile); } catch (Exception ex) { log("Error opening web translations file" + translationFile + ": " + ex.Message, 1); log(ex); } replacements.CopyDirectoryReplaced(baseDir, dirWeb, extensions, AppSettings.UseTidyOverOutput, UI); if (Project.FullTextSearch) { // Copy full text serch files: string[] aspxExtensions = { ".aspx" }; string dirSearchFiles = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "searchFiles"; replacements.CopyDirectoryReplaced(dirSearchFiles, dirWeb, aspxExtensions, false, UI); } if (Project.GenerateSitemap) // Generate site map for web indexers (google). GeneateSitemap(dirWeb); //return dirWeb + Path.DirectorySeparatorChar + "index.html"; } catch (Exception ex) { log(ex); } }
/// <summary> /// Generated the help web site /// </summary> /// <param name="archivosGenerados">List of all files of the help content.</param> /// <param name="index">Index help information</param> /// <param name="cssFile">File that contains extracted CSS styles</param> private void GenerateWebSite( ArrayList archivosGenerados, Index index, string cssFile ) { try { // Crear el directorio web y copiar archivos adicionales: string dirWeb; //if( DirectorioWeb.Equals("") ) if (Project.WebDirectory.Equals("")) dirWeb = Project.HelpProjectDirectory + Path.DirectorySeparatorChar + "web"; else dirWeb = Project.WebDirectory; GenerarDirDestino(dirWeb); // Copy the css file if was generated: if (cssFile != null) File.Copy(cssFile, dirWeb + Path.DirectorySeparatorChar + Path.GetFileName(cssFile)); // Prepare the indexing database: WebIndex indexer = null; try { if (Project.FullTextSearch) { indexer = new WebIndex(); string dbFile = dirWeb + Path.DirectorySeparatorChar + "fullsearchdb.db3"; string dirTextFiles = dirWeb + Path.DirectorySeparatorChar + "textFiles"; indexer.Connect(dbFile); indexer.CreateDatabase(System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "searchdb.sql", dirTextFiles); indexer.StoreConfiguration(Project.WebLanguage); } // Create new files for the web help: GuardarDocumentos(dirWeb, webDecorator, indexer); } finally { if (indexer != null) indexer.Disconnect(); } // HTML save version of the title: string htmlTitle = HtmlEncode(Project.HelpTitle); // Generate search form HTML code: string textSearch = ""; if (Project.FullTextSearch) { textSearch = "<form name=\"searchform\" method=\"post\" action=\"search.aspx\" id=\"searchform\" onsubmit=\"doFullTextSearch();return false;\" >\n"; textSearch += "<p><img src=\"system-search.png\" align=middle alt=\"Search image\" /> <b>%Search Text%:</b><br /><input type=\"text\" id=\"searchText\" style=\"width:80%;\" name=\"searchText\"/>\n"; textSearch += "<input type=\"button\" value=\"%Search%\" onclick=\"doFullTextSearch();\" id=\"Button1\" name=\"Button1\"/></p>\n"; } else { textSearch = "<form name=\"searchform\" method=\"post\" action=\"search.aspx\" id=\"searchform\" onsubmit=\"doSearch();return false;\" >\n"; textSearch += "<p><img src=\"system-search.png\" align=middle alt=\"Search image\" /> <b>%Search Text%:</b><br /><input type=\"text\" id=\"searchText\" style=\"width:80%;\" name=\"searchText\"/><br/>\n"; textSearch += "<input type=\"button\" value=\"%Search%\" onclick=\"doSearch();\" id=\"Button1\" name=\"Button1\"/></p>\n"; textSearch += "<select id=\"searchResult\" style=\"width:100%;\" size=\"20\" name=\"searchResult\">\n"; textSearch += "<option></option>\n"; textSearch += "</select>\n"; } textSearch += "</form>\n"; // The text placements for web files: string[] variables = { "%TEXTSEARCH%" , "%TITLE%", "%TREE%", "%TOPICS%", "%FIRSTPAGECONTENT%", "%WEBDESCRIPTION%", "%KEYWORDS%" , "%HEADER%" , "%FOOTER%" , "%HEADINCLUDE%" }; string[] newValues = { textSearch , htmlTitle, tree.GenerarArbolHtml(Project.MaxHeaderContentTree, "contentsTree", "contentTree"), index.GenerateWebIndex(), FirstChapterContent, webDecorator.MetaDescriptionTag , webDecorator.MetaKeywordsTag , webDecorator.HeaderHtmlCode , webDecorator.FooterHtmlCode , webDecorator.HeadIncludeHtmlCode }; Replacements replacements = new Replacements(variables, newValues); // Load translation files. string translationFile = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "webTranslations" + Path.DirectorySeparatorChar + Project.WebLanguage + ".txt"; try { replacements.AddReplacementsFromFile(translationFile); } catch (Exception ex) { log("Error opening web translations file" + translationFile + ": " + ex.Message, ConsoleUserInterface.ERRORWARNING); log(ex); } // Copy web files replacing text string baseDir = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "webFiles"; replacements.CopyDirectoryReplaced(baseDir, dirWeb, MSWord.HTMLEXTENSIONS, AppSettings.UseTidyOverOutput, UI, webDecorator.OutputEncoding); // Copy full text search files replacing text: if (Project.FullTextSearch) { // Copy full text serch files: string dirSearchFiles = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "searchFiles"; replacements.CopyDirectoryReplaced(dirSearchFiles, dirWeb, MSWord.ASPXEXTENSIONS, false, UI, webDecorator.OutputEncoding); } if (Project.GenerateSitemap) // Generate site map for web indexers (google). GeneateSitemap(dirWeb); } catch (Exception ex) { log(ex); } }
private void GuardarDocumentos(string directory, HtmlPageDecorator decorator, NodoArbol nodo, ArrayList archivosGenerados, WebIndex indexer) { if( nodo.body != null ) { string texto = ""; if( nodo.body.innerText != null ) texto = nodo.body.innerText.Trim(); if( !texto.Equals("") ) { bool guardar = true; string titulo = ""; IHTMLElement seccion = null; seccion = SearchFirstCutNode( nodo.body ); if( seccion != null && seccion.innerText != null ) { titulo = seccion.innerText.Trim() ; if( titulo.Length == 0 ) guardar = false; } if( guardar ) { // hacer un preproceso de TODOS los nodos del cuerpo: IHTMLElementCollection col = (IHTMLElementCollection)nodo.body.children; foreach( IHTMLElement nodoBody in col ) PreprocessHtmlNode( nodoBody , null); // Save the section, adding header, footers, etc: string filePath = directory + Path.DirectorySeparatorChar + nodo.Archivo; decorator.ProcessAndSavePage(nodo.body, filePath, nodo.Name); if (FirstChapterContent == null) { // This is the first chapter of the document. Store it clean, because // we will need after. FirstChapterContent = nodo.body.innerHTML.Replace("about:blank", "").Replace("about:", ""); } archivosGenerados.Add(filePath); if (indexer != null) // Store the document at the full text search index: //indexer.AddPage(nodo.Archivo, nodo.Title, nodo.body); indexer.AddPage(nodo.Archivo, nodo.Name, nodo.body); } } } foreach( NodoArbol hijo in nodo.Hijos ) GuardarDocumentos( directory , decorator , hijo , archivosGenerados , indexer ); }