public SearchableIndex GetSearchIndex() { var paths = GetIndexesPathPrefixes().Select(bp => Path.Combine(bp, "search_index")); var p = paths.FirstOrDefault(Directory.Exists); return(p == null ? (SearchableIndex)null : SearchableIndex.Load(p)); }
public static SearchableIndex Load (string dir) { SearchableIndex s = new SearchableIndex (); s.dir = dir; s.Results = new ArrayList (20); try { s.searcher = new IndexSearcher (dir); } catch (IOException) { Console.WriteLine ("Index nonexistent or in bad format"); return null; } return s; }
public static SearchableIndex Load (string dir) { SearchableIndex s = new SearchableIndex (); s.dir = dir; try { //s.searcher = new IndexSearcher (dir); // TODO: parametrize that depending if we run on the desktop (low footprint) or the server (use RAMDirectory for instance) s.searcher = new IndexSearcher (FSDirectory.Open (dir)); } catch (IOException) { Console.WriteLine ("Index nonexistent or in bad format"); return null; } return s; }
public static SearchableIndex Load(string dir) { SearchableIndex s = new SearchableIndex(); s.dir = dir; s.Results = new ArrayList(20); try { s.searcher = new IndexSearcher(dir); } catch (IOException) { Console.WriteLine("Index nonexistent or in bad format"); return(null); } return(s); }
public static SearchableIndex Load(string dir) { SearchableIndex s = new SearchableIndex(); s.dir = dir; try { //s.searcher = new IndexSearcher (dir); // TODO: parametrize that depending if we run on the desktop (low footprint) or the server (use RAMDirectory for instance) s.searcher = new IndexSearcher(FSDirectory.Open(dir)); } catch (IOException) { Console.WriteLine("Index nonexistent or in bad format"); return(null); } return(s); }
void SetupSearch () { searchIndex = Program.Root.GetSearchIndex (); indexSearch = new IndexSearcher (Program.IndexUpdateManager.IsFresh ? Program.Root.GetIndex () : null); searchInput = new SearchTextBox (searchBox.TextBox); searchInput.SearchTextChanged += SearchCallback; indexSearchBox.SearchTextChanged += IndexSearchCallback; indexLoadingNode = new AnimatedTreeNode (indexListResults.Nodes [0]); indexLoadingNode.StartAnimation (); tabContainer.Selected += (s, e) => { if (tabContainer.SelectedIndex == 1 && !indexPageLoaded) { FillUpIndex (); indexPageLoaded = true; } if (match != null && ShowNodeInTree (match)) { docTree.SelectedNode = nodeToTreeNodeMap[match]; match = null; } }; indexListResults.AfterSelect += (s, e) => { var entry = e.Node.Tag as IndexEntry; if (entry.Count == 1) { LoadUrl (entry[0].Url); } else { LoadMultipleMatchData (entry); indexSplitContainer.Panel2Collapsed = false; e.Node.EnsureVisible (); } }; multipleMatchList.AfterSelect += (s, e) => { var topic = e.Node.Tag as Topic; LoadUrl (topic.Url); multipleMatchList.SelectedNode = e.Node; }; searchListResults.DrawNode += CustomDrawing.DrawSearchResultNodeText; searchListResults.BeforeSelect += (s, e) => e.Cancel = e.Node.Tag == null; searchListResults.AfterSelect += (s, e) => { var entry = e.Node.Tag as ResultDataEntry; LoadUrl (entry.ResultSet.GetUrl (entry.Index)); }; }
void Search (string text) { // We may have a null search index if it's the first time the app is launched // In that case try to grab a snapshot and if still nothing exits cleanly if (searchIndex == null) { searchIndex = AppDelegate.Root.GetSearchIndex (); if (searchIndex == null) return; } var dataSource = ((ResultDataSource)searchResults.Source); dataSource.LatestSearchTerm = text; Result results = searchIndex.FastSearch (text, 5); dataSource.ClearResultSet (); dataSource.AddResultSet (results); // No SynchronizationContext for MonoMac yet Task.Factory.StartNew (() => searchIndex.Search (text, 20)).ContinueWith (t => InvokeOnMainThread (() => { var rs = t.Result; if (rs == null || rs.Count == 0 || text != dataSource.LatestSearchTerm) return; dataSource.AddResultSet (rs); searchResults.ReloadData (); })); searchResults.ReloadData (); if (results.Count > 0) { searchResults.SelectRow (1, false); searchResults.ScrollRowToVisible (0); OnSearchRowSelected (1); } }
void ToggleSearchCreationStatus (object sender, EventArgs e) { var manager = (IndexUpdateManager)sender; if (!manager.IsCreatingSearchIndex) { InvokeOnMainThread (delegate { var indexSpinnerHeight = indexSpinnerView.Frame.Height * 3 /4; var searchSpinnerHeight = spinnerView.Frame.Height * 3 / 4; spinnerWidget.StopAnimation (this); spinnerView.Hidden = true; indexSpinnerWidget.StopAnimation (this); indexSpinnerView.Hidden = true; searchIndex = AppDelegate.Root.GetSearchIndex (); indexSearchEntry.Enabled = true; mdocSearch.Index = AppDelegate.Root.GetIndex (); indexResults.ReloadData (); var splitViewFrame = splitView.Frame; splitView.Frame = new RectangleF (splitViewFrame.X, splitViewFrame.Y - indexSpinnerHeight, splitViewFrame.Width, splitViewFrame.Height + indexSpinnerHeight); var searchScrollViewFrame = searchScrollView.Frame; searchScrollView.Frame = new RectangleF (searchScrollViewFrame.X, searchScrollViewFrame.Y - searchSpinnerHeight, searchScrollViewFrame.Width, searchScrollViewFrame.Height + searchSpinnerHeight); }); } else { InvokeOnMainThread (delegate { spinnerView.Hidden = false; spinnerWidget.StartAnimation (this); indexSpinnerView.Hidden = false; indexSpinnerWidget.StartAnimation (this); indexSearchEntry.Enabled = false; }); } }
void SetupSearch () { AppDelegate.IndexUpdateManager.UpdaterChange += ToggleSearchCreationStatus; searchIndex = AppDelegate.Root.GetSearchIndex (); mdocSearch = new IndexSearcher (AppDelegate.IndexUpdateManager.IsFresh ? AppDelegate.Root.GetIndex () : null); indexResults.Source = new IndexDataSource (mdocSearch); multipleMatchResults.Source = new MultipleMatchDataSource (this); searchResults.Source = new ResultDataSource (); splitView.Delegate = new SplitViewDelegate (); tabSelector.DidSelect += (sender, e) => { if (e.Item.TabView.IndexOf (e.Item) == 2) WindowForSheet.MakeFirstResponder (toolbarSearchEntry); }; }
void ToggleSearchCreationStatus (object sender, EventArgs e) { var manager = (IndexUpdateManager)sender; if (!manager.IsCreatingSearchIndex) { InvokeOnMainThread (delegate { spinnerWidget.StopAnimation (this); spinnerView.Hidden = true; searchIndex = AppDelegate.Root.GetSearchIndex (); indexSearchEntry.Enabled = true; mdocSearch.Index = AppDelegate.Root.GetIndex (); indexResults.ReloadData (); }); } else { InvokeOnMainThread (delegate { spinnerView.Hidden = false; spinnerWidget.StartAnimation (this); indexSearchEntry.Enabled = false; }); } }
void SetupSearch () { AppDelegate.IndexUpdateManager.UpdaterChange += ToggleSearchCreationStatus; searchIndex = AppDelegate.Root.GetSearchIndex (); mdocSearch = new IndexSearcher (AppDelegate.Root.GetIndex ()); indexResults.Source = new IndexDataSource (mdocSearch); multipleMatchResults.Source = new MultipleMatchDataSource (this); searchResults.Source = new ResultDataSource (); }
// Initianlizes the search index void CreateSearchPanel () { //get the search index if (search_index == null) { search_index = help_tree.GetSearchIndex(); //restore widgets search_vbox.Remove (ppanel); } // // Create the search panel // VBox vbox1 = new VBox (false, 0); search_vbox.PackStart (vbox1); // title HBox hbox1 = new HBox (false, 3); hbox1.BorderWidth = 3; Image icon = new Image (Stock.Find, IconSize.Menu); Label look_for_label = new Label ("Search for:"); look_for_label.Justify = Justification.Left; look_for_label.Xalign = 0; hbox1.PackEnd (look_for_label, true, true, 0); hbox1.PackEnd (icon, false, true, 0); hbox1.ShowAll (); vbox1.PackStart (hbox1, false, true, 0); // entry search_term = new Entry (); search_term.Activated += OnSearchActivated; vbox1.PackStart (search_term, false, true, 0); // treeview ScrolledWindow scrolledwindow_search = new ScrolledWindow (); scrolledwindow_search.HscrollbarPolicy = PolicyType.Automatic; scrolledwindow_search.VscrollbarPolicy = PolicyType.Always; vbox1.PackStart (scrolledwindow_search, true, true, 0); search_tree = new TreeView (); search_tree.HeadersVisible = false; scrolledwindow_search.AddWithViewport (search_tree); //prepare the treeview search_store = new TreeStore (typeof (string)); search_tree.Model = search_store; search_tree.AppendColumn ("Searches", new CellRendererText(), "text", 0); search_tree.Selection.Changed += new EventHandler (ShowSearchResult); search_tree.FocusOutEvent += new FocusOutEventHandler(LostFocus); vbox1.ShowAll (); search_vbox.ShowAll (); }
public Browser (string basedir, IEnumerable<string> sources, string engine) { #if MACOS try { InitMacAppHandlers(); } catch (Exception ex) { Console.Error.WriteLine ("Installing Mac AppleEvent handlers failed. Skipping.\n" + ex); } #endif this.engine = engine; ui = new Glade.XML (null, "browser.glade", "window1", null); ui.Autoconnect (this); MainWindow = (Gtk.Window) ui["window1"]; MainWindow.DeleteEvent += new DeleteEventHandler (delete_event_cb); MainWindow.KeyPressEvent += new KeyPressEventHandler (keypress_event_cb); MainWindow.KeyReleaseEvent += new KeyReleaseEventHandler (keyrelease_event_cb); Stream icon = GetResourceImage ("monodoc.png"); if (icon != null) { monodoc_pixbuf = new Gdk.Pixbuf (icon); MainWindow.Icon = monodoc_pixbuf; } //ellipsizing label for the title title_label = new ELabel (""); title_label.Xalign = 0; Pango.FontDescription fd = new Pango.FontDescription (); fd.Weight = Pango.Weight.Bold; title_label.ModifyFont (fd); title_label.Layout.FontDescription = fd; title_label_box.Add (title_label); title_label.Show (); //colour the bar according to the current style bar_style = bar_eb.Style.Copy (); bar_eb.Style = bar_style; MainWindow.StyleSet += new StyleSetHandler (BarStyleSet); BarStyleSet (null, null); help_tree = Driver.LoadTree (basedir, sources); tree_browser = new TreeBrowser (help_tree, reference_tree, this); // Bookmark Manager init; bookmark_manager = new BookmarkManager(this); // // Tab Notebook and first tab // tabs_nb = new Notebook(); //the Notebook that holds tabs tabs_nb.Scrollable = true; tabs_nb.SwitchPage += new SwitchPageHandler(ChangeTab); help_container.Add(tabs_nb); AddTab(); if ((capabilities & Capabilities.Fonts) != 0) { // Add Menu entries for changing the font Menu aux = (Menu) view1.Submenu; MenuItem sep = new SeparatorMenuItem (); sep.Show (); aux.Append (sep); AccelGroup accel = new AccelGroup (); MainWindow.AddAccelGroup (accel); textLarger = new MenuItem ("_Larger text"); textLarger.Activated += new EventHandler (TextLarger); textLarger.Show (); aux.Append (textLarger); AccelKey ak = new AccelKey (Gdk.Key.plus, Gdk.ModifierType.ControlMask, AccelFlags.Visible); textLarger.AddAccelerator ("activate", accel, ak); textSmaller = new MenuItem ("_Smaller text"); textSmaller.Activated += new EventHandler (TextSmaller); textSmaller.Show (); aux.Append (textSmaller); ak = new AccelKey (Gdk.Key.minus, Gdk.ModifierType.ControlMask, AccelFlags.Visible); textSmaller.AddAccelerator ("activate", accel, ak); textNormal = new MenuItem ("_Original size"); textNormal.Activated += new EventHandler (TextNormal); textNormal.Show (); aux.Append (textNormal); ak = new AccelKey (Gdk.Key.Key_0, Gdk.ModifierType.ControlMask, AccelFlags.Visible); textNormal.AddAccelerator ("activate", accel, ak); } // restore the editing setting editing1.Active = SettingsHandler.Settings.EnableEditing; comments1.Active = SettingsHandler.Settings.ShowComments; cut1.Sensitive = false; paste1.Sensitive = false; // // Other bits // search_index = help_tree.GetSearchIndex(); if (search_index == null) { ppanel = new ProgressPanel ("<b>No Search index found</b>", "Generate", RootTree.MakeSearchIndex, CreateSearchPanel); search_vbox.Add (ppanel); search_vbox.Show (); } else { CreateSearchPanel (); } bookList = new ArrayList (); index_browser = IndexBrowser.MakeIndexBrowser (this); MainWindow.ShowAll(); #if MACOS try { InstallMacMainMenu (); ((MenuBar)ui["menubar1"]).Hide (); } catch (Exception ex) { Console.Error.WriteLine ("Installing Mac IGE Main Menu failed. Skipping.\n" + ex); } #endif }
void SearchCallback (object sender, EventArgs e) { var input = sender as SearchTextBox; if (searchIndex == null) { searchIndex = Program.Root.GetSearchIndex (); if (searchIndex == null) return; } var text = input.Text; if (string.IsNullOrEmpty (text)) return; tabContainer.SelectedIndex = 2; searchListResults.Tag = text; // Last searched term Result results = searchIndex.FastSearch (text, 5); dataSource.ClearResultSet (); dataSource.AddResultSet (results); Task.Factory.StartNew (() => searchIndex.Search (text, 20)).ContinueWith (t => Invoke (new Action (() => { var rs = t.Result; if (rs == null || rs.Count == 0 || text != ((string)searchListResults.Tag)) return; dataSource.AddResultSet (rs); ReloadSearchData (); })), TaskScheduler.FromCurrentSynchronizationContext ()); ReloadSearchData (); if (results.Count > 0) { var firstNode = searchListResults.Nodes[1]; searchListResults.SelectedNode = firstNode; firstNode.EnsureVisible (); } }
void IndexUpdaterCallback (object sender, EventArgs e) { var manager = (IndexUpdateManager)sender; if (!manager.IsCreatingSearchIndex) { Invoke (new Action (delegate { indexesLabel.Visible = false; indexesProgressBar.Visible = false; searchIndex = Program.Root.GetSearchIndex (); searchBox.Enabled = true; indexSearch.Index = Program.Root.GetIndex (); if (tabContainer.SelectedIndex == 1) FillUpIndex (); else indexPageLoaded = false; })); } else { Invoke (new Action (delegate { indexesLabel.Visible = true; indexesProgressBar.Visible = true; searchBox.Enabled = false; indexSearchBox.Enabled = false; })); } }