示例#1
0
        public ArrayList Search(SearchWords searchWords)
        {
            // Search documents contaning all words:
            DbCommand cmd     = CreateCommandSinonymous(searchWords.WordSets.Count, searchWords.WordSets);
            ArrayList results = SearchWords(searchWords.WordSets, cmd);

            results.Sort();

            return(results);
        }
示例#2
0
        public SearchWords PrepareRealWords(string[] words)
        {
            // Load index language:
            string   language = "";
            IndexCfg cfg      = IndexCfg.Load(cnn);

            if (cfg != null)
            {
                language = cfg.Language.ToLower();
            }

            // Normalize words, see if they are at the index and search synonymous:
            SearchWords synonimous = new SearchWords();

            foreach (string word in words)
            {
                string n = Normalize(word);
                if (!n.Equals(""))
                {
                    ArrayList currentSet = new ArrayList(3);
                    Word      wrd        = Word.Load(cnn, n);
                    if (wrd == null)
                    {
                        currentSet = SearchSynonyms(n, language);
                        if (currentSet.Count == 0)
                        {
                            // Word not found: Exit without results.
                            return(null);
                        }
                    }
                    else
                    {
                        currentSet.Add(wrd);
                        currentSet.AddRange(SearchSynonyms(n, language));
                    }
                    synonimous.WordSets.Add(currentSet);
                }
            }

            if (synonimous.WordSets.Count == 0)
            {
                // Any good search word: Exit without results.
                return(null);
            }

            return(synonimous);
        }
示例#3
0
        public string GoogleTextFormat(string textFilesDirectory, SearchWords searchWords)
        {
            string showText = DisplayText(textFilesDirectory);

            showText = BoldSearchedWords(showText, searchWords);

            long   kb   = (long)(Math.Ceiling(((double)DocLenght) / 1024.0)) + 1;
            string text = "<a href=\"" + UrlPath + "\">" + BoldSearchedWords(Description, searchWords) +
                          "</a><br/>" +
                          showText + "<br/><font color=\"green\">" + UrlPath + "</font>";

/*#if DEBUG
 *          text += " - " + NumberOfInstances + " instances";
 #endif*/
            text += "<br/><br/>";
            return(text);
        }
示例#4
0
        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);
        }
示例#5
0
        static private string FormatSearchWord(string currentWord, SearchWords searchWords)
        {
            string currentWordLower = currentWord.ToLower();

            // Check if the word is a search word:

            /*bool searchWord = false;
             * foreach (string word in normalizedWords)
             * {
             *  if (word.Equals(currentWordLower))
             *  {
             *      searchWord = true;
             *      break;
             *  }
             * }*/
            if (!searchWords.Contains(currentWordLower))
            {
                return(HttpUtility.HtmlEncode(currentWord));
            }
            else
            {
                return("<b><u>" + HttpUtility.HtmlEncode(currentWord) + "</u></b>");
            }
        }
示例#6
0
        public ArrayList Search( SearchWords searchWords )
        {
            // Search documents contaning all words:
            DbCommand cmd = CreateCommandSinonymous(searchWords.WordSets.Count, searchWords.WordSets );
            ArrayList results = SearchWords( searchWords.WordSets, cmd);
            results.Sort();

            return results;
        }
示例#7
0
        public SearchWords PrepareRealWords(string[] words)
        {
            // Load index language:
            string language = "";
            IndexCfg cfg = IndexCfg.Load(cnn);
            if (cfg != null)
                language = cfg.Language.ToLower();

            // Normalize words, see if they are at the index and search synonymous:
            SearchWords synonimous = new SearchWords();
            foreach (string word in words)
            {
                string n = Normalize(word);
                if (!n.Equals(""))
                {
                    ArrayList currentSet = new ArrayList(3);
                    Word wrd = Word.Load(cnn, n);
                    if (wrd == null)
                    {
                        currentSet = SearchSynonyms(n, language);
                        if (currentSet.Count == 0)
                            // Word not found: Exit without results.
                            return null;
                    }
                    else
                    {
                        currentSet.Add(wrd);
                        currentSet.AddRange(SearchSynonyms(n, language));
                    }
                    synonimous.WordSets.Add(currentSet);
                }
            }

            if (synonimous.WordSets.Count == 0)
                // Any good search word: Exit without results.
                return null;

            return synonimous;
        }
示例#8
0
        private static string FormatSearchWord(string currentWord, SearchWords searchWords)
        {
            string currentWordLower = currentWord.ToLower();

            // Check if the word is a search word:
            /*bool searchWord = false;
            foreach (string word in normalizedWords)
            {
                if (word.Equals(currentWordLower))
                {
                    searchWord = true;
                    break;
                }
            }*/
            if ( !searchWords.Contains(currentWordLower) )
                return HttpUtility.HtmlEncode(currentWord);
            else
                return "<b><u>" + HttpUtility.HtmlEncode(currentWord) + "</u></b>";
        }
示例#9
0
        private static 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;
        }
示例#10
0
        public string GoogleTextFormat(string textFilesDirectory, SearchWords searchWords)
        {
            string showText = DisplayText(textFilesDirectory);
            showText = BoldSearchedWords(showText, searchWords);

            long kb = (long)(Math.Ceiling(((double)DocLenght) / 1024.0)) + 1;
            string text = "<a href=\"" + UrlPath + "\">" + BoldSearchedWords(Description, searchWords) +
                "</a><br/>" +
                showText + "<br/><font color=\"green\">" + UrlPath + "</font>";
            /*#if DEBUG
            text += " - " + NumberOfInstances + " instances";
            #endif*/
            text += "<br/><br/>";
            return text;
        }