Skip to content

Commit

Permalink
update existing code for FTS in PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
rieckpil committed Mar 30, 2019
1 parent f4d5f08 commit e5555ea
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
Expand Up @@ -23,7 +23,7 @@ public class CommentController {
@GetMapping
public List<Comment> getCommentsContainingText(@RequestParam("q") String queryText) {

List<Comment> list = em.createQuery("SELECT c FROM Comment c where fts(c.commentText, :commentText) = true", Comment.class)
List<Comment> list = em.createQuery("SELECT c FROM Comment c where fts(english, c.commentText, :commentText) = true", Comment.class)
.setParameter("commentText", queryText).getResultList();

return list;
Expand Down
Expand Up @@ -26,16 +26,16 @@ public boolean hasParenthesesIfNoArguments() {
return false;
}

@SuppressWarnings("rawtypes")
@Override
public String render(Type type, List args, SessionFactoryImplementor factory) throws QueryException {

if (args == null || args.size() != 2) {
if (args == null || args.size() != 3) {
throw new IllegalArgumentException("The function must be passed 2 arguments");
}

String field = (String) args.get(0);
String searchString = (String) args.get(1);
return field + " @@ to_tsquery(" + searchString + ")";
String language = (String) args.get(0);
String field = (String) args.get(1);
String searchString = (String) args.get(2);
return field + " @@ to_tsquery('" + language + "', " + searchString + ")";
}
}
Expand Up @@ -4,4 +4,4 @@ spring:
password: postgres
url: jdbc:postgresql://localhost:5432/postgres jpa: hibernate: ddl-auto: validate
properties: hibernate:
dialect: de.rieckpil.blog.ExtendedPostgreSQLDialect
dialect: de.rieckpil.blog.ExtendedPostgreSQLDialect show-sql: true
Expand Down
@@ -0,0 +1 @@
INSERT INTO comment (id, comment_text, created_at) VALUES (1, to_tsvector('english', 'Out believe has request not how comfort evident. Up delight cousins we feeling minutes. Genius has looked end piqued spring. Down has rose feel find man. Learning day desirous informed expenses material returned six the. She enabled invited exposed him another. Reasonably conviction solicitude me mr at discretion reasonable. Age out full gate bed day lose.') ,NOW());

0 comments on commit e5555ea

Please sign in to comment.