Classes
The following classes are available globally.
-
OrionSearchis 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:
See morelet 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 }Declaration
Swift
public class OrionSearch
-
OSDatabaseis an object that enables OrionSearch to interact with any databases. It also contains akeywords cache
that is used for rewriting the query. The cache will be auto-configured with theconfiguremethod, but if you already ran this function, you can just restore the cache by initiating the class with it:let db1 = OSDatabase() db1.configure(main: "title", secondary: "content") let db2 = new OSDatabase(db1.keywordsCache) // same as db1⚠️ Note about database structure: Every database should have a column named
keywordsthat will be used by OrionSearch to filter records.Set up bindings for your DB
In this section, we’ll show you a detailed example with the SQLite 3 database.
See moreconst db = new OSDatabase() // Creates the object /* Implementing methods */ db.setPlugin( (key, contains, range) => { // Select method const r = range == null ? [0, Number.MAX_SAFE_INTEGER] : range // Creates a range let rows = [] if (contains == null) { // If OrionSearch needs to query everything. Used for the configure method. const query = data.prepare(`SELECT rowid, * FROM main WHERE rowid BETWEEN ${r[0]} AND ${r[1]}`) rows = query.all() } else { // Otherwise const query = data.prepare(`SELECT rowid, * FROM main WHERE ${key} LIKE "%${contains}%" AND rowid BETWEEN ${r[0]} AND ${r[1]}`) rows = query.all() } let out = [] rows.forEach(row => { // Setting the main key. const record = new OSRecord(row) // Creating a record based on the retrieved data. record.main("headlines") // "headlines" is now the main column for this record. out.push(record) }) return out // Returning all the records }, add => { // Add a record const query = data.prepare(`INSERT INTO main VALUES (${add.values})`) query.run() }, (keywords, record) => { // Manage "keywords" column. It will insert an array of records in the desired row. const keyQuery = data.prepare(`UPDATE main SET keywords = "${[...keywords].join(' ')}" WHERE rowid = ${record.data.rowid};`) keyQuery.run() } )Declaration
Swift
public class OSDatabase
-
OSQueryis an object that represents a search query. It makes the process of parsing and tokenizing a query without the need for user’s interaction. It currently supports 57 languages (ISO 639-1):af ar hy eu bn br bg ca zh hr cs da nl en eo et fi fr gl de el ha he hi hu id ga it ja ko ku la lt lv ms mr no fa pl pt ro ru sk sl so st es sw sv th tl tr uk ur vi yo zu The query object can also specify which column to search in using the
keysarray. This will mostly be useful in the Quick searches, but it works on allOrionSearch.OSSearchType.Construction
See morelet query = OSQuery(str: "Articles about Donald Trump")Declaration
Swift
public class OSQuery
-
OSRecordis an object representing a row in your database. It can be modified to keep certain properties or hide data. It’s a pretty light object that helps OrionSearch unifying its ecosystem architecture without using native objects for better integration across all the different platforms.The
OSRecordobject will mostly be used as a read-only property given by theperformmethod inOrionSearch. But it can also be created manually for in-memory databases:let record = OSRecord(data: [ ... ]) // creates the recordAccessing the data
OSRecordhas a simpledataproperty to access the data originally given.
See morerecord.data["myproperty"]Declaration
Swift
public class OSRecord : Equatable, Hashable
View on GitHub
Classes Reference