-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR allows theme authors to create a search page respectively. ```release-note 允许主题自定义搜索模板 ```
- Loading branch information
Showing
3 changed files
with
50 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package run.halo.search.widget; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.server.*; | ||
import reactor.core.publisher.Mono; | ||
import run.halo.app.search.SearchOption; | ||
import run.halo.app.search.SearchService; | ||
|
||
import java.util.Map; | ||
|
||
@Component | ||
public class SearchView { | ||
|
||
private final SearchService searchService; | ||
|
||
public SearchView(SearchService searchService) { | ||
this.searchService = searchService; | ||
} | ||
|
||
@Bean | ||
RouterFunction<ServerResponse> searchView() { | ||
return RouterFunctions.route() | ||
.GET("/search", RequestPredicates.accept(MediaType.TEXT_HTML), this::performSearch) | ||
.build(); | ||
} | ||
|
||
private Mono<ServerResponse> performSearch(ServerRequest serverRequest) { | ||
var keyword = serverRequest.queryParam("keyword").orElse(""); | ||
var limit = serverRequest.queryParam("limit") | ||
.map(Integer::parseInt) | ||
.orElse(10); | ||
var includeTypes = serverRequest.queryParams().get("includeTypes"); | ||
var option = new SearchOption(); | ||
option.setKeyword(keyword); | ||
option.setLimit(limit); | ||
option.setFilterExposed(true); | ||
option.setFilterPublished(true); | ||
option.setFilterRecycled(false); | ||
option.setIncludeTypes(includeTypes); | ||
var result = searchService.search(option); | ||
return ServerResponse.ok().render("search", Map.of( | ||
"searchResult", result | ||
)); | ||
} | ||
} |
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