示例#1
0
        /**
         * Runs a text search in Fauvel, using all specified search settings.
         * Each type of search (poetry, music lyrics, and images) is in its own thread.
         * */
        private void runSearch()
        {
            String searchQuery = searchQueryBox.Text;
            SurfaceKeyboard.IsVisible = false;

            searchTabHeader.Text = searchQueryBox.Text;
            searchResults.Visibility = Visibility.Visible;

            if (optionsShown)
            {
                selectLanguage.Visibility = Visibility.Hidden;
                selectLanguageButton.Visibility = Visibility.Visible;
            }

            int caseType = 0;
            int wordType = 0;
            if (caseSensitive.IsChecked == true)
                caseType = 1;
            if (wholeWordOnly.IsChecked == true)
                wordType = 1;

            exactPhr = exactPhraseOnly.IsChecked;

            if (optionsShown == true)
                compressResults();

            poetryTab.Content = getLoadingImage();
            lyricsTab.Content = getLoadingImage();
            imagesTab.Content = getLoadingImage();
            poetryTab.Header = "Poetry (...)";
            lyricsTab.Header = "Lyrics (...)";
            imagesTab.Header = "Images (...)";
            searchQueryBox.IsEnabled = false;
            caseSensitive.IsEnabled = false;
            wholeWordOnly.IsEnabled = false;
            exactPhraseOnly.IsEnabled = false;
            moreOptions.IsEnabled = false;
            fewerOptions.IsEnabled = false;
            selectLanguageButton.IsEnabled = false;
            goSearch.Content = "searching";
            goSearch.IsEnabled = false;
            unreturnedResults = 3;

            poetryScroll.ScrollToTop();
            lyricsScroll.ScrollToTop();
            imagesScroll.ScrollToTop();
            poetryPanel.Children.Clear();
            lyricsPanel.Children.Clear();
            imagesPanel.Children.Clear();

            // Poetry results //
            poetryResults = new List<SearchResult>();

            Action poetryResultAction = delegate
            {
                BackgroundWorker worker = new BackgroundWorker();

                worker.DoWork += delegate
                {
                    if (exactPhr == false)
                        poetryResults = Search.searchMultipleWordsPoetry(searchQuery, caseType, wordType, (int)currentSearchLanguage);
                    else
                        poetryResults = Search.searchExactPoetry(searchQuery, caseType, wordType, (int)currentSearchLanguage);
                };
                worker.RunWorkerCompleted += delegate
                {
                    ListBox poetryLB = new ListBox();
                    poetryLB.Style = sideBar.tabBar.FindResource("SearchResultSurfaceListBox") as Style;
                    poetryScroll.Content = poetryLB; // NB: the scroll bar comes from the poetryScroll, not poetryLB

                    foreach (SearchResult result in poetryResults)
                    {
                        ResultBoxItem resultRBI = new ResultBoxItem();
                        convertSearchResultToResultBoxItem(result, resultRBI);
                        resultRBI.resultThumbnail.Source = Thumbnailer.getThumbnail(result.tag);
                        if (((optionsShown == false) && poetryResults.Count < 4) || ((optionsShown == true) && poetryResults.Count < 2))
                            resultRBI.Width = 480;
                        poetryLB.Items.Add(resultRBI);
                    }

                    poetryTab.Header = "Poetry (" + poetryResults.Count + ")";

                    if (poetryResults.Count == 0)
                    {
                        TextBlock noResults = new TextBlock();
                        noResults.Text = "Sorry, your search returned no poetry results.";
                        poetryTab.Content = noResults;
                    }
                    else
                        poetryTab.Content = poetryCanvas;

                    poetryScroll.Background = Brushes.LightGray;
                    poetryBorder.BorderBrush = Brushes.DarkGray;
                    returnAResult();
                };
                worker.RunWorkerAsync();
            };
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, poetryResultAction);

            // Lyric results //
            lyricResults = new List<SearchResult>();

            Action lyricResultAction = delegate
            {
                BackgroundWorker worker = new BackgroundWorker();

                worker.DoWork += delegate
                {
                    if (exactPhr == false)
                        lyricResults = Search.searchMultipleWordsLyrics(searchQuery, caseType, wordType, (int) currentSearchLanguage);
                    else
                        lyricResults = Search.searchExactLyrics(searchQuery, caseType, wordType, Search.whichXml((int)currentSearchLanguage));
                };

                worker.RunWorkerCompleted += delegate
                {
                    ListBox lyricsLB = new ListBox();

                    foreach (SearchResult result in lyricResults)
                    {
                        ResultBoxItem resultRBI = new ResultBoxItem();
                        convertSearchResultToResultBoxItem(result, resultRBI);
                        resultRBI.resultThumbnail.Source = Thumbnailer.getThumbnail(result.tag);
                        lyricsLB.Items.Add(resultRBI);
                    }

                    lyricsLB.Style = sideBar.tabBar.FindResource("SearchResultSurfaceListBox") as Style;

                    lyricsScroll.Content = lyricsLB;

                    lyricsTab.Header = "Lyrics (" + lyricResults.Count + ")";

                    if (lyricResults.Count == 0)
                    {
                        TextBlock noResults = new TextBlock();
                        noResults.Text = "Sorry, your search returned no music lyric results.\r\n\r\nNB: Lyrics don't exist in English yet!";
                        lyricsTab.Content = noResults;
                    }
                    else
                        lyricsTab.Content = lyricsCanvas;

                    lyricsScroll.Background = Brushes.LightGray;
                    lyricsBorder.BorderBrush = Brushes.DarkGray;
                    returnAResult();
                };
                worker.RunWorkerAsync();
            };
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, lyricResultAction);

            // Image results //
            imageResults = new List<SearchResult>();

            Action imageResultAction = delegate
            {
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += delegate
                {

                    if (exactPhr == false)
                        imageResults = Search.searchMultipleWordsPicCaptions(searchQuery, caseType, wordType, Search.whichXml((int) currentSearchLanguage));
                    else
                        imageResults = Search.searchExactPicCaptions(searchQuery, caseType, wordType, Search.whichXml((int)currentSearchLanguage));
                };
                worker.RunWorkerCompleted += delegate
                {
                    ListBox imagesLB = new ListBox();
                    imagesLB.Style = sideBar.tabBar.FindResource("SearchResultSurfaceListBox") as Style;
                    imagesScroll.Content = imagesLB;

                    foreach (SearchResult result in imageResults)
                    {
                        ResultBoxItem resultRBI = new ResultBoxItem();
                        convertSearchResultToResultBoxItem(result, resultRBI);
                        resultRBI.miniThumbnail.Source = new BitmapImage(new Uri(@"..\..\minithumbnails\" + result.tag + ".jpg", UriKind.Relative));
                        resultRBI.miniThumbnail.Width = 50;
                        resultRBI.miniThumbnail.Height = 50;
                        resultRBI.resultThumbnail.Source = Thumbnailer.getThumbnail(result.tag);
                        imagesLB.Items.Add(resultRBI);
                    }

                    imagesTab.Header = "Images (" + imageResults.Count + ")";

                    if (imageResults.Count == 0)
                    {
                        TextBlock noResults = new TextBlock();
                        noResults.Text = "Sorry, your search returned no image results.\r\n\r\nNB: Image captions don't exist in English yet!";
                        imagesTab.Content = noResults;
                    }
                    else
                        imagesTab.Content = imagesCanvas;

                    imagesScroll.Background = Brushes.LightGray;
                    imagesBorder.BorderBrush = Brushes.DarkGray;
                    returnAResult();
                };
                worker.RunWorkerAsync();
            };
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, imageResultAction);
        }
示例#2
0
 /**
  * This method checks if the target page in goToFolio is a "recto", on the right side.
  * If it is, since each opening of 2 pages is stored as a single combined image, each of the X coordinates must be adjusted accordingly by adding 5250 (width of a page).
  * */
 private void editCoordinates(ResultBoxItem rbi)
 {
     if (rbi.folioInfo.Text.EndsWith("r"))
     {
         rbi.topL.X += 5250;
         rbi.bottomR.X += 5250;
     }
 }
示例#3
0
        /**
         * Selects a search result for closeup (bottom rectangle of search panel).
         * Shows a thumbnail (image) and a text excerpt.
         * */
        private void Result_Closeup(object sender, RoutedEventArgs e)
        {
            ResultBoxItem selectedResult = e.Source as ResultBoxItem;
            lastCloseupRBI = selectedResult;  // For later reference in goToFolio

            Image closeupImage = new Image();
            closeupImage.Source = selectedResult.resultThumbnail.Source;
            closeupImage.Width = 185;
            closeupImage.Height = 176;
            closeupImage.Margin = new Thickness(0, 0, 10, 0);

            TextBlock closeupText = new TextBlock();
            closeupText.TextWrapping = TextWrapping.Wrap;
            closeupText.FontSize = 15;
            closeupText.Width = 275;
            closeupText.VerticalAlignment = VerticalAlignment.Center;

            if (selectedResult.resultType == 1)
            {
                poetryPanel.Children.Clear();
                poetryPanel.Children.Add(closeupImage);
                poetryPanel.Children.Add(closeupText);
                poetryPanel.TouchDown += delegate(object s, TouchEventArgs r) { goToFolio(sender, r, selectedResult.folioInfo.Text); };
                poetryPanel.MouseLeftButtonDown += delegate(object s, MouseButtonEventArgs r) { goToFolio(sender, r, selectedResult.folioInfo.Text); };
            }

            else if (selectedResult.resultType == 2)
            {
                lyricsPanel.Children.Clear();
                lyricsPanel.Children.Add(closeupImage);
                lyricsPanel.Children.Add(closeupText);
                lyricsPanel.TouchDown += delegate(object s, TouchEventArgs r) { goToFolio(sender, r, selectedResult.folioInfo.Text); };
                lyricsPanel.MouseLeftButtonDown += delegate(object s, MouseButtonEventArgs r) { goToFolio(sender, r, selectedResult.folioInfo.Text); };
            }

            else if (selectedResult.resultType == 3)
            {
                imagesPanel.Children.Clear();
                imagesPanel.Children.Add(closeupImage);
                imagesPanel.Children.Add(closeupText);
                imagesPanel.TouchDown += delegate(object s, TouchEventArgs r) { goToFolio(sender, r, selectedResult.folioInfo.Text); };
                imagesPanel.MouseLeftButtonDown += delegate(object s, MouseButtonEventArgs r) { goToFolio(sender, r, selectedResult.folioInfo.Text); };
            }

            // Bolds all search terms
            foreach (SpecialString ss in selectedResult.excerpts)
            {
                if (ss.isStyled == 1)
                    closeupText.Inlines.Add(new Run { FontFamily = new FontFamily("Cambria"), Text = ss.str, FontWeight = FontWeights.Bold });
                else
                    closeupText.Inlines.Add(new Run { FontFamily = new FontFamily("Cambria"), Text = ss.str, FontWeight = FontWeights.Normal });
            }
        }
示例#4
0
        /**
         * Transfers information about a search result into a ResultBoxItem for ListBox display.
         * */
        private void convertSearchResultToResultBoxItem(SearchResult sr, ResultBoxItem rbi)
        {
            rbi.folioInfo.Text = sr.folio;
            rbi.topL = sr.topL;
            rbi.bottomR = sr.bottomR;
            rbi.matchStrength = sr.matchStrength;
            rbi.resultType = sr.resultType;
            if (rbi.resultType == 1)
                rbi.lineInfo.Text = Convert.ToString(sr.lineNum) + sr.lineRange; // Assuming only one will be filled out
            rbi.excerpts = sr.excerpts;
            rbi.Height = 80; // temp taller than desired, so scrollbar shows
            rbi.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            rbi.Width = 475; //430
            rbi.Style = sideBar.tabBar.FindResource("SearchResultSurfaceListBoxItem") as Style; // Not sure if this works..

            if (rbi.resultType == 2 || rbi.resultType == 3) // For lyrics or images
                rbi.resultText.Text = sr.text1 + "\r\n" + sr.text2;
            else // For poetry
            {
                rbi.resultText.Inlines.Add(new Run { FontFamily = new FontFamily("Cambria"), Text = sr.text1 + "\r\n", FontStyle = FontStyles.Normal });
                rbi.resultText.Inlines.Add(new Run { FontFamily = new FontFamily("Cambria"), Text = sr.text2, FontStyle = FontStyles.Italic });
            }

            rbi.BorderBrush = Brushes.LightGray;
            rbi.BorderThickness = new Thickness(1.0);
            rbi.Selected += new RoutedEventHandler(Result_Closeup);
        }