OrionSearch
public class OrionSearch
OrionSearch is the main object of this framework. It will coordinate and operates all the operations and queries inside your database. This is how you construct it:
let db = OSDatabase()
/* ... */
let os = OrionSearch(db: db, filters: ["author", "type"])
Filters
Filters are a way of filtering the data. It’s very similar to GitHub’s search filters like
is:issueorlanguage:javascriptthat acts as conditions.
Performing queries
Queries are an important part of the research experience. That’s why querying the database is extremely simple:
let db = OSDatabase()
/* ... */
let os = OrionSearch(db: db, filters: ["author", "type"])
let query = OSQuery("Rose are red type:poem") // "Rose are red" + filter looks for a poem
let type: OSSearchType = .normal // Will perform normal search
os.perform(query: query, type: type) { (record) in
// Will call this function for every records
}
-
OrionSearch’s initializer
Declaration
Swift
public init(db: OSDatabase, filters: [String] = [])Parameters
dbYour database
filtersYour filters
-
Add filters
Declaration
Swift
public func add(filters: [String])Parameters
filtersYour filters
-
performwill be the function you want to call to basically search something in your database.The
performfunction is synchronous and blocking. While you can see here a weakness, it’s actually a strength as you have the hand on optimisation and thread management.⚠️ We strongly recommend to dispatch the function You can do that by doing something like:
DispatchQueue.global().sync { os.perform(query: query, type: .normal) { ... } }Declaration
Swift
public func perform(query: OSQuery, type: OSSearchType = .normal, completion: @escaping (OSRecord) -> Void)Parameters
querytypeThe type of your search. It can be:
.quick: forOSQuicksearches,.normal: forOSNormalsearches and.advanced: forOSAdvancedsearches powered by machine learningcompletionA callback that will be called each time a record is found. All records will be sorted.
View on GitHub
OrionSearch Class Reference