public void SimpleSearchCriteria_ToQueryStringCreatesValidQueryStringForEmptySearchCriteria() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria(); string queryString = simpleSearchCriteria.ToQueryString(); Assert.AreEqual(queryString, String.Empty, "Created query string is invalid!"); }
public void SimpleSearchCriteria_ToQueryStringCreatesValidQueryString_QuotedSearchTerm() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByUsageType = true, UsageTypes = new SortedSet <UsageType>() { UsageType.Definitions }, SearchTerms = new SortedSet <string>(WordSplitter.ExtractSearchTerms("\"Class Simple\"")) }; string queryString = simpleSearchCriteria.ToQueryString(); Assert.AreEqual(queryString, "(" + SandoField.Name.ToString() + ":*Class?Simple*^3)", "Created query string is invalid!"); try { var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, SandoField.Name.ToString(), new SimpleAnalyzer()); parser.SetAllowLeadingWildcard(true); Query query = parser.Parse(queryString); Assert.NotNull(query, "Generated query object is null!"); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void SimpleSearchCriteria_ToQueryStringCreatesValidProgramElementTypesQueryString_MultipleConditions() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByProgramElementType = true, ProgramElementTypes = new SortedSet <ProgramElementType>() { ProgramElementType.Property, ProgramElementType.Class, ProgramElementType.Enum } }; string queryString = simpleSearchCriteria.ToQueryString(); Assert.AreEqual(queryString, "(" + SandoField.ProgramElementType.ToString() + ":property OR " + SandoField.ProgramElementType.ToString() + ":enum OR " + SandoField.ProgramElementType.ToString() + ":class)", "Created query string is invalid!"); try { Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, SandoField.ProgramElementType.ToString(), new SimpleAnalyzer()).Parse(queryString); Assert.NotNull(query, "Generated query object is null!"); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void SimpleSearchCriteria_ToQueryStringCreatesValidUsageTypesQueryString_MultipleConditions() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByUsageType = true, UsageTypes = new SortedSet <UsageType>() { UsageType.ExtendedClasses, UsageType.Definitions, UsageType.NamespaceNames }, SearchTerms = new SortedSet <string>() { "SimpleClass" } }; string queryString = simpleSearchCriteria.ToQueryString(); Assert.AreEqual(queryString, "(" + SandoField.Name.ToString() + ":SimpleClass^3 OR " + SandoField.ExtendedClasses.ToString() + ":SimpleClass^0.2 OR " + SandoField.Namespace.ToString() + ":SimpleClass^0.05)", "Created query string is invalid!"); try { Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, SandoField.Name.ToString(), new SimpleAnalyzer()).Parse(queryString); Assert.NotNull(query, "Generated query object is null!"); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void SimpleSearchCriteria_ToQueryStringCreatesValidUsageTypesQueryString_NoCondition() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByUsageType = false, SearchTerms = new SortedSet <string>() { "SimpleClass" } }; string queryString = simpleSearchCriteria.ToQueryString(); string actual = "(" + SandoField.Body.ToString() + ":SimpleClass^4 OR " + SandoField.Name.ToString() + ":SimpleClass^3 OR " + SandoField.ExtendedClasses.ToString() + ":SimpleClass^0.2 OR " + SandoField.ImplementedInterfaces.ToString() + ":SimpleClass^0.2 OR " + SandoField.Arguments.ToString() + ":SimpleClass^0.1 OR " + SandoField.ReturnType.ToString() + ":SimpleClass^0.2 OR " + SandoField.Namespace.ToString() + ":SimpleClass^0.05 OR " + SandoField.DataType.ToString() + ":SimpleClass OR " + SandoField.Source.ToString() + ":SimpleClass OR " + SandoField.ClassName.ToString() + ":SimpleClass)"; Assert.AreEqual(queryString, actual, "Created query string is invalid!"); try { Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, SandoField.Name.ToString(), new SimpleAnalyzer()).Parse(queryString); Assert.NotNull(query, "Generated query object is null!"); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void SimpleSearchCriteria_ToQueryStringCreatesValidQueryString_SpecialCharacters() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByUsageType = true, UsageTypes = new SortedSet <UsageType>() { UsageType.Bodies }, SearchTerms = new SortedSet <string>() { "\"+ - && || ! ( ) { } [ ] ^ ~ : \"" } }; string queryString = simpleSearchCriteria.ToQueryString(); Assert.AreEqual("(Body:*\\+?\\-?\\&\\&?\\|\\|?\\!?\\(?\\)?\\{?\\}?\\[?\\]?\\^?\\~?\\:?*^4)", queryString, "Created query string is invalid!"); try { var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, SandoField.Name.ToString(), new SimpleAnalyzer()); parser.SetAllowLeadingWildcard(true); Query query = parser.Parse(queryString); Assert.NotNull(query, "Generated query object is null!"); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void SearchReturnsElementsUsingCrossFieldMatching() { var codeSearcher = new CodeSearcher(new IndexerSearcher()); string keywords = "fetch output argument"; SearchCriteria searchCriteria = new SimpleSearchCriteria() { SearchTerms = new SortedSet <string>(keywords.Split(' ')) }; List <CodeSearchResult> codeSearchResults = codeSearcher.Search(searchCriteria); var methodSearchResult = codeSearchResults.Find(el => el.ProgramElement.ProgramElementType == ProgramElementType.Method && (el.ProgramElement.Name == "FetchOutputStream")); if (methodSearchResult == null) { Assert.Fail("Failed to find relevant search result for search: " + keywords); } var method = methodSearchResult.ProgramElement as MethodElement; Assert.AreEqual(method.AccessLevel, AccessLevel.Public, "Method access level differs!"); Assert.AreEqual(method.Arguments, "A B string fileName Image image", "Method arguments differs!"); Assert.NotNull(method.Body, "Method body is null!"); Assert.True(method.ClassId != null && method.ClassId != Guid.Empty, "Class id is invalid!"); Assert.AreEqual(method.ClassName, "ImageCapture", "Method class name differs!"); Assert.AreEqual(method.DefinitionLineNumber, 83, "Method definition line number differs!"); Assert.True(method.FullFilePath.EndsWith("\\TestFiles\\MethodElementTestFiles\\ImageCapture.cs".ToLowerInvariant()), "Method full file path is invalid!"); Assert.AreEqual(method.Name, "FetchOutputStream", "Method name differs!"); Assert.AreEqual(method.ProgramElementType, ProgramElementType.Method, "Program element type differs!"); Assert.AreEqual(method.ReturnType, "void", "Method return type differs!"); Assert.False(String.IsNullOrWhiteSpace(method.RawSource), "Method snippet is invalid!"); }
public void MethodSearchRespectsFileExtensionsCriteria() { var codeSearcher = new CodeSearcher(new IndexerSearcher()); var keywords = "main"; var searchCriteria = new SimpleSearchCriteria() { SearchTerms = new SortedSet <string>(keywords.Split(' ')), SearchByFileExtension = true, FileExtensions = new SortedSet <string> { ".cpp" } }; var codeSearchResults = codeSearcher.Search(searchCriteria); Assert.AreEqual(1, codeSearchResults.Count, "Invalid results number"); var methodSearchResult = codeSearchResults.Find(el => el.ProgramElement.ProgramElementType == ProgramElementType.Method && el.ProgramElement.Name == "main"); if (methodSearchResult == null) { Assert.Fail("Failed to find relevant search result for search: " + keywords); } //var method = methodSearchResult.Element as MethodElement; //Assert.AreEqual(method.AccessLevel, AccessLevel.Public, "Method access level differs!"); //Assert.AreEqual(method.Arguments, String.Empty, "Method arguments differs!"); //Assert.NotNull(method.Body, "Method body is null!"); //Assert.True(method.ClassId != null && method.ClassId != Guid.Empty, "Class id is invalid!"); //Assert.AreEqual(method.ClassName, "SimpleSearchCriteria", "Method class name differs!"); //Assert.AreEqual(method.DefinitionLineNumber, 31, "Method definition line number differs!"); //Assert.True(method.FullFilePath.EndsWith("\\TestFiles\\MethodElementTestFiles\\Searcher.cs"), "Method full file path is invalid!"); //Assert.AreEqual(method.Name, "ToQueryString", "Method name differs!"); //Assert.AreEqual(method.ProgramElementType, ProgramElementType.Method, "Program element type differs!"); //Assert.AreEqual(method.ReturnType, "void", "Method return type differs!"); //Assert.False(String.IsNullOrWhiteSpace(method.RawSource), "Method snippet is invalid!"); }
public static SearchModel MapToSearchModel(this SimpleSearchCriteria criteria) { return(new SearchModel { MaxCost = criteria.MaxCost.ToString(CultureInfo.InvariantCulture), NumberOfRooms = criteria.NumberOfRooms.ToString(CultureInfo.InvariantCulture) }); }
public void SimpleSearchCriteria_QuotedNoWeirdCharsToQueryString() { SimpleSearchCriteria simpleSearchCriteria = new SimpleSearchCriteria(); simpleSearchCriteria.SearchTerms.Add("\"ServiceLocatorResolve\""); string queryString = simpleSearchCriteria.ToQueryString(); Assert.IsTrue(queryString.Contains("Source:*ServiceLocatorResolve*"), "Created query string is invalid!"); }
public void SimpleSearchCriteria_QuotedWithSpaces() { SimpleSearchCriteria simpleSearchCriteria = new SimpleSearchCriteria(); simpleSearchCriteria.SearchTerms.Add("\"foreach(var term in SearchTerms)\""); string queryString = simpleSearchCriteria.ToQueryString(); Assert.IsTrue(queryString.Contains("Source:*foreach\\(var?term?in?SearchTerms\\)*"), "Created query string is invalid!"); }
public void SimpleSearchCriteria_ExactMatchToQueryString() { SimpleSearchCriteria simpleSearchCriteria = new SimpleSearchCriteria(); simpleSearchCriteria.SearchTerms.Add("\"ServiceLocator.Resolve<DTE2>();\""); string queryString = simpleSearchCriteria.ToQueryString(); // Source:*ServiceLocator.Resolve<DTE2>\(\);* Assert.IsTrue(queryString.Contains("Source:*ServiceLocator.Resolve<DTE2>\\(\\);*"), "Created query string is invalid!"); }
private void SearchAsync(String text, SimpleSearchCriteria searchCriteria) { var sandoWorker = new BackgroundWorker(); sandoWorker.DoWork += sandoWorker_DoWork; var workerSearchParams = new WorkerSearchParameters { Query = text, Criteria = searchCriteria }; sandoWorker.RunWorkerAsync(workerSearchParams); }
private IEnumerable <CodeSearchResult> GetResults(string searchString) { var searcher = new IndexerSearcher(); var criteria = new SimpleSearchCriteria { SearchTerms = new SortedSet <string>(searchString.Split(' ').ToList()) }; var results = searcher.Search(criteria); return(results); }
private SearchCriteria GetCriteria(string searchString, SimpleSearchCriteria searchCriteria = null) { var sandoOptions = ServiceLocator.Resolve <ISandoOptionsProvider>().GetSandoOptions(); var description = new SandoQueryParser().Parse(searchString); var builder = CriteriaBuilder.GetBuilder(). AddCriteria(searchCriteria). NumResults(sandoOptions.NumberOfSearchResultsReturned).AddFromDescription(description); var simple = builder.GetCriteria() as SimpleSearchCriteria; SearchCriteriaReformer.ReformSearchCriteria(simple); return(simple); }
public IActionResult Get(SimpleSearchCriteria model) { if (!ModelState.IsValid) { return(BadRequest()); } var result = _offerSearchService.SimpleSearch(model); var offers = GetGrouppedOffers(result); return(Ok(offers)); }
public void SimpleSearchCriteria_BasicQueryWeightsInFinnish() { SimpleSearchCriteria simpleSearchCriteria = new SimpleSearchCriteria(); simpleSearchCriteria.SearchTerms.Add("hi"); string queryString = simpleSearchCriteria.ToQueryString(); Assert.IsTrue(queryString.Contains("ImplementedInterfaces:hi^0.2 "), "Created query string is invalid!"); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fi-FI"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("fi-FI"); queryString = simpleSearchCriteria.ToQueryString(); Assert.IsTrue((0.2).ToString().Equals("0,2")); Assert.IsTrue(queryString.Contains("ImplementedInterfaces:hi^0.2 "), "Created query string is invalid!"); }
public void SearchCriteria_EqualsReturnTrueWhenObjectIsComparedToItsOwn() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByProgramElementType = true, ProgramElementTypes = new SortedSet <ProgramElementType>() { ProgramElementType.Class, ProgramElementType.Method } }; Assert.True(simpleSearchCriteria.Equals(simpleSearchCriteria), "Equals should return true when search criteria object is compared to its own!"); }
public ICollection <OfferModel> SimpleSearch(SimpleSearchCriteria criteria) { var searchModel = criteria.MapToSearchModel(); var queryProvider = new SimpleSearchQueryProvider(searchModel); var query = queryProvider.GetSearchExpression(); var result = _repository.GetWithExpression(query, 1000, 1); var offerModels = result .Select(x => x.MapToOfferModel()) .ToList(); return(offerModels); }
public void SimpleSearchCriteria_ToQueryStringThrowsWhenSearchingByProgramElementTypeWithNoProgramElementTypeCriteria() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByProgramElementType = true }; try { string queryString = simpleSearchCriteria.ToQueryString(); } catch { } Assert.True(contractFailed, "Contract should fail!"); }
public void SimpleSearchCriteria_ToQueryStringThrowsWhenSearchingByAccessLevelWithNoAccessLevelCriteria() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByAccessLevel = true }; try { string queryString = simpleSearchCriteria.ToQueryString(); } catch { } Assert.True(contractFailed, "Contract should fail!"); }
private void BeginSearch(string searchString) { RemoveOldResults(); AddSearchHistory(searchString); SimpleSearchCriteria Criteria = new SimpleSearchCriteria(); //Store the search key this.searchKey = searchBox.Text; //Clear the old recommendation. UpdateRecommendedQueries(Enumerable.Empty <String>().AsQueryable()); var selectedAccessLevels = AccessLevels.Where(a => a.Checked).Select(a => a.Access).ToList(); if (selectedAccessLevels.Any()) { Criteria.SearchByAccessLevel = true; Criteria.AccessLevels = new SortedSet <AccessLevel>(selectedAccessLevels); } else { Criteria.SearchByAccessLevel = false; Criteria.AccessLevels.Clear(); } var selectedProgramElementTypes = ProgramElements.Where(e => e.Checked).Select(e => e.ProgramElement).ToList(); if (selectedProgramElementTypes.Any()) { Criteria.SearchByProgramElementType = true; Criteria.ProgramElementTypes = new SortedSet <ProgramElementType>(selectedProgramElementTypes); } else { Criteria.SearchByProgramElementType = false; Criteria.ProgramElementTypes.Clear(); } SearchAsync(searchString, Criteria); }
public void SearchRespectsAccessLevelCriteria() { var codeSearcher = new CodeSearcher(new IndexerSearcher()); string keywords = "usage type"; SearchCriteria searchCriteria = new SimpleSearchCriteria() { AccessLevels = new SortedSet <AccessLevel>() { AccessLevel.Private }, SearchByAccessLevel = true, SearchTerms = new SortedSet <string>(keywords.Split(' ')) }; List <CodeSearchResult> codeSearchResults = codeSearcher.Search(searchCriteria); Assert.AreEqual(2, codeSearchResults.Count, "Invalid results number"); var methodSearchResult = codeSearchResults.Find(el => el.ProgramElement.ProgramElementType == ProgramElementType.Method && (el.ProgramElement.Name == "UsageTypeCriteriaToString")); if (methodSearchResult == null) { Assert.Fail("Failed to find relevant search result for search: " + keywords); } var method = methodSearchResult.ProgramElement as MethodElement; Assert.AreEqual(method.AccessLevel, AccessLevel.Private, "Method access level differs!"); Assert.AreEqual(method.Arguments, "StringBuilder stringBuilder bool searchByUsageType", "Method arguments differs!"); Assert.NotNull(method.Body, "Method body is null!"); //Assert.True(method.ClassId != null && method.ClassId != Guid.Empty, "Class id is invalid!"); //Assert.AreEqual(method.ClassName, "SimpleSearchCriteria", "Method class name differs!"); Assert.AreEqual(method.DefinitionLineNumber, 96, "Method definition line number differs!"); Assert.True(method.FullFilePath.EndsWith("\\TestFiles\\MethodElementTestFiles\\Searcher.cs".ToLowerInvariant()), "Method full file path is invalid!"); Assert.AreEqual(method.Name, "UsageTypeCriteriaToString", "Method name differs!"); Assert.AreEqual(method.ProgramElementType, ProgramElementType.Method, "Program element type differs!"); Assert.AreEqual(method.ReturnType, "void", "Method return type differs!"); Assert.False(String.IsNullOrWhiteSpace(method.RawSource), "Method snippet is invalid!"); }
public void SearchCriteria_EqualsReturnTrueWhenObjectsHaveTheSameData() { SearchCriteria simpleSearchCriteria1 = new SimpleSearchCriteria() { SearchByProgramElementType = true, ProgramElementTypes = new SortedSet <ProgramElementType>() { ProgramElementType.Class, ProgramElementType.Method } }; SearchCriteria simpleSearchCriteria2 = new SimpleSearchCriteria() { SearchByProgramElementType = true, ProgramElementTypes = new SortedSet <ProgramElementType>() { ProgramElementType.Method, ProgramElementType.Class } }; Assert.True(simpleSearchCriteria1.Equals(simpleSearchCriteria2), "Equals should return true when search criteria objects have the same data!"); }
public void SearchCriteria_EqualsReturnFalseWhenObjectsHaveDifferentData() { SearchCriteria simpleSearchCriteria1 = new SimpleSearchCriteria() { SearchByProgramElementType = true, ProgramElementTypes = new SortedSet <ProgramElementType>() { ProgramElementType.Class, ProgramElementType.Property } }; SearchCriteria simpleSearchCriteria2 = new SimpleSearchCriteria() { SearchByProgramElementType = true, ProgramElementTypes = new SortedSet <ProgramElementType>() { ProgramElementType.Class, ProgramElementType.Method } }; Assert.False(simpleSearchCriteria1.Equals(simpleSearchCriteria2), "Equals should return false when search criteria objects have different data!"); }
public void SimpleSearchCriteria_ToQueryStringCreatesValidAccessLevelsQueryString_SingleCondition() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByAccessLevel = true, AccessLevels = new SortedSet <AccessLevel>() { AccessLevel.Private } }; string queryString = simpleSearchCriteria.ToQueryString(); Assert.AreEqual(queryString, "(" + SandoField.AccessLevel.ToString() + ":private)", "Created query string is invalid!"); try { Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, SandoField.AccessLevel.ToString(), new SimpleAnalyzer()).Parse(queryString); Assert.NotNull(query, "Generated query object is null!"); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void SimpleSearchCriteria_ToQueryStringCreatesValidLocationsQueryString_SingleCondition() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByLocation = true, Locations = new SortedSet <string>() { "C:/Project/*.cs" } }; string queryString = simpleSearchCriteria.ToQueryString(); Assert.AreEqual(queryString, "(" + SandoField.FullFilePath.ToString() + ":\"C:/Project/*.cs\")", "Created query string is invalid!"); try { Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, SandoField.FullFilePath.ToString(), new SimpleAnalyzer()).Parse(queryString); Assert.NotNull(query, "Generated query object is null!"); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void SimpleSearchCriteria_ToQueryStringCreatesFileExtensionsQueryString_MultipleConditions() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByFileExtension = true, FileExtensions = new SortedSet <string>() { ".cs", ".h" } }; var queryString = simpleSearchCriteria.ToQueryString(); Assert.AreEqual(queryString, "(" + SandoField.FileExtension.ToString() + ":\".cs\" OR " + SandoField.FileExtension.ToString() + ":\".h\")", "Created query string is invalid!"); try { var query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, SandoField.FullFilePath.ToString(), new SimpleAnalyzer()).Parse(queryString); Assert.NotNull(query, "Generated query object is null!"); } catch (Exception ex) { Assert.Fail(ex.Message); } }
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); } }
public void SimpleSearchCriteria_ToQueryStringCreatesValidQueryString_AllConditions() { SearchCriteria simpleSearchCriteria = new SimpleSearchCriteria() { SearchByAccessLevel = true, AccessLevels = new SortedSet <AccessLevel>() { AccessLevel.Public, AccessLevel.Protected }, SearchByFileExtension = true, FileExtensions = new SortedSet <string>() { ".cs", ".h" }, SearchByLocation = true, Locations = new SortedSet <string>() { "C:/Project/*.cs", "C:/Project2/*.cs" }, SearchByProgramElementType = true, ProgramElementTypes = new SortedSet <ProgramElementType>() { ProgramElementType.Property, ProgramElementType.Class, ProgramElementType.Enum }, SearchByUsageType = true, UsageTypes = new SortedSet <UsageType>() { UsageType.ExtendedClasses, UsageType.Definitions, UsageType.NamespaceNames }, SearchTerms = new SortedSet <string>() { "SimpleClass" } }; string queryString = simpleSearchCriteria.ToQueryString(); Assert.AreEqual(queryString, "(" + SandoField.AccessLevel.ToString() + ":protected OR " + SandoField.AccessLevel.ToString() + ":public) AND " + "(" + SandoField.ProgramElementType.ToString() + ":property OR " + SandoField.ProgramElementType.ToString() + ":enum OR " + SandoField.ProgramElementType.ToString() + ":class) AND " + "(" + SandoField.FileExtension.ToString() + ":\".cs\" OR " + SandoField.FileExtension.ToString() + ":\".h\") AND " + "(" + SandoField.FullFilePath.ToString() + ":\"C:/Project/*.cs\" OR " + SandoField.FullFilePath.ToString() + ":\"C:/Project2/*.cs\") AND " + "(" + SandoField.Name.ToString() + ":SimpleClass^3 OR " + SandoField.ExtendedClasses.ToString() + ":SimpleClass^0.2 OR " + SandoField.Namespace.ToString() + ":SimpleClass^0.05)", "Created query string is invalid!"); try { Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, SandoField.Name.ToString(), new SimpleAnalyzer()).Parse(queryString); Assert.NotNull(query, "Generated query object is null!"); } catch (Exception ex) { Assert.Fail(ex.Message); } }