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:issue
orlanguage:javascript
that 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
db
Your database
filters
Your filters
-
Add filters
Declaration
Swift
public func add(filters: [String])
Parameters
filters
Your filters
-
perform
will be the function you want to call to basically search something in your database.The
perform
function 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
query
type
The type of your search. It can be:
.quick
: forOSQuick
searches,.normal
: forOSNormal
searches and.advanced
: forOSAdvanced
searches powered by machine learningcompletion
A callback that will be called each time a record is found. All records will be sorted.