2017-11-09 8 views
0

매개 변수에서 주어진 태그 중 적어도 하나를 포함하는 첫 번째 개체를 검색하고 싶습니다.스프링 데이터 couchbase 목록 매개 변수가있는 N1QL

@Query("#{#n1ql.selectEntity} WHERE SOME t IN tags SATISFIES t IN [\"#{#currentTags}\"] " + 
     "END AND #{#n1ql.filter} LIMIT 1") 
RecipeEntry findFirstContainingTags(@Param("currentTags")List<String> tags); 

그러나 생성 된 N1QL 쿼리

"SELECT * FROM contents WHERE SOME t IN tags SATISFIES t IN ["tag1,tag2"] END LIMIT 1" 
입니다

예상 쿼리는

"SELECT * FROM contents WHERE SOME t IN tags SATISFIES t IN ["tag1","tag2"] END LIMIT 1" 

그래서 난 내 매개 변수 currentTags는 [ "tag1로", "이 tag2"로 전환 될 것으로 기대입니다 ] not [ "tag1, tag2"]

Spring 데이터로이 쿼리를 생성 할 의향이 있습니까? 자세한 내용은, 내가 무슨 짓을 아래

+0

는 = @query (이 쿼리를 시도 했습니까 "# {#의 n1ql.selectEntity} WHERE 일부 t IN IN 만족 t 태그 : {#의 currentTags} + #"END AND # {#의 n1ql.filter} ORDER BY creationDate DESC LIMIT 1 ") – ozgur

+0

따옴표를 제거하면 어떻게됩니까? (SATISFIES t IN [# {# currentTags}]) – marco

+0

Jpa Query IN [ "params"]을 사용할 수 없습니다. 이것은 원시 쿼리가 아닙니다. – ozgur

답변

0

:

  • 내가 매개 변수

서비스와 JSON 줘 JSON

  • 에 문자열의 내 목록을 변환 잭슨 objectMapper를 사용

    public RecipeEntry findMostRecentWithAtLeastTags(List<String> tags) { 
        RecipeEntry recipeEntry = null; 
        try { 
         String tagsArray = objectMapper.writeValueAsString(tags); 
         recipeEntry = ((RecipeQueryRepository) this.queryRepository).findMostRecentWithAtLeastTags(tagsArray); 
        } catch (Exception e) { 
         log.error("Error while retrieving most recent recipe with given tags", e); 
        } 
    
        return recipeEntry; 
    } 
    

    저장소 :

    @Query("#{#n1ql.selectEntity} WHERE status = 'PUBLISHED' AND (EVERY t IN #{#currentTags} SATISFIES t IN tags END) " + 
         "AND #{#n1ql.filter} ORDER BY publishDate DESC LIMIT 1") 
    RecipeEntry findMostRecentWithAtLeastTags(@Param("currentTags") String tags);