Skip to content

Commit

Permalink
do not include current typed word in suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
iNPUTmice committed Apr 6, 2019
1 parent ef2026d commit 88d49c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
Expand Up @@ -31,8 +31,12 @@
@Dao
public abstract class SearchSuggestionDao {

@Query("select id as "+ BaseColumns._ID +", `query` as "+ SearchManager.SUGGEST_COLUMN_TEXT_1+","+ R.drawable.ic_restore_black_24dp+" as "+SearchManager.SUGGEST_COLUMN_ICON_1+",`query` as "+SearchManager.SUGGEST_COLUMN_QUERY+" from search_suggestion where `query` like :needle order by id desc limit 30")
public abstract Cursor getSearchSuggestions(String needle);
@Query("select id as "+ BaseColumns._ID +", `query` as "+ SearchManager.SUGGEST_COLUMN_TEXT_1+","+ R.drawable.ic_restore_black_24dp+" as "+SearchManager.SUGGEST_COLUMN_ICON_1+",`query` as "+SearchManager.SUGGEST_COLUMN_QUERY+" from search_suggestion where `query` like :needle and `query` is not :actual order by id desc limit 30")
abstract Cursor getSearchSuggestions(String needle, String actual);

public Cursor getSearchSuggestions(String needle) {
return getSearchSuggestions('%'+needle+(needle.isEmpty()?"":"%"), needle);
}

@Insert(onConflict = REPLACE)
public abstract void insert(SearchSuggestionEntity entity);
Expand Down
Expand Up @@ -15,23 +15,17 @@

package rs.ltt.android.provider;

import android.app.SearchManager;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.provider.BaseColumns;
import android.util.Log;

import com.google.common.base.CharMatcher;

import java.util.Arrays;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import rs.ltt.android.Credentials;
import rs.ltt.android.R;
import rs.ltt.android.database.LttrsDatabase;

public class EmailSearchSuggestionsProvider extends ContentProvider {
Expand All @@ -45,20 +39,11 @@ public boolean onCreate() {
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {

if (selectionArgs == null || selectionArgs.length != 1) {
return null;
}

String query = CharMatcher.is('%').removeFrom(selectionArgs[0]);

Log.d("lttrs","query for "+selection+" selection args="+ Arrays.asList(selectionArgs));

Cursor cursor = LttrsDatabase.getInstance(getContext(), Credentials.username).searchSuggestionDao().getSearchSuggestions('%'+query+(query.isEmpty()?"":"%"));

Log.d("lttrs","cursor size: "+cursor.getCount());

return cursor;
final String query = CharMatcher.is('%').removeFrom(selectionArgs[0]);
return LttrsDatabase.getInstance(getContext(), Credentials.username).searchSuggestionDao().getSearchSuggestions(query);
}

@Nullable
Expand Down

0 comments on commit 88d49c1

Please sign in to comment.