Implement search filter for all columns

后端 未结 1 631
粉色の甜心
粉色の甜心 2021-01-26 09:25

I found this search example in PostgreSQL http://www.postgresql.org/docs/current/interactive/textsearch-tables.html#TEXTSEARCH-TABLES-SEARCH

I tried to implement this co

相关标签:
1条回答
  • 2021-01-26 10:07

    You will have to add your 'null guard' to the the fulltext search and use to_tsquery instead of plainto_tsquery (in order for prefix search to work).

    SqlStatement = "SELECT * FROM ACCOUNT "
        + " WHERE (trim(?) = '') IS NOT FALSE"
        + " OR to_tsvector('english', USER_NAME || ' ' || FIRST_NAME || ' ' || LAST_NAME ) @@  to_tsquery(?)"
        + " ORDER BY user_name ASC offset ? limit ? ";
    

    and add the searchString to your PreparedStatement a second time

     ps = conn.prepareStatement(sql);
    
     ps.setString(1, searchString);
     ps.setString(2, searchString);
     ps.setInt(3, firstRow);
     ps.setInt(4, rowCount);
    

    Note using a fulltext search you will not be able to search for word-parts (like %user%, %name or us%name). You can search for prefixes though, e.g. user:*

    0 讨论(0)
提交回复
热议问题