コード例 #1
0
ファイル: Main.cs プロジェクト: Gnostice/DocumentStudio.NET
        private void btnPrevSearch_Click(object sender, EventArgs e)
        {
            string searchText = txtSearchText.Text.Trim();

            textSearchResult = DocumentViewer1.FindPrevious(searchText, lastSearchResult: textSearchResult, searchOptions: textSearchOptions);
            ShowSearchedTextNotFound(textSearchResult);
        }
コード例 #2
0
        public TextSearchResult Search(int tenantId, string query, string module)
        {
            try
            {
                if (string.IsNullOrEmpty(module)) throw new ArgumentNullException("module");

                var result = new TextSearchResult(module);
                if (string.IsNullOrEmpty(query))
                {
                    return result;
                }
                if (TextIndexCfg.MaxQueryLength < query.Length)
                {
                    query = query.Substring(0, TextIndexCfg.MaxQueryLength);
                }

                var tenant = CoreContext.TenantManager.GetTenant(tenantId);
                var path = configuration.GetIndexPath(tenantId, module);
                if (tenant == null || !Directory.Exists(path)) return result;


                var searcher = new TextSearcher(module, path);
                return searcher.Search(query, tenant);
            }
            catch (Lucene.Net.QueryParsers.ParseException ex)
            {
                throw new ArgumentException(ex.Message);
            }
        }
コード例 #3
0
        private void Scan_Click(object sender, RoutedEventArgs e)
        {
            literatureSourceUIs = new List <LiteratureSourceUI>();
            SourcesList.Children.Clear();
            TextSearchResults textSearchResults = richTextBoxAdv.FindAll(new Regex(@"\[.*?\]"), FindOptions.None);

            if (textSearchResults != null)
            {
                int index = 1;
                for (int i = 0; i < textSearchResults.Count; i++)
                {
                    TextSearchResult textSearchResult = textSearchResults[i];
                    string[]         sublinks         = textSearchResult.Text.Substring(1, textSearchResult.Text.Length - 1).Split('#');
                    for (int j = 0; j < sublinks.Length; j++)
                    {
                        string text = sublinks[j].Trim();
                        try
                        {
                            literatureSourceUIs.First(x => x.literatureSource.shadowText == text);
                        }
                        catch
                        {
                            LiteratureSourceUI literatureSourceUI = new LiteratureSourceUI(new LiteratureSource(index, text), this);
                            literatureSourceUIs.Add(literatureSourceUI);
                            index++;
                            SourcesList.Children.Add(literatureSourceUI);
                        }
                    }
                }
            }
        }
コード例 #4
0
        public TextSearchResult Search(int tenantId, string query, string module)
        {
            try
            {
                if (string.IsNullOrEmpty(module))
                {
                    throw new ArgumentNullException("module");
                }

                var result = new TextSearchResult(module);
                if (string.IsNullOrEmpty(query))
                {
                    return(result);
                }
                if (TextIndexCfg.MaxQueryLength < query.Length)
                {
                    query = query.Substring(0, TextIndexCfg.MaxQueryLength);
                }

                var tenant = CoreContext.TenantManager.GetTenant(tenantId);
                var path   = configuration.GetIndexPath(tenantId, module);
                if (tenant == null || !Directory.Exists(path))
                {
                    return(result);
                }


                var searcher = new TextSearcher(module, path);
                return(searcher.Search(query, tenant));
            }
            catch (Lucene.Net.QueryParsers.ParseException ex)
            {
                throw new ArgumentException(ex.Message);
            }
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: Gnostice/DocumentStudio.NET
 private void ShowSearchedTextNotFound(TextSearchResult result)
 {
     if (result == null)
     {
         MessageBox.Show("DocumentViewer has finished searching the document. No matches were found.");
     }
 }
コード例 #6
0
ファイル: Main.cs プロジェクト: Gnostice/DocumentStudio.NET
 private void txtSearchText_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == System.Windows.Forms.Keys.Enter)
     {
         string searchText = txtSearchText.Text.Trim();
         textSearchResult = DocumentViewer1.FindNext(searchText, lastSearchResult: textSearchResult, searchOptions: textSearchOptions);
         ShowSearchedTextNotFound(textSearchResult);
         e.Handled          = true;
         e.SuppressKeyPress = true;
     }
 }
コード例 #7
0
ファイル: FormMain.cs プロジェクト: cuplexProjects/C-Projects
        private void _formFind_OnSearch(object sender, TextSearchEventArgs eventArgs)
        {
            if (_tabSearchEngine == null)
            {
                _tabSearchEngine = new TabSearchEngine(_tabPageDataCollection);
            }

            try
            {
                var searchProperties = new TextSearchProperties
                {
                    CaseSensitive   = eventArgs.SearchProperties.CaseSensitive,
                    LoopSearch      = eventArgs.SearchProperties.LoopSearch,
                    SearchAllTabs   = eventArgs.SearchProperties.SearchAllTabs,
                    SearchDirection = eventArgs.SearchProperties.SearchDirection,
                    SearchText      = eventArgs.SearchProperties.SearchText
                };

                TextSearchResult searchResult = _tabSearchEngine.GetTextSearchResult(searchProperties);

                if (searchResult.SearchTextFound)
                {
                    _tabSearchEngine.SelectionSetByCode = true;
                    if (searchResult.TabIndex != _tabPageDataCollection.ActiveTabIndex && searchProperties.SearchAllTabs)
                    {
                        _tabPageDataCollection.ActiveTabIndex = searchResult.TabIndex;
                        tabControlNotepad.SelectedIndex       = searchResult.TabIndex;
                    }

                    Focus();
                    RichTextBox textBox = GetRichTextBoxInActiveTab();
                    textBox.SelectionStart  = searchResult.StartPos;
                    textBox.SelectionLength = searchResult.Length;
                    textBox.Focus();
                    _tabSearchEngine.SelectionSetByCode = false;
                }
                else
                {
                    MessageBox.Show(Resources.FormMain__Search_string_not_found, Resources.FormMain__Not_found, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    RichTextBox textBox = GetRichTextBoxInActiveTab();
                    _tabSearchEngine.ResetSearchState(_tabPageDataCollection.ActiveTabIndex, textBox.SelectionStart, textBox.SelectionLength);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Tab Text search function encountered an exception.");
                Log.Error(ex, "Unhandled exception when calling _formFind_OnSearch()");
                MessageBox.Show(ex.Message, Resources.FormMain__ErrorText, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #8
0
        public TextSearchResult Search(string query, Tenant tenant)
        {
            var result = new TextSearchResult(module);

            if (string.IsNullOrEmpty(query) || !Directory.Exists(path))
            {
                return(result);
            }

            var dir      = Lucene.Net.Store.FSDirectory.Open(new DirectoryInfo(path));
            var searcher = new IndexSearcher(dir, false);

            try
            {
                var analyzer = new AnalyzersProvider().GetAnalyzer(tenant.GetCulture().TwoLetterISOLanguageName);
                var parser   = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Text", analyzer);
                parser.SetDefaultOperator(QueryParser.Operator.AND);
                if (TextIndexCfg.MaxQueryLength < query.Length)
                {
                    query = query.Substring(0, TextIndexCfg.MaxQueryLength);
                }
                Query q = null;
                try
                {
                    q = parser.Parse(query);
                }
                catch (Lucene.Net.QueryParsers.ParseException) { }
                if (q == null)
                {
                    q = parser.Parse(QueryParser.Escape(query));
                }

#pragma warning disable 618
                var hits = searcher.Search(q);
#pragma warning restore 618
                for (int i = 0; i < hits.Length(); i++)
                {
                    var doc = hits.Doc(i);
                    result.AddIdentifier(doc.Get("Id"));
                }
            }
            finally
            {
                searcher.Close();
                dir.Close();
            }
            return(result);
        }
コード例 #9
0
ファイル: TextSearcher.cs プロジェクト: ridhouan/teamlab.v6.5
        public TextSearchResult Search(string query, Tenant tenant)
        {
            var result = new TextSearchResult(module);

            if (string.IsNullOrEmpty(query) || !Directory.Exists(path))
            {
                return result;
            }

            var dir = Lucene.Net.Store.FSDirectory.Open(new DirectoryInfo(path));
            var searcher = new IndexSearcher(dir, false);
            try
            {
                var analyzer = new AnalyzersProvider().GetAnalyzer(tenant.GetCulture().TwoLetterISOLanguageName);
                var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Text", analyzer);
                parser.SetDefaultOperator(QueryParser.Operator.AND);
                if (TextIndexCfg.MaxQueryLength < query.Length)
                {
                    query = query.Substring(0, TextIndexCfg.MaxQueryLength);
                }
                Query q = null;
                try
                {
                    q = parser.Parse(query);
                }
                catch (Lucene.Net.QueryParsers.ParseException) { }
                if (q == null)
                {
                    q = parser.Parse(QueryParser.Escape(query));
                }

#pragma warning disable 618
                var hits = searcher.Search(q);
#pragma warning restore 618
                for (int i = 0; i < hits.Length(); i++)
                {
                    var doc = hits.Doc(i);
                    result.AddIdentifier(doc.Get("Id"));
                }
            }
            finally
            {
                searcher.Close();
                dir.Close();
            }
            return result;
        }
コード例 #10
0
        private object[] GetIdentifiers(TextSearchResult searchResult, int projectId, EntityType entryType)
        {
            var result = new List <object>()
            {
                -1
            };
            var ids = new List <string>();

            if (projectId != 0)
            {
                ids.AddRange(searchResult.GetIdentifierDetails(projectId.ToString()));
            }
            else
            {
                ids.AddRange(searchResult.GetIdentifiers());
                foreach (var id in searchResult.GetIdentifiers())
                {
                    ids.AddRange(searchResult.GetIdentifierDetails(id));
                }
            }

            foreach (var id in ids)
            {
                if (entryType == EntityType.Project && char.IsDigit(id, id.Length - 1))
                {
                    result.Add(int.Parse(id));
                }
                else if (entryType == EntityType.Milestone && id.EndsWith("s"))
                {
                    result.Add(int.Parse(id.TrimEnd('s')));
                }
                else if (entryType == EntityType.Task && id.EndsWith("t"))
                {
                    result.Add(int.Parse(id.TrimEnd('t')));
                }
                else if (entryType == EntityType.Message && id.EndsWith("m"))
                {
                    result.Add(int.Parse(id.TrimEnd('m')));
                }
                else if (entryType == EntityType.File && id.EndsWith("f"))
                {
                    result.Add(id.TrimEnd('f'));
                }
            }

            return(result.ToArray());
        }
コード例 #11
0
        private void ShowAll_Click(object sender, RoutedEventArgs e)
        {
            mainWindow.richTextBoxAdv.Selection.CharacterFormat.HighlightColor = HighlightColor.NoColor;
            List <string> allShadows = mainWindow.GetAllShadows(this);

            foreach (string shadow in allShadows)
            {
                TextSearchResults textSearchResults = mainWindow.richTextBoxAdv.FindAll(shadow, FindOptions.None);
                if (textSearchResults != null)
                {
                    for (int j = 0; j < textSearchResults.Count; j++)
                    {
                        TextSearchResult textSearchResult = textSearchResults[j];
                        mainWindow.richTextBoxAdv.Selection.SelectionRanges.Add(textSearchResult.Start, textSearchResult.End);
                    }
                    mainWindow.richTextBoxAdv.Selection.CharacterFormat.HighlightColor = HighlightColor.Gray25;
                }
            }
        }
コード例 #12
0
 public ImageSearchResult(TextSearchResult result)
 {
     NumberOfResults = result.NumberOfResults;
     Memes           = result.Memes;
 }
コード例 #13
0
ファイル: Main.cs プロジェクト: Gnostice/DocumentStudio.NET
 private void txtSearchText_TextChanged(object sender, EventArgs e)
 {
     textSearchResult = null;
 }
コード例 #14
0
ファイル: Main.cs プロジェクト: Gnostice/DocumentStudio.NET
 private void DocumentViewer1_DocumentLoaded(object sender, DocumentLoadedEventArgs e)
 {
     textSearchResult   = null;
     txtSearchText.Text = "";
 }
コード例 #15
0
        public List <TextSearchResult> FindTextInAllTabs(TextSearchProperties searchProperties)
        {
            if (_searchState == null)
            {
                _searchState = new TextSearchState
                {
                    InitialTabIndex = searchProperties.TabIndex,
                    TabIndex        = searchProperties.TabIndex,
                    StartPos        = searchProperties.StartPosition,
                    InitialStartPos = searchProperties.StartPosition,
                    MatchesFound    = 0
                };
            }

            TextSearchResultCollection resultCollection = new TextSearchResultCollection();
            int searchStrLength = searchProperties.SearchText.Length;

            int tabPageIndex = searchProperties.TabIndex;

            for (int i = 0; i < _searchCollection.Count; i++)
            {
                if (tabPageIndex > _searchCollection.Count)
                {
                    tabPageIndex = 0;
                }

                var item = _searchCollection.FirstOrDefault(x => x.TabPageIndex == tabPageIndex);

                if (item != null)
                {
                    int index = -1;

                    while (index > 0)
                    {
                        if (_searchState.StartPos > item.RichTextBox.TextLength)
                        {
                            break;
                        }

                        index = item.RichTextBox.Find(searchProperties.SearchText, _searchState.StartPos, RichTextBoxFinds.None);

                        if (index == -1)
                        {
                            break;
                        }

                        TextSearchResult searchResult = new TextSearchResult {
                            StartPos = index, Length = searchStrLength, TabIndex = tabPageIndex
                        };
                        resultCollection.AddSearchResult(searchResult);

                        _searchState.StartPos = index + searchStrLength;
                    }
                }

                _searchState.StartPos = 0;
                tabPageIndex++;
            }


            return(resultCollection.GetAllSearchResults());
        }