public void Start() { _grpcServer = new Grpc.Core.Server { Services = { SearchServer.BindService(new SearchService()) }, Ports = { new ServerPort("localhost", _port, ServerCredentials.Insecure) } }; _grpcServer.Start(); _log.Info("Server listening on port " + _port); }
public void CorrectXmlShouldReturnCorrectNumberOfHits() { var q = new Mock<IQuery>(); q.Setup(m => m.ConstructQuery()).Returns(@"samplegsaxml.xml"); var server = new SearchServer(); var result = server.Search(q.Object); Assert.IsNotNull(result); Assert.IsNullOrEmpty(result.Error); Assert.AreEqual(3480, result.NumberOfHits); }
/// <summary> /// Provides suggestions that complete a user's search query. /// </summary> /// <param name="q">The partial query as inputted by the user</param> /// <param name="s">The system name that performs the search. Supported values are: "Klara", "SuntLiv", "Klaratest", "SuntLivTest"</param> /// <param name="collections">The Collections in which to search for hits. You can use . (AND) or | (OR) to search in several collections.</param> /// <param name="client">A string that indicates a valid front end</param> /// <param name="maxSuggestions">The maximum number of results that the suggest server should return. The minimum is 0, which indicates that the server should return an empty set, /// however this result would not be meaningful. Maximum is not set. Default is 10. If fewer suggestions are configured, then they are returned.</param> /// <returns>A list of suggestions</returns> public List<string> Get(string q, string s, string collections = "", string client = "", int maxSuggestions = 10) { var server = new SearchServer(); var query = new SuggestionQuery(); query.SearchTerm = q; query.Collections = collections; query.Client = client; query.MaxSuggestions = maxSuggestions; query.GsaHostAddress = string.Format(this.GetHostFromSystemName(s), "/suggest"); var result = server.Suggest(query); return result; }
public void CorrectJsonShouldReturnResult() { var q = new Mock<ISuggestionQuery>(); q.Setup(m => m.ConstructQuery()).Returns(@"C:\Repos\WebApi\GSA.Search.Tests\samplejson.txt"); var server = new SearchServer(); var result = server.Suggest(q.Object); Assert.IsNotNull(result); CollectionAssert.IsNotEmpty(result); CollectionAssert.AllItemsAreNotNull(result); Assert.AreEqual(10, result.Count); CollectionAssert.Contains(result, "lediga dagar 2014"); CollectionAssert.Contains(result, "ledighetsansökan"); CollectionAssert.DoesNotContain(result, "fakeandbake"); CollectionAssert.DoesNotContain(result, "suggest"); }
public void CorrectXmlShouldReturnCorrectFacets() { var q = new Mock<IQuery>(); q.Setup(m => m.ConstructQuery()).Returns(@"samplegsaxml.xml"); var server = new SearchServer(); var result = server.Search(q.Object); Assert.IsNotNull(result); Assert.IsNullOrEmpty(result.Error); CollectionAssert.IsNotEmpty(result.Facets); Assert.AreEqual(6, result.Facets.Count); CollectionAssert.AllItemsAreNotNull(result.Facets); CollectionAssert.AllItemsAreUnique(result.Facets); Assert.AreEqual(1, result.Facets.First().FacetItems.Count); Assert.AreEqual(628, result.Facets.First().FacetItems.First().Count); }
/// <summary> /// A search request. All parameters are optional, although it's good practice to at least provide a query. /// </summary> /// <param name="q">The query as inputted by the user</param> /// <param name="s">The system name that performs the search. Supported values are: "Klara", "SuntLiv", "Klaratest", "SuntLivTest"</param> /// <param name="collections">The Collections in which to search for hits. You can use . (AND) or | (OR) to search in several collections.</param> /// <param name="client">A string that indicates a valid front end</param> /// <param name="resultsPerPage">The maximum number of hits to return. Default is 10. Maximum is 100.</param> /// <param name="requiredFields">The required metadata fields that the hits must contain in order to be returned. Should be separated by |. /// The values specified will be required to exist as a metadata tag on page for it to be included in the result.</param> /// <param name="partialfields">Metadata fields that are partially required, /// that means the metadatafield and value must contain the specified word or phrases. For example specifying "dep" for a partialfield would /// return hits that contains the metadatafield "department" and "depending". Should be separated by |</param> /// <returns>The searchresult</returns> public ISearchResult Get(string q, string s, string collections = "", string client = "", int resultsPerPage = 10, string requiredFields = "", string partialfields = "") { var server = new SearchServer(); var query = new Query(); query.SearchTerm = q; query.Collections = collections; query.Client = client; query.MaxSearchHits = 10; if (!string.IsNullOrEmpty(requiredFields)) { if (requiredFields.Contains("|")) { //The more complex scenario. The user has serveral required fields that needs to be handled //TODO update this to handle not only AND but OR and NEGATE too var tags = requiredFields.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var tag in tags) { if (!string.IsNullOrEmpty(tag)) { var field = new MetaDataField(); field.Key = tag; field.MetaDataSearchSpecification = MetaDataSearchSpecification.And; query.RequiredFields.Add(field); } } } else { var field = new MetaDataField(); field.Key = requiredFields; field.MetaDataSearchSpecification = MetaDataSearchSpecification.Ignore; query.RequiredFields.Add(field); } } if (!string.IsNullOrEmpty(partialfields)) { if (partialfields.Contains("|")) { //The more complex scenario. The user has serveral partial fields that needs to be handled //TODO update this to handle not only AND but OR and NEGATE too var tags = partialfields.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var tag in tags) { if (!string.IsNullOrEmpty(tag)) { var field = new MetaDataField(); field.Key = tag; field.MetaDataSearchSpecification = MetaDataSearchSpecification.And; query.PartialFields.Add(field); } } } else { var field = new MetaDataField(); field.Key = partialfields; field.MetaDataSearchSpecification = MetaDataSearchSpecification.Ignore; query.PartialFields.Add(field); } } query.GsaHostAddress = string.Format(this.GetHostFromSystemName(s), "/search"); var result = server.Search(query); return result; }
public void CorrectXmlShouldReturnCorrectResult() { var q = new Mock<IQuery>(); q.Setup(m => m.ConstructQuery()).Returns(@"samplegsaxml.xml"); var server = new SearchServer(); var result = server.Search(q.Object); Assert.IsNotNull(result); Assert.IsNullOrEmpty(result.Error); CollectionAssert.IsNotEmpty(result.SearchHits); Assert.IsTrue(result.SearchHits.Count == 10); CollectionAssert.AllItemsAreNotNull(result.SearchHits); CollectionAssert.AllItemsAreUnique(result.SearchHits); }
public void SearchShouldReturnResults() { var q = new Mock<IQuery>(); q.Setup(m => m.ConstructQuery()).Returns(@"samplegsaxml.xml"); var server = new SearchServer(); var result = server.Search(q.Object); Assert.IsNotNull(result); Assert.IsNullOrEmpty(result.Error); }
public void MalformedSearchHostShouldReturnAnError() { var q = new Mock<IQuery>(); q.Setup(m => m.ConstructQuery()).Returns("apa.xml"); var server = new SearchServer(); var result = server.Search(q.Object); Assert.IsNotNull(result); Assert.IsNotNullOrEmpty(result.Error); }
public void CorrectXmlShouldReturnSpellingSuggestions() { var q = new Mock<IQuery>(); q.Setup(m => m.ConstructQuery()).Returns(@"samplegsaxml.xml"); var server = new SearchServer(); var result = server.Search(q.Object); Assert.IsNotNull(result); Assert.IsNullOrEmpty(result.Error); CollectionAssert.IsNotEmpty(result.SpellingSuggestions); Assert.IsTrue(result.SpellingSuggestions.Count == 1); }
public void CorrectXmlShouldReturnQuery() { var q = new Mock<IQuery>(); q.Setup(m => m.ConstructQuery()).Returns(@"samplegsaxml.xml"); var server = new SearchServer(); var result = server.Search(q.Object); Assert.IsNotNull(result); Assert.IsNullOrEmpty(result.Error); StringAssert.AreEqualIgnoringCase(result.Query, "Försäkring"); }