我有一个域名
@Document
public @Data class Note {
@Id
private String noteId;
private String owner;
@TextIndexed
private String name;
@TextIndexed
private String text;
private List<Tag> tags;
private LocalDate date;具有两个索引字段- name和text。我想通过这些字段执行全文搜索。
期望搜索条件的Rest如下所示
@GetMapping("/notes-rest/search/custom")
public List<Note> searchNotes(@RequestParam("criteria") String searchCriteria) {
LOGGER.info("Attempt to perform full text search by criteria: [{}].", searchCriteria);
return searchRepository.findNotesByCriteria(searchCriteria);
}我像这样传递代码
localhost:8080/notes-rest/search/custom?criteria={'name':'1234', 'text': 'trx'}执行全文搜索的存储库方法如下所示
@Repository
public class SearchRepository implements ISearchRepository {
@Autowired
private MongoTemplate template;
@Override
public List<Note> findNotesByCriteria(String searchCriteria) {
TextCriteria criteria = TextCriteria.forDefaultLanguage().matching(searchCriteria);
Query query = TextQuery.queryText(criteria);
return template.find(query, Note.class);
}
}但是,无论我传递什么,它总是返回数据库中的全部数据
[
{
"noteId": "594eae353bc51592f432b62e",
"owner": "xxx",
"name": "xxx note",
"text": "My text",
"tags": [
{
"tagId": null,
"tag": "basic2"
}
],
"date": [
1997,
12,
15
]
},
{
"noteId": "594ea38a3bc5150070d0aed2",
"owner": "system",
"name": "system note",
"text": "My text",
"tags": [
{
"tagId": "594e629b3bc5150f4c869905",
"tag": "basic"
}
],
"date": [
1997,
12,
15
]
},
{
"noteId": "594ea0ae3bc5150ad88a1dfc",
"owner": "borland",
"name": "borland note",
"text": "My text",
"tags": null,
"date": [
1992,
12,
15
]
}
]有什么问题吗?
发布于 2017-06-25 04:42:22
我将搜索条件的格式更改为{name:"borl", text: "t"},它似乎开始正常工作
https://stackoverflow.com/questions/44739732
复制相似问题