Android Open Source - hello-srch2-android-sdk S Q Lite Book Index






From Project

Back to project page hello-srch2-android-sdk.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project hello-srch2-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.srch2.android.demo.sqlite;
/*from www  .j  a  v a2  s. co m*/
import android.database.sqlite.SQLiteOpenHelper;

import com.srch2.android.sdk.Highlighter;
import com.srch2.android.sdk.SQLiteIndexable;

public class SQLiteBookIndex extends SQLiteIndexable {

    // For clarity, SQLiteBookIndex defined as top-level class;
    // could also be nested, non-static class of the DatabaseHelper.
    // Pass in as DatabaseHelper to automatically insert the records
    // when onIndexReady() call back is executed.
    private final DatabaseHelper mSQLiteOpenHelper;

    public SQLiteBookIndex(DatabaseHelper databaseHelper) {
        mSQLiteOpenHelper = databaseHelper;
    }

    @Override
    public String getIndexName() {
        // For convenience, make the same as the table name.
        return DatabaseHelper.TABLE_NAME;
    }

    @Override
    public SQLiteOpenHelper getSQLiteOpenHelper() {
        return mSQLiteOpenHelper;
    }

    @Override
    public String getDatabaseName() {
        return DatabaseHelper.DATABASE_NAME;
    }

    @Override
    public String getTableName() {
        return DatabaseHelper.TABLE_NAME;
    }

    @Override
    public String getRecordBoostColumnName() {
        // Is equivalent to setting the RecordBoostField for a Schema in
        // the Indexable getSchema() function.
        return DatabaseHelper.COLUMN_SCORE;
    }

    @Override
    public int getColumnBoostValue(String textTypeColumnName) {
        // Since books are often looked up by title, give title the
        // greatest field boost relative to the other searchable fields/columns.
        int fieldBoostValue = 1;
        if (textTypeColumnName.equals(DatabaseHelper.COLUMN_AUTHOR)) {
            fieldBoostValue = 25;
        } else if (textTypeColumnName.equals(DatabaseHelper.COLUMN_TITLE)) {
            fieldBoostValue = 50;
        }
        return fieldBoostValue;
    }

    @Override
    public boolean getColumnIsHighlighted(String textTypeColumnName) {
        // Highlight all searchable / of type TEXT columns.
        return true;
    }

    @Override
    public Highlighter getHighlighter() {
        return Highlighter.createHighlighter()
                .formatExactTextMatches(true, false, "#FF0000")
                .formatFuzzyTextMatches(true, false, "#FF00FF");
    }

    @Override
    public void onIndexReady() {
        super.onIndexReady();
        if (getRecordCount() == 0) {
            mSQLiteOpenHelper.insertRecords(Book.getBookList());
        }
    }
}




Java Source Code List

com.srch2.android.demo.helloworld.ApplicationTest.java
com.srch2.android.demo.helloworld.InstantSearchEditText.java
com.srch2.android.demo.helloworld.MovieIndex.java
com.srch2.android.demo.helloworld.MovieSearchResult.java
com.srch2.android.demo.helloworld.SearchActivity.java
com.srch2.android.demo.helloworld.SearchResultsAdapter.java
com.srch2.android.demo.sqlite.ApplicationTest.java
com.srch2.android.demo.sqlite.BookSearchResult.java
com.srch2.android.demo.sqlite.Book.java
com.srch2.android.demo.sqlite.DatabaseHelper.java
com.srch2.android.demo.sqlite.InstantSearchEditText.java
com.srch2.android.demo.sqlite.SQLiteBookIndex.java
com.srch2.android.demo.sqlite.SearchActivity.java
com.srch2.android.demo.sqlite.SearchResultsAdapter.java