From 53fa726b32acaaa11aec3fe878fe086ca91e2224 Mon Sep 17 00:00:00 2001 From: Thibault Deutsch Date: Wed, 3 Jun 2015 23:26:30 +0200 Subject: [PATCH] add new Query parameter and method --- ChangeLog | 6 ++++++ Source/Query.swift | 28 ++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 ChangeLog diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 000000000..50416ec26 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,6 @@ +CHANGELOG + +2015-05-04 1.2.0 + * new retry logic + * add new parameter on the Query: setMinProximity & setHighlightingTags + * add new method on the Query: resetLocationParameters diff --git a/Source/Query.swift b/Source/Query.swift index 4ec4c652b..886a755e0 100644 --- a/Source/Query.swift +++ b/Source/Query.swift @@ -72,6 +72,10 @@ public class Query : Printable { /// Defaults to 7. public var minWordSizeForApprox2: UInt = 7 + /// Configure the precision of the proximity ranking criterion. By default, the minimum (and best) proximity value distance between 2 matching words is 1. Setting it to 2 (or 3) would allow 1 (or 2) words to be found between the matching words without degrading the proximity ranking value. + /// Considering the query "javascript framework", if you set minProximity=2 the records "JavaScript framework" and "JavaScript charting framework" will get the same proximity score, even if the second one contains a word between the 2 matching words. + public var minProximity: UInt = 1 + /// If true, the result hits will contain ranking information in _rankingInfo attribute. /// Default to false. public var getRankingInfo = false @@ -157,10 +161,15 @@ public class Query : Printable { /// The list of words that should be considered as optional when found in the query. public var optionalWords: [String]? - /// List of object attributes you want to use for textual search (must be a subset of the - /// attributesToIndex index setting). + /// List of object attributes you want to use for textual search (must be a subset of the attributesToIndex index setting). public var restrictSearchableAttributes: [String]? + /// Specify the string that is inserted before the highlighted parts in the query result (default to ""). + public var highlightPreTag: String? + + /// Specify the string that is inserted after the highlighted parts in the query result (default to ""). + public var highlightPostTag: String? + private var aroundLatLongViaIP = false private var aroundLatLong: String? private var insideBoundingBox: String? @@ -232,6 +241,14 @@ public class Query : Printable { return self } + /// Reset location parameters (aroundLatLong,insideBoundingBox, aroundLatLongViaIP set to false) + public func resetLocationParameters() -> Query { + aroundLatLong = nil + insideBoundingBox = nil + aroundLatLongViaIP = false + return self + } + /// Return the final query string used in URL. public func buildURL() -> String { var url = [String]() @@ -303,6 +320,9 @@ public class Query : Printable { if hitsPerPage != 20 && hitsPerPage > 0 { url.append(Query.encodeForQuery(hitsPerPage, withKey: "hitsPerPage")) } + if minProximity > 1 { + url.append(Query.encodeForQuery(minProximity, withKey: "minProximity")) + } if let queryType = queryType { url.append(Query.encodeForQuery(queryType, withKey: "queryType")) } @@ -315,6 +335,10 @@ public class Query : Printable { if let numericFilters = numericFilters { url.append(Query.encodeForQuery(numericFilters, withKey: "numericFilters")) } + if let highlightPreTag = highlightPreTag, highlightPostTag = highlightPostTag { + url.append(Query.encodeForQuery(highlightPreTag, withKey: "highlightPreTag")) + url.append(Query.encodeForQuery(highlightPostTag, withKey: "highlightPostTag")) + } if let insideBoundingBox = insideBoundingBox { url.append(insideBoundingBox)