Esempio n. 1
0
        /// <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;
        }
Esempio n. 2
0
        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");
        }