dnet-applications/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/repository/readonly/OrganizationSimpleViewRepos...

30 lines
1.6 KiB
Java
Raw Normal View History

2020-07-03 12:09:22 +02:00
package eu.dnetlib.organizations.repository.readonly;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
2020-10-01 11:33:14 +02:00
import org.springframework.data.repository.query.Param;
2020-07-03 12:09:22 +02:00
import org.springframework.stereotype.Repository;
import eu.dnetlib.organizations.model.view.OrganizationSimpleView;
@Repository
public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<OrganizationSimpleView, String> {
// SEARCH
@Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) where idx.txt @@ plainto_tsquery(:text) order by o.name", nativeQuery = true)
2020-10-01 11:33:14 +02:00
Page<OrganizationSimpleView> search(@Param("text") String text, Pageable pageable);
2020-07-03 12:09:22 +02:00
// SEARCH FOR USER
@Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) left outer join user_countries uc on (uc.country = o.country) where idx.txt @@ plainto_tsquery(:text) and uc.email = :email order by o.name", nativeQuery = true)
2020-10-01 11:33:14 +02:00
Page<OrganizationSimpleView> searchForUser(@Param("text") String text, @Param("email") String email, Pageable pageable);
2020-07-03 12:09:22 +02:00
Page<OrganizationSimpleView> findByCountryOrderByName(String country, Pageable pageable);
2020-07-03 12:09:22 +02:00
Page<OrganizationSimpleView> findByTypeOrderByName(String type, Pageable pageable);
2020-07-03 12:09:22 +02:00
@Query(value = "select o.* from organizations_simple_view o left outer join user_countries uc on (uc.country = o.country) where uc.email = ?2 and o.type = ?1 order by o.name", nativeQuery = true)
2020-07-03 12:09:22 +02:00
Page<OrganizationSimpleView> findByTypeForUser(String type, String name, Pageable pageable);
}