Classes

The following classes are available globally.

  • 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 or language: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
    }
    
    See more

    Declaration

    Swift

    public class OrionSearch
  • OSDatabase is an object that enables OrionSearch to interact with any databases. It also contains a keywords cache that is used for rewriting the query. The cache will be auto-configured with the configure method, 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 keywords that 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.

    const 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()
        }
    )
    
    See more

    Declaration

    Swift

    public class OSDatabase
  • OSQuery is 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):

    afarhyeubnbrbgcazhhrcsdanleneoetfifrgldeelhahehihuidgaitjakokulaltlvmsmrnofaplptroruskslsostesswsvthtltrukurviyozu

    The query object can also specify which column to search in using the keys array. This will mostly be useful in the Quick searches, but it works on all OrionSearch.OSSearchType.

    Construction

    let query = OSQuery(str: "Articles about Donald Trump")
    
    See more

    Declaration

    Swift

    public class OSQuery
  • OSRecord is 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 OSRecord object will mostly be used as a read-only property given by the perform method in OrionSearch. But it can also be created manually for in-memory databases:

    let record = OSRecord(data: [ ... ]) // creates the record
    

    Accessing the data

    OSRecord has a simple data property to access the data originally given.

    record.data["myproperty"]
    
    See more

    Declaration

    Swift

    public class OSRecord : Equatable, Hashable