-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suche und SearchIndex-Refresh, Tag-Service
- Loading branch information
Showing
14 changed files
with
218 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package de.holarse.backend.db; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
|
||
/** | ||
* Als Abbildung über Spring Data Repository SearchRepository | ||
* @author comrad | ||
*/ | ||
@Table(name = "mv_searchindex") | ||
@Entity | ||
public class SearchIndex { | ||
|
||
@Id | ||
@Column(name = "nodeid") | ||
private Integer nodeId; | ||
|
||
public Integer getNodeId() { | ||
return nodeId; | ||
} | ||
|
||
public void setNodeId(Integer nodeId) { | ||
this.nodeId = nodeId; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/de/holarse/backend/db/datasets/SearchResultView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package de.holarse.backend.db.datasets; | ||
|
||
public interface SearchResultView { | ||
|
||
Integer getNodeId(); | ||
String getTitle(); | ||
String getUrl(); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/de/holarse/backend/db/repositories/SearchRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package de.holarse.backend.db.repositories; | ||
|
||
import de.holarse.backend.db.SearchIndex; | ||
import de.holarse.backend.db.datasets.SearchResultView; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Repository | ||
public interface SearchRepository extends JpaRepository<SearchIndex, Integer> { | ||
|
||
@Query(value = "select nodeid as nodeid, ptitle as title, purl as url from mv_searchindex " + | ||
"where document @@ websearch_to_tsquery('german', :query) " + | ||
"order by ts_rank(document, websearch_to_tsquery('german', :query)) desc", nativeQuery = true) | ||
List<SearchResultView> search(@Param("query") final String query); | ||
|
||
@Modifying | ||
@Query(value = "refresh materialized view mv_searchindex", nativeQuery = true) | ||
void refreshIndex(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/de/holarse/queues/commands/SearchRefresh.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package de.holarse.queues.commands; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Marker-Command, um das Materialized Refresh anzustossen | ||
* @author comrad | ||
*/ | ||
public class SearchRefresh implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/de/holarse/queues/consumers/SearchWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package de.holarse.queues.consumers; | ||
|
||
import de.holarse.backend.db.repositories.SearchRepository; | ||
import de.holarse.queues.commands.SearchRefresh; | ||
import static de.holarse.config.JmsQueueTypes.QUEUE_SEARCH; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jms.annotation.JmsListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class SearchWorker { | ||
|
||
private final static transient Logger log = LoggerFactory.getLogger(SearchWorker.class); | ||
|
||
@Autowired | ||
private SearchRepository searchRepository; | ||
|
||
@JmsListener(destination = QUEUE_SEARCH) | ||
public void importDrückblickEntries(final SearchRefresh cmd) { | ||
log.debug("Incoming Command to Refresh Materialized View"); | ||
searchRepository.refreshIndex(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.