public void TestSimilarityMetrics() { var documentIndexer = ServiceLocator.Resolve <DocumentIndexer>(); var analyzer = ServiceLocator.Resolve <Analyzer>(); PreRetrievalMetrics preMetrics = new PreRetrievalMetrics(documentIndexer.Reader, analyzer); Assert.IsTrue(preMetrics.AvgSqc("indexer") > preMetrics.AvgSqc("potato chip")); Assert.IsTrue(preMetrics.AvgSqc("indexer") > preMetrics.AvgSqc("soda pop")); }
public void Search(String searchString, SimpleSearchCriteria searchCriteria = null, bool interactive = true) { if (!EnsureSolutionOpen()) { return; } try { var codeSearcher = new CodeSearcher(new IndexerSearcher()); if (String.IsNullOrEmpty(searchString)) { return; } var solutionKey = ServiceLocator.ResolveOptional <SolutionKey>(); //no opened solution if (solutionKey == null) { _searchResultListener.UpdateMessage("Sando searches only the currently open Solution. Please open a Solution and try again."); return; } searchString = ExtensionPointsRepository.Instance.GetQueryRewriterImplementation().RewriteQuery(searchString); PreRetrievalMetrics preMetrics = new PreRetrievalMetrics(ServiceLocator.Resolve <DocumentIndexer>().Reader, ServiceLocator.Resolve <Analyzer>()); LogEvents.PreSearch(this, preMetrics.MaxIdf(searchString), preMetrics.AvgIdf(searchString), preMetrics.AvgSqc(searchString), preMetrics.AvgVar(searchString)); LogEvents.PreSearchQueryAnalysis(this, QueryMetrics.ExamineQuery(searchString).ToString(), QueryMetrics.DiceCoefficient(QueryMetrics.SavedQuery, searchString)); QueryMetrics.SavedQuery = searchString; var criteria = GetCriteria(searchString, searchCriteria); var results = codeSearcher.Search(criteria, true).AsQueryable(); var resultsReorderer = ExtensionPointsRepository.Instance.GetResultsReordererImplementation(); results = resultsReorderer.ReorderSearchResults(results); var returnString = new StringBuilder(); if (criteria.IsQueryReformed()) { returnString.Append(criteria.GetQueryReformExplanation()); } if (!results.Any()) { returnString.Append("No results found. "); } else { returnString.Append(results.Count() + " results returned. "); } if (ServiceLocator.Resolve <InitialIndexingWatcher>().IsInitialIndexingInProgress()) { returnString.Append("Sando is still performing its initial index of this project, results may be incomplete."); } _searchResultListener.Update(searchString, results); _searchResultListener.UpdateMessage(returnString.ToString()); _searchResultListener.UpdateRecommendedQueries(criteria.GetRecommendedQueries()); LogEvents.PostSearch(this, results.Count(), criteria.NumberOfSearchResultsReturned, PostRetrievalMetrics.AvgScore(results.ToList()), PostRetrievalMetrics.StdDevScore(results.ToList())); } catch (Exception e) { _searchResultListener.UpdateMessage("Sando is experiencing difficulties. See log file for details."); LogEvents.UISandoSearchingError(this, e); } }