您好我有以下查询,但是Spring数据solr为最后一个参数放入参数1值而不是param 10值:“AND days_ss :(?10)”......我猜它看到了?1而不是? 10
无论如何,我尝试使用:像JPA一样的日子,但这会干扰lucene语法
@Highlight(prefix = "<b>", postfix = "</b>")
@Query("""text:(?0) AND moduleLevel_s:(?1) AND programOfStudy_s:\"?2\" AND yearOfEntry_i:?3 AND yearOfStudy_i:?4 AND unitValue_d:?5 AND
department_s:(?6) AND teachers_ss:(?7) AND cappedAccess_b:?8 AND terms_ss:(?9) AND days_ss:(?10)""")
HighlightPage<CourseGuide> advancedSearch(@Param(value = "query") List<String> query,
@Param(value = "moduleLevel") List<ModuleLevel> moduleLevel,
@Param(value = "programOfStudy") String programOfStudy,
@Param(value = "yearOfEntry") def yearOfEntry,
@Param(value = "yearOfStudy") def yearOfStudy,
@Param(value = "unitValue") def unitValue,
@Param(value = "department") List<String> department,
@Param(value = "teachers") List<String> teachers,
@Param(value = "cappedAccess") def cappedAccess,
@Param(value = "terms") List<String> terms,
@Param(value = "days") List<String> days,Pageable pageable)
实际上发生的事情是,在它的param替换过程中,它在字符串中查找所有出现的“?1”并错误地弄乱了我的?10占位符。如果它在另一个方向上工作,事情可能会好起来,即先处理?10然后?9,然后是?8等等
答案 0 :(得分:1)
我有同样的问题。 我在Spring-data-solr上为这个问题创建了一个Jira,https://jira.spring.io/browse/DATASOLR-296?jql=text%20~%20%22%40Query%22%20ORDER%20BY%20created%20DESC
但我找到了解决方案。
您需要使用solrTemplate。
例如:
在你的solrConfiguration.java
中@Configuration
@EnableSolrRepositories(value = "com.project.repository.solr", multicoreSupport = true)
public class SolrConfiguration implements EnvironmentAware{
private RelaxedPropertyResolver propertyResolver;
private Environment environment;
@Override
public void setEnvironment(Environment environment) {
this.environment = environment;
this.propertyResolver = new RelaxedPropertyResolver(environment, "spring.data.solr.");
}
@Bean
public SolrServer solrServer() {
String solrHost = propertyResolver.getProperty("host");
return new HttpSolrServer(solrHost);
}
@Bean(name = "testSolrTemplate")
public SolrOperations testSolrTemplate() {
HttpSolrServer httpSolrServer = new HttpSolrServer(propertyResolver.getProperty("host"));
return new SolrTemplate(httpSolrServer, "TestCore");
}
}
然后在你的TestRepository.java
中public interface TestRepository extends TestRepositoryCustom, SolrRepository<Test, String>, SolrCrudRepository<Test, String> {
}
然后在你的TestRepositoryCustom.java
中interface TestRepositoryCustom {
public ArrayList<Test> findTests(
String arg1, String arg2, String arg3, String arg4, String arg5, String arg6, String arg7, String arg8, String arg9, String arg10, String arg11
);
}
然后在你的TestRepositoryImpl.java
中public class TestRepositoryImpl implements TestRepositoryCustom {
@Resource
private SolrTemplate testSolrTemplate;
@Override
public ArrayList<Test> findTests(
String arg1, String arg2, String arg3, String arg4, String arg5, String arg6, String arg7, String arg8, String arg9, String arg10, String arg11
) {
Criteria criteria = new Criteria(Criteria.WILDCARD).expression(Criteria.WILDCARD)
.and(new Criteria("arg1").expression(arg1))
.and(new Criteria("arg2").expression(arg2))
.and(new Criteria("arg3").expression(arg3))
.and(new Criteria("arg4").expression(arg4))
.and(new Criteria("arg5").expression(arg5))
.and(new Criteria("arg6").expression(arg6))
.and(new Criteria("arg7").expression(arg7))
.and(new Criteria("arg8").expression(arg8))
.and(new Criteria("arg9").expression(arg9))
.and(new Criteria("arg10").expression(arg10))
.and(new Criteria("arg11").expression(arg11))
;
return new ArrayList<>(testSolrTemplate.queryForPage(new SimpleQuery(criteria).setRows(2147483647), Test.class).getContent());
}
}
最好,托马斯