private void word_connector_ContextChanged_BACKGROUND_FindRecommendations()
        {
            while (true)
            {
                // Get the next context to search for, and if there is none, then exit the background thread
                string context;

                Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
                lock (context_thread_lock)
                {
                    l1_clk.LockPerfTimerStop();
                    context = context_thread_next_context;
                    context_thread_next_context = null;

                    if (null == context)
                    {
                        context_thread_running = false;
                        break;
                    }
                }

                // Now that we have the context, do the query
                List <PDFDocument> context_pdf_documents = new List <PDFDocument>();
                {
                    WebLibraryDetail web_library_detail = this.web_library_detail;
                    if (null != web_library_detail)
                    {
                        string context_search_string = PolishContextForLucene(context);
                        context_search_string = context_search_string.Trim();
                        if (!String.IsNullOrEmpty(context_search_string))
                        {
                            List <IndexResult> fingerprints = LibrarySearcher.FindAllFingerprintsMatchingQuery(web_library_detail.library, context_search_string);
                            if (null != fingerprints && 0 != fingerprints.Count)
                            {
                                foreach (var fingerprint in fingerprints)
                                {
                                    if (20 <= context_pdf_documents.Count)
                                    {
                                        break;
                                    }

                                    PDFDocument pdf_document = web_library_detail.library.GetDocumentByFingerprint(fingerprint.fingerprint);
                                    if (null != pdf_document)
                                    {
                                        context_pdf_documents.Add(pdf_document);
                                    }
                                }
                            }
                        }
                    }
                }

                // And get the GUI to update with the results
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    word_connector_ContextChanged_BACKGROUND_PopulateRecommendations(context_pdf_documents);
                }
                                                  ), DispatcherPriority.Background);
            }
        }
Exemplo n.º 2
0
        public void DoSearch()
        {
            string query = SearchQuick.Text;

            // Do we have anything to do?
            if (String.IsNullOrEmpty(query))
            {
                SystemSounds.Beep.Play();
                return;
            }

            // Search each library
            List <CombinedSearchResultItem> results = new List <CombinedSearchResultItem>();

            foreach (WebLibraryDetail web_library_detail in WebLibraryManager.Instance.WebLibraryDetails_WorkingWebLibraries)
            {
                Logging.Info("Searching library {0}", web_library_detail.Title);

                Library library = web_library_detail.Xlibrary;

                List <IndexResult> index_results = LibrarySearcher.FindAllFingerprintsMatchingQuery(web_library_detail, query);

                foreach (IndexResult index_result in index_results)
                {
                    PDFDocument pdf_document = library.GetDocumentByFingerprint(index_result.fingerprint);
                    if (null != pdf_document)
                    {
                        CombinedSearchResultItem result = new CombinedSearchResultItem
                        {
                            fingerprint  = index_result.fingerprint,
                            score        = index_result.score,
                            pdf_document = pdf_document
                        };
                        results.Add(result);
                    }
                    else
                    {
                        Logging.Debug特("Received a null document from library search?! (Fingerprint: {0})", index_result.fingerprint);
                    }
                }
            }

            // Sort the results
            results.Sort(delegate(CombinedSearchResultItem p1, CombinedSearchResultItem p2) { return(-Sorting.Compare(p1.score, p2.score)); });

            // Create the ordered results
            List <PDFDocument>          pdf_documents = new List <PDFDocument>();
            Dictionary <string, double> search_scores = new Dictionary <string, double>();

            foreach (CombinedSearchResultItem result in results)
            {
                pdf_documents.Add(result.pdf_document);
                search_scores[result.fingerprint] = result.score;
            }

            ObjLibraryCatalog.SetPDFDocuments(pdf_documents, null, query, search_scores);
        }
        internal void ExecuteSearchQuick(string query)
        {
            ASSERT.Test(query != null);
            SearchQuick.Text = query;

            if (!String.IsNullOrEmpty(query))
            {
                FeatureTrackingManager.Instance.UseFeature(Features.Library_KeywordFilter);

                List <IndexResult> index_results = LibrarySearcher.FindAllFingerprintsMatchingQuery(library_filter_control.web_library_detail, query);

                library_filter_control.search_quick_query        = query;
                library_filter_control.search_quick_scores       = new Dictionary <string, double>();
                library_filter_control.search_quick_fingerprints = new HashSet <string>();
                foreach (var index_result in index_results)
                {
                    library_filter_control.search_quick_fingerprints.Add(index_result.fingerprint);
                    library_filter_control.search_quick_scores[index_result.fingerprint] = index_result.score;
                }
            }
            else
            {
                library_filter_control.search_quick_query        = null;
                library_filter_control.search_quick_fingerprints = null;
                library_filter_control.search_quick_scores       = null;
            }

            // Create the feedback
            library_filter_control.search_quick_fingerprints_span = new Span();
            Bold bold = new Bold();

            bold.Inlines.Add("Search");
            library_filter_control.search_quick_fingerprints_span.Inlines.Add(bold);
            library_filter_control.search_quick_fingerprints_span.Inlines.Add(" (click search score for details)");
            library_filter_control.search_quick_fingerprints_span.Inlines.Add(": ");
            library_filter_control.search_quick_fingerprints_span.Inlines.Add("'");
            library_filter_control.search_quick_fingerprints_span.Inlines.Add(query);
            library_filter_control.search_quick_fingerprints_span.Inlines.Add("'");
            library_filter_control.search_quick_fingerprints_span.Inlines.Add(LibraryFilterHelpers.GetClearImageInline("Clear this filter.", hyperlink_search_quick_fingerprints_span_OnClick));
        }