Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDBs全文搜索可以与SpringDataREST一起使用吗?_Mongodb_Spring Data Rest - Fatal编程技术网

MongoDBs全文搜索可以与SpringDataREST一起使用吗?

MongoDBs全文搜索可以与SpringDataREST一起使用吗?,mongodb,spring-data-rest,Mongodb,Spring Data Rest,我刚刚开始使用SpringDataREST,并希望为MongoDB中的文本索引字段公开一个查找器。我有以下索引定义: @TextIndexed private String title; public interface ContentRespository extends MongoRepository<Content, String> { public Page<Content> findByTitle(@Param("title") TextCriteri

我刚刚开始使用SpringDataREST,并希望为MongoDB中的文本索引字段公开一个查找器。我有以下索引定义:

@TextIndexed
private String title;
public interface ContentRespository extends MongoRepository<Content, String> {
    public Page<Content> findByTitle(@Param("title") TextCriteria title, @Param("pageable") Pageable pageable);
}
并验证已创建索引。我已经在存储库定义上创建了一个finder方法:

@TextIndexed
private String title;
public interface ContentRespository extends MongoRepository<Content, String> {
    public Page<Content> findByTitle(@Param("title") TextCriteria title, @Param("pageable") Pageable pageable);
}
我得到以下错误:

2017-01-19 13:16:41.831 ERROR 16705 --- [nio-8080-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.repository.support.QueryMethodParameterConversionException: Failed to convert test into org.springframework.data.mongodb.core.query.TextCriteria!] with root cause

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [@org.springframework.data.repository.query.Param  org.springframework.data.mongodb.core.query.TextCriteria]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:324) ~[spring-core-4.3.4.RELEASE.jar:4.3.4.RELEASE]
....

调用RESTAPI的正确方法是什么?我找不到关于它的任何文件。或者如何为TextCriteria编写转换器?

与mongo无关,但spring rest告诉您,它无法将传入字符串(来自web请求)转换为公开的方法参数。您有两个选项-创建并注册有问题的转换器或wrap方法,并自己将字符串转换为所需类型

与mongo无关-但spring rest告诉您,它无法将传入字符串(来自web请求)转换为公开的方法参数。您有两个选项-创建并注册有问题的转换器或wrap方法,并自己将字符串转换为所需类型

过了一段时间,我回到这里,通过使用@Query符号定义查找器找到了答案:

@Query("{$text: {$search: ?0}}")
public Page<Content> findByTitle(@Param("title") String title, @Param("pageable") Pageable pageable);
@Query(“{$text:{$search:?0}”)
公共页面findbytle(@Param(“title”)字符串标题,@Param(“pageable”)pageable pageable);

过了一段时间,我回到这里,通过使用@Query符号定义finder找到了答案:

@Query("{$text: {$search: ?0}}")
public Page<Content> findByTitle(@Param("title") String title, @Param("pageable") Pageable pageable);
@Query(“{$text:{$search:?0}”)
公共页面findbytle(@Param(“title”)字符串标题,@Param(“pageable”)pageable pageable);

是的,有没有编写这种转换器的示例?当然有。谷歌将帮助找到它。但是用某个类包装内容存储库会更容易,当然,我可以用谷歌搜索它,但我的问题更多的是关于通过RESTAPI访问文本索引字段的默认方式。索引字段的其他查找器方法是现成的。编写转换器将是第二个选项-关于注册自定义属性编辑器的部分是一个良好的开端。是的,有没有编写此类转换器的示例?当然有。谷歌将帮助找到它。但是用某个类包装内容存储库会更容易,当然,我可以用谷歌搜索它,但我的问题更多的是关于通过RESTAPI访问文本索引字段的默认方式。索引字段的其他查找器方法是现成的。编写转换器将是第二种选择——关于注册自定义属性编辑器的部分是一个良好的开端。