LCSearchQuery

Objective-C

@interface LCSearchQuery : NSObject

/*!
 *  使用 queryString 构造一个 LCSearchQuery 对象
 *  @return LCSearchQuery 实例
 */
+ (instancetype)searchWithQueryString:(NSString *)queryString;

/*!
 *  查询的 className,默认为 nil,即包括所有启用了应用内搜索的 Class
 */
@property (nonatomic, copy, nullable) NSString *className;

/*!
 The number of objects to skip before returning any.
 */
@property (nonatomic, assign) NSInteger skip;

/*!
 *  返回集合大小上限,默认值为100,最大为1000
 */
@property (nonatomic, assign) NSInteger limit;

/*!
 * 查询字符串,具体语法参考 http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax
 */
@property (nonatomic, copy, nullable) NSString *queryString;

/*!
 *  查询的LCSearchSortBuilder,使用更丰富的排序选项
 */
@property (nonatomic, strong, nullable) LCSearchSortBuilder *sortBuilder;

/*!
 *  符合查询条件的记录条数
 */
@property (nonatomic, assign, readonly) NSInteger hits;

/*!
 *  当前页面的scroll id,用于分页,可选。
 #  @warning 如非特殊需求,请不要手动设置 sid。每次 findObjects 之后,SDK 会自动更新 sid。如果手动设置了错误的sid,将无法获取到搜索结果。
 *  有关scroll id,可以参考 http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/scan-scroll.html
 */
@property (nonatomic, copy, nullable) NSString *sid;

/*!
 *  查询的字段列表,可选。
 */
@property (nonatomic, strong, nullable) NSArray *fields;

/*!
 *  返回结果的高亮语法,默认为 "*"
 *  语法规则可以参考 http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-highlighting.html#highlighting-settings
 */
@property (nonatomic, copy, nullable) NSString *highlights;

/*!
 * 缓存策略
 */
@property (readwrite, assign) LCCachePolicy cachePolicy;

/* !
 * 最多缓存时间,单位为秒,默认值 24*3600 秒
 */
@property (readwrite, assign) NSTimeInterval maxCacheAge;

/*!
 Make the query include LCObjects that have a reference stored at the provided key.
 This has an effect similar to a join.  You can use dot notation to specify which fields in
 the included object are also fetch.

 @param key The key to load child LCObjects for.
 */
- (void)includeKey:(NSString *)key;

#pragma mark - Find methods

/*!
 *  根据查询条件获取结果对象
 *  @return LCObjects 数组
 */
- (nullable NSArray *)findObjects;

/*!
 *  根据查询条件获取结果对象,如果有 error,则设置一个 error
 *  @param error 指针
 *  @return LCObjects 数组
 */
- (nullable NSArray *)findObjects:(NSError **)error;

/*!
 An alias of `-[LCSearchQuery findObjects:]` methods that supports Swift exception.
 @seealso `-[LCSearchQuery findObjects:]`
 */
- (nullable NSArray *)findObjectsAndThrowsWithError:(NSError **)error;

/*!
 *  异步获取搜索结果,并回调block
 *  @param block 需要有这样的方法签名 (NSArray *objects, NSError *error)
 */
- (void)findInBackground:(LCArrayResultBlock)block;

#pragma mark - Sorting
/*!
 搜索结果会根据关键字,按升序排序
 @param key 排序关键字
 */
- (void)orderByAscending:(NSString *)key;

/*!
 添加一个升序排序关键字。排序优先级由添加关键字的前后顺序决定。
 @param key 排序关键字
 */
- (void)addAscendingOrder:(NSString *)key;

/*!
 搜索结果会根据关键字,按降序排序
 @param key 排序关键字
 */
- (void)orderByDescending:(NSString *)key;

/*!
 添加一个降序排序关键字。关键字的排序优先级由添加关键字的前后顺序决定。
 @param key 排序关键字
 */
- (void)addDescendingOrder:(NSString *)key;

/*!
 根据 NSSortDescriptor 排序搜索结果
 @param sortDescriptor 排序描述符
 */
- (void)orderBySortDescriptor:(NSSortDescriptor *)sortDescriptor;

/*!
 根据 NSSortDescriptor 数组排序搜索结果
 @param sortDescriptors NSSortDescriptor 数组
 */
- (void)orderBySortDescriptors:(NSArray *)sortDescriptors;

@end

Swift

class LCSearchQuery : NSObject

Undocumented

  • Undocumented

    Declaration

    Objective-C

    + (nonnull instancetype)searchWithQueryString:(nonnull NSString *)queryString;

    Swift

    class func search(withQueryString queryString: String) -> Self
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSString *className;

    Swift

    var className: String? { get set }
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic) NSInteger skip;

    Swift

    var skip: Int { get set }
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic) NSInteger limit;

    Swift

    var limit: Int { get set }
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSString *queryString;

    Swift

    var queryString: String? { get set }
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) LCSearchSortBuilder *sortBuilder;

    Swift

    var sortBuilder: LCSearchSortBuilder? { get set }
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSInteger hits;

    Swift

    var hits: Int { get }
  • sid

    Undocumented

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSString *sid;

    Swift

    var sid: String? { get set }
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) NSArray *fields;

    Swift

    var fields: [Any]? { get set }
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSString *highlights;

    Swift

    var highlights: String? { get set }
  • Undocumented

    Declaration

    Objective-C

    @property LCCachePolicy cachePolicy;

    Swift

    var cachePolicy: LCCachePolicy { get set }
  • Undocumented

    Declaration

    Objective-C

    @property NSTimeInterval maxCacheAge

    Swift

    var maxCacheAge: TimeInterval { get set }
  • Undocumented

    Declaration

    Objective-C

    - (void)includeKey:(nonnull NSString *)key;

    Swift

    func includeKey(_ key: String)

Find methods

Sorting

  • Undocumented

    Declaration

    Objective-C

    - (void)orderByAscending:(nonnull NSString *)key;

    Swift

    func order(byAscending key: String)
  • Undocumented

    Declaration

    Objective-C

    - (void)addAscendingOrder:(nonnull NSString *)key;

    Swift

    func addAscendingOrder(_ key: String)
  • Undocumented

    Declaration

    Objective-C

    - (void)orderByDescending:(nonnull NSString *)key;

    Swift

    func order(byDescending key: String)
  • Undocumented

    Declaration

    Objective-C

    - (void)addDescendingOrder:(nonnull NSString *)key;

    Swift

    func addDescendingOrder(_ key: String)
  • Undocumented

    Declaration

    Objective-C

    - (void)orderBySortDescriptor:(nonnull NSSortDescriptor *)sortDescriptor;

    Swift

    func order(by sortDescriptor: NSSortDescriptor)
  • Undocumented

    Declaration

    Objective-C

    - (void)orderBySortDescriptors:(nonnull NSArray *)sortDescriptors;

    Swift

    func order(bySortDescriptors sortDescriptors: [Any])