Skip to content

Commit

Permalink
add new Query parameter and method
Browse files Browse the repository at this point in the history
  • Loading branch information
dethi committed Jun 3, 2015
1 parent 299d46c commit 53fa726
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
28 changes: 26 additions & 2 deletions Source/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "<em>").
public var highlightPreTag: String?

/// Specify the string that is inserted after the highlighted parts in the query result (default to "</em>").
public var highlightPostTag: String?

private var aroundLatLongViaIP = false
private var aroundLatLong: String?
private var insideBoundingBox: String?
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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"))
}
Expand All @@ -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)
Expand Down

0 comments on commit 53fa726

Please sign in to comment.