如果使用postgresql的android中的某些字符不正确,则获取搜索结果

如果使用postgresql的android中的某些字符不正确,则获取搜索结果,android,postgresql,search,Android,Postgresql,Search,如果用户输入了一些不正确的单词,我想从数据库中得到结果,例如“Ahmed”存储在数据库中,用户输入“Ahmad”,我想,用户用“Ahmed”得到结果。如果我使用“Like”,用户必须输入准确的拼写“Ahmed”,如果他/她输入“Ahmad”,结果将为空 为了实现这个想法,我使用以下代码: private final TextWatcher mTextEditorWatcher = new TextWatcher() { public void beforeTextChanged(Char

如果用户输入了一些不正确的单词,我想从数据库中得到结果,例如“Ahmed”存储在数据库中,用户输入“Ahmad”,我想,用户用“Ahmed”得到结果。如果我使用“Like”,用户必须输入准确的拼写“Ahmed”,如果他/她输入“Ahmad”,结果将为空

为了实现这个想法,我使用以下代码:

private final TextWatcher mTextEditorWatcher = new TextWatcher() {
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (count > 2) {
            //call your async class through which you can make request for get suggestions.
        }
    }

    public void afterTextChanged(Editable s) {
        if (count > 2) {
            //call your async class through which you can make request for get suggestions.
        }
    }
};

为了实现这个想法,我使用以下代码:

private final TextWatcher mTextEditorWatcher = new TextWatcher() {
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (count > 2) {
            //call your async class through which you can make request for get suggestions.
        }
    }

    public void afterTextChanged(Editable s) {
        if (count > 2) {
            //call your async class through which you can make request for get suggestions.
        }
    }
};

使用pg_trgm扩展名。使用以下查询为数据库安装它:

CREATE EXTENSION pg_trgm;
对于此表:

CREATE TABLE test (t varchar);
INSERT INTO test VALUES ('Ahmad');
您可以得到以下结果:

SELECT * FROM test WHERE 'Ahmed' % t;
   t   
-------
 Ahmad
(1 row)

SELECT * FROM test WHERE t LIKE 'Ahmed';
 t 
---
(0 rows)

使用pg_trgm扩展名。使用以下查询为数据库安装它:

CREATE EXTENSION pg_trgm;
对于此表:

CREATE TABLE test (t varchar);
INSERT INTO test VALUES ('Ahmad');
您可以得到以下结果:

SELECT * FROM test WHERE 'Ahmed' % t;
   t   
-------
 Ahmad
(1 row)

SELECT * FROM test WHERE t LIKE 'Ahmed';
 t 
---
(0 rows)

为此,请使用TextWatcher。您需要使用postgres“全文搜索”或“pg_trgm”进行搜索。谷歌了解更多详细信息请使用TextWatcher进行搜索。您需要使用postgres“全文搜索”或“pg_trgm”进行搜索。谷歌了解更多详细信息