public async Task<JToken> GetBooksAsync(string searchString, int pageNumber, int pageSize)
 {
     var query = new Query(searchString);
     query.SetNbHitsPerPage(pageSize);
     query.SetPage(pageNumber);
     query.SetAttributesToRetrieve(new[] { "objectId", "title", "author", "author_first" });
     query.SetAttributesToHighlight(new string[] { });
     var queryResult = await this.PrimaryIndex.SearchAsync(query);
     JToken returnValue;
     return queryResult.TryGetValue("hits", out returnValue) ? returnValue : null;
 }
        private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
            {
                var searchTerm = sender.Text;
                var query = new Query(searchTerm);
                var result = algoliaIndex.SearchAsync(query).Result;
                var packagesResult = result.ToObject<PackagesResult>();

                sender.ItemsSource = packagesResult.hits;
            }
        }
 /// <summary>
 /// Create a new index query.
 /// </summary>
 /// <param name="index">The name of the index.</param>
 /// <param name="query">The query.</param>
 public IndexQuery(String index, Query query)
 {
     this.Index = index;
     this.Query = query;
 }
 public void TestDeleteObject()
 {
     clearTest();
     _index.AddObject(JObject.Parse(@"{""firstname"":""Jimmie"", ""lastname"":""Barninger"", ""objectID"":""àlgol?à""}"));
     var task = _index.DeleteObject("àlgol?à");
     _index.WaitTask(task["taskID"].ToString());
     Query query = new Query();
     query.SetQueryString("");
     var res = _index.Search(query);
     Assert.AreEqual(0, res["nbHits"].ToObject<int>());
 }
 public void TestBigQueryNone()
 {
     clearTest();
     _index.AddObject(JObject.Parse(@"{""firstname"":""Jimmie J""
         , ""Age"":42, ""lastname"":""Barninger"", ""_tags"": ""people""
         , ""_geoloc"":{""lat"":0.853409, ""lng"":0.348800}}"));
     var task = _index.SetSettings(JObject.Parse(@"{""attributesForFaceting"": [""_tags""]}"));
     _index.WaitTask(task["taskID"].ToString());
     Query query = new Query("Jimmie");
     query.SetPage(0);
     query.SetOptionalWords("J");
     query.SetNbHitsPerPage(1);
     string[] attr = { "firstname" };
     query.SetAttributesToHighlight(attr);
     query.SetMinWordSizeToAllowOneTypo(1);
     query.SetMinWordSizeToAllowTwoTypos(2);
     query.EnableDistinct(true);
     query.EnableAdvancedSyntax(true);
     query.GetRankingInfo(true);
     query.EnableTypoTolerance(false);
     query.SetAttributesToRetrieve(attr);
     query.SetAttributesToSnippet(attr);
     query.SetMaxValuesPerFacets(1);
     query.InsideBoundingBox(0, 0, 90, 90);
     query.AroundLatitudeLongitude(0, 0, 2000000000, 100);
     string[] facetFilter = { "_tags:people" };
     string[] facets = { "_tags" };
     query.SetFacetFilters(facetFilter);
     query.SetFacets(facets);
     query.SetTagFilters("people");
     query.SetNumericFilters("Age>=42");
     query.SetQueryType(Query.QueryType.PREFIX_NONE);
     query.SetRemoveWordsIfNoResult(Query.RemoveWordsIfNoResult.LAST_WORDS);
     var res = _index.Search(query);
     Assert.AreEqual(1, res["nbHits"].ToObject<int>());
     Assert.AreEqual("Jimmie J", res["hits"][0]["firstname"].ToString());
     _client.DeleteIndex(safe_name("àlgol?à-csharp"));
 }
 /// <summary>
 /// Generates a secured and public API Key from a query parameters and an optional user token identifying the current user
 /// </summary>
 /// <param name="privateApiKey">Your private API Key</param>
 /// <param name="query">The query parameters applied to the query (used as security)</param>
 /// <param name="userToken">An optional token identifying the current user</param>
 /// <returns></returns>
 public string GenerateSecuredApiKey(String privateApiKey, Query query, String userToken = null)
 {
     return GenerateSecuredApiKey(privateApiKey, query.ToString(), userToken);
 }
 /// <summary>
 /// Generates a secured and public API Key from a query parameters and an optional user token identifying the current user
 /// </summary>
 /// <param name="privateApiKey">Your private API Key</param>
 /// <param name="query">The query parameters applied to the query (used as security)</param>
 /// <param name="userToken">An optional token identifying the current user</param>
 /// <returns></returns>
 public string GenerateSecuredApiKey(String privateApiKey, Query query, String userToken = null)
 {
     if (userToken != null)
         query.SetUserToken(userToken);
     string queryStr = query.GetQueryString();
     byte[] content = System.Text.Encoding.UTF8.GetBytes(string.Format("{0}{1}", Hmac(privateApiKey, queryStr), queryStr));
     return System.Convert.ToBase64String(content);
 }
        /// <summary>
        /// Clone this query to a new query.
        /// </summary>
        /// <returns>The cloned query.</returns>
        public Query clone()
        {
            Query q = new Query();
            q.advancedSyntax = advancedSyntax;
	    q.removeStopWords = removeStopWords;
            q.allowTyposOnNumericTokens = allowTyposOnNumericTokens;
            q.analytics = analytics;
            q.aroundLatLong = aroundLatLong;
            q.aroundLatLongViaIP = aroundLatLongViaIP;
            q.attributes = attributes;
            q.attributesToHighlight = attributesToHighlight;
            q.noTypoToleranceOn = noTypoToleranceOn;
            q.attributesToSnippet = attributesToSnippet;
            q.distinct = distinct;
            q.facetFilters = facetFilters;
            q.facets = facets;
            q.getRankingInfo = getRankingInfo;
            q.hitsPerPage = hitsPerPage;
            q.ignorePlural = ignorePlural;
            q.insideBoundingBox = insideBoundingBox;
            q.insidePolygon = insidePolygon;
            q.maxValuesPerFacets = maxValuesPerFacets;
            q.minWordSizeForApprox1 = minWordSizeForApprox1;
            q.minWordSizeForApprox2 = minWordSizeForApprox2;
            q.numerics = numerics;
            q.optionalWords = optionalWords;
            q.page = page;
            q.query = query;
	    q.similarQuery = similarQuery;
            q.queryType = queryType;
            q.removeWordsIfNoResult = removeWordsIfNoResult;
            q.replaceSynonyms = replaceSynonyms;
            q.restrictSearchableAttributes = restrictSearchableAttributes;
            q.synonyms = synonyms;
            q.tags = tags;
            q.typoTolerance = typoTolerance;
            q.filters = filters;
            q.aroundRadius = aroundRadius;
            q.aroundPrecision = aroundPrecision;
            return q;
        }