Skip to content

Commit

Permalink
Search by a tag e.g. tag:eng #2
Browse files Browse the repository at this point in the history
  • Loading branch information
tedwon committed Jan 1, 2023
1 parent b01781b commit 50f560b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions quokka-backend/src/main/java/sara/won/quokka/MemoResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public String getAsText() {
}

@GET
@Path("{pin}/")
@Path("{pin}")
public List<Memo> getByKeyword(Boolean pin) {
String namedQuery = "Memos.findAll";
if (pin) {
Expand All @@ -71,7 +71,14 @@ public List<Memo> getByKeyword(Boolean pin) {
@GET
@Path("{pin}/{keyword}")
public List<Memo> getByKeyword(String pin, String keyword) {
System.out.println(pin + " : " + keyword);
if (keyword.startsWith("tag:")) {
String tagSearch = keyword.substring(4);
System.out.println(tagSearch);
return entityManager.createNamedQuery("Memos.findByTag")
.setParameter("tagSearch", "%" + tagSearch + "%")
.getResultList();
}

String namedQuery = "Memos.findByKeyword";
if (Boolean.parseBoolean(pin)) {
namedQuery = "Memos.findPinnedByKeyword";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@Entity
@Table(name = "Memo")
@NamedQuery(name = "Memos.findAll", query = "SELECT m FROM Memo m ORDER BY m.pin DESC, m.date DESC", hints = @QueryHint(name = "org.hibernate.cacheable", value = "true"))
@NamedQuery(name = "Memos.findByTag", query = "SELECT m FROM Memo m WHERE m.tags LIKE :tagSearch ORDER BY m.pin DESC, m.date DESC")
@NamedQuery(name = "Memos.findPinned", query = "SELECT m FROM Memo m WHERE m.pin = true ORDER BY m.date DESC", hints = @QueryHint(name = "org.hibernate.cacheable", value = "true"))
@NamedQuery(name = "Memos.findByKeyword", query = "SELECT m FROM Memo m WHERE (upper(m.title) LIKE upper(:keyword)) OR (upper(m.body) LIKE upper(:keyword)) OR (upper(m.tags) LIKE upper(:keyword)) ORDER BY m.pin DESC, m.date DESC")
@NamedQuery(name = "Memos.findPinnedByKeyword", query = "SELECT m FROM Memo m WHERE m.pin = true AND ((upper(m.title) LIKE upper(:keyword)) OR (upper(m.body) LIKE upper(:keyword)) OR (upper(m.tags) LIKE upper(:keyword))) ORDER BY m.pin DESC, m.date DESC")
Expand Down

0 comments on commit 50f560b

Please sign in to comment.