38 lines
1.5 KiB
Java
38 lines
1.5 KiB
Java
package com.novelreader.repository;
|
|
|
|
import com.novelreader.model.NovelDO;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
|
import org.springframework.data.mongodb.repository.Query;
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
import java.util.List;
|
|
|
|
@Repository
|
|
public interface NovelRepository extends MongoRepository<NovelDO, String> {
|
|
|
|
@Query("{ $or: [ { 'name': { $regex: ?0, $options: 'i' } }, { 'author': { $regex: ?0, $options: 'i' } } ] }")
|
|
Page<NovelDO> findByNameOrAuthorContainingIgnoreCase(String keyword, Pageable pageable);
|
|
|
|
@Query("{ 'tags': { $in: ?0 } }")
|
|
Page<NovelDO> findByTagsIn(List<String> tags, Pageable pageable);
|
|
|
|
@Query("{ $and: [ { $or: [ { 'name': { $regex: ?0, $options: 'i' } }, { 'author': { $regex: ?0, $options: 'i' } } ] }, { 'tags': { $in: ?1 } } ] }")
|
|
Page<NovelDO> findByNameOrAuthorAndTags(String keyword, List<String> tags, Pageable pageable);
|
|
|
|
Page<NovelDO> findAll(Pageable pageable);
|
|
|
|
// 按作者精确匹配
|
|
List<NovelDO> findByAuthor(String author);
|
|
|
|
// 按书名前缀匹配(不分页,用于智能搜索)
|
|
@Query("{ 'name': { $regex: '^?0', $options: 'i' } }")
|
|
List<NovelDO> findByNameStartingWithIgnoreCase(String prefix);
|
|
|
|
// 按书名模糊匹配(不分页,用于智能搜索)
|
|
@Query("{ 'name': { $regex: ?0, $options: 'i' } }")
|
|
List<NovelDO> findByNameContainingIgnoreCase(String keyword);
|
|
}
|
|
|