         }
         
         if let facetFilters = facetFilters {
-            // TODO: complete code (JSON)
+            var error: NSError?
+            let data = NSJSONSerialization.dataWithJSONObject(facetFilters, options: .PrettyPrinted, error: &error)
+            if error == nil {
+                let json: String = NSString(data: data!, encoding: NSUTF8StringEncoding)!
+                url.append(Query.encodeForQuery(json, withKey: "facetFilters"))
+            } else {
+                NSException(name: "InvalidArgument", reason: "Invalid facetFilters (should be an array of string)", userInfo: nil).raise()
+            }
         } else if let facetFiltersRaw = facetFiltersRaw {
-            url.append(Query.encodeForQuery(facetFiltersRaw, withKey: "facetFilters="))
+            url.append(Query.encodeForQuery(facetFiltersRaw, withKey: "facetFilters"))
         }
         
         if let facets = facets {


import Foundation

// TODO: rethink attributes. Use for example enum for queryType
// TODO: add comment for all attributes

/// Describes all parameters of search query.
public class Query : Printable {
    public var minWordSizeForApprox1: UInt = 3
    public var minWordSizeForApprox2: UInt = 7
    public var getRankingInfo = false
    public var ignorePlural = false
    public var distinct = false
    public var page: UInt = 0
    public var hitsPerPage: UInt = 20
    public var typosOnNumericTokens = true
    public var analytics = true
    public var synonyms = true
    public var replaceSynonyms = true
    public var optionalWordsMinimumMatched: UInt = 0
    public var attributesToHighlight: [String]?
    public var attributesToRetrieve: [String]?
    public var tagFilters: String?
    public var numericFilters: String?
    public var fullTextQuery: String?
    public var queryType: String?
    public var removeWordsIfNoResult: String?
    public var typoTolerance: String?
    public var attributesToSnippet: [String]?
    public var facetFilters: [String]?
    public var facetFiltersRaw: String?
    public var facets: [String]?
    public var optionalWords: [String]?
    public var restrictSearchableAttributes: String?
    
    private var aroundLatLongViaIP = false
    private var aroundLatLong: String?

    public var description: String {
        get { return "Query = \(buildURL())" }
    }
    
    // MARK: - Methods
    
    public init(fullTextQuery: String? = nil) {
        self.fullTextQuery = fullTextQuery
