2016-04-04 10 views
0

こんにちは私は次のクエリを持っていますが、springデータsolrは最後のparamのparam 10の値の代わりにparam 1の値を入れています: "AND days_ss :(?10)"。 ??のような日は、JPAで行うことができますが、起こってはということですいただきました!これはSpring Data Solr - @Query parameters "?10"

@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) 

実際にLuceneの構文を妨げる:..私はそれがこの周りとにかく1及びません10

を見ていると思い、私が使用してみましたパラメタの置換処理中に、文字列内に「?1」がすべて出現し、誤って「?10」というプレースホルダがつぶれています。それが他の方向に働いていれば、おそらくプロセスは?10、最初に?9、次に?8など

答えて

1

私は同じ問題があります。 この問題のSpring-data-solrにJiraを作成しました。https://jira.spring.io/browse/DATASOLR-296?jql=text%20~%20%22%40Query%22%20ORDER%20BY%20created%20DESC

解決策が見つかりました。

solrTemplateを使用する必要があります。

Exemple:あなたの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 
    ); 
} 

Tにおけるその後、あなたのTestRepository.java

public interface TestRepository extends TestRepositoryCustom, SolrRepository<Test, String>, SolrCrudRepository<Test, String> { 
} 

でその後、あなたの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"); 
    } 
} 

あなたの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()); 
    } 

} 

ベスト、トーマス