Haciendo ajestes al buscador, empezando con operaciones de busqueda y detalles internas de la busqueda

master
vicsash 5 months ago
parent 0440e82747
commit 88fb8b99c2

@ -5,15 +5,20 @@ import com.example.proyectofinal.repositories.empresas.ContactoRepository;
import com.example.proyectofinal.repositories.empresas.OfertaRepository; import com.example.proyectofinal.repositories.empresas.OfertaRepository;
import com.example.proyectofinal.repositories.empresas.SucursalRepository; import com.example.proyectofinal.repositories.empresas.SucursalRepository;
import com.github.javafaker.Faker; import com.github.javafaker.Faker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@Configuration @Configuration
public class DatabaseTest { public class DatabaseTest {
@Autowired
private DataSource dataSource;
@Bean @Bean
CommandLineRunner initDatabase(AlumnoRepository alumnoRepository, ContactoRepository contactoRepository, SucursalRepository sucursalRepository, OfertaRepository ofertaRepository) { CommandLineRunner initDatabase(AlumnoRepository alumnoRepository, ContactoRepository contactoRepository, SucursalRepository sucursalRepository, OfertaRepository ofertaRepository) {
@ -80,6 +85,9 @@ public class DatabaseTest {
); );
ofertaRepository.save(oferta); ofertaRepository.save(oferta);
} }
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON empresas(keywords,nombre)");
}; };
} }
} }

@ -1,14 +1,36 @@
package com.example.proyectofinal.controllers; package com.example.proyectofinal.controllers;
import org.springframework.ui.Model;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.repositories.empresas.EmpressaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@Controller @Controller
@RequestMapping("/buscador") @RequestMapping("/buscador")
public class BuscadorController { public class BuscadorController {
@Autowired
private EmpressaRepository empressaRepository;
@GetMapping @GetMapping
public String buscador(){ public String buscador(){
return "buscador"; return "buscador_admin";
}
@GetMapping("/search")
public String search(@RequestParam String query, @RequestParam(required = false) String optempresa, String optskill, String optalumno, String optoferta, Model model) {
if(optempresa != null){
ArrayList<Empresa> empresas = empressaRepository.getEmpressaByKeywordsOrName("*"+query+"*");
model.addAttribute("empresas", empresas);
}
return "list_empresas";
} }
} }

@ -13,7 +13,7 @@ import java.util.Set;
//@Getter //@Getter
//@Setter //@Setter
@Data @Data
@Table(name = "Alumno") @Table(name = "alumnos")
public class Alumno { public class Alumno {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@ -45,6 +45,8 @@ public class Alumno {
@NonNull @NonNull
@Column(length = 45) @Column(length = 45)
private String keyword; private String keyword;
//TODO Añadir campos adicinales en alumno dni,correo 1 y 2,
// nacionalidad, domicillo y otros adicionales si hay necesidad
@ManyToMany(cascade = {CascadeType.PERSIST,CascadeType.REFRESH},fetch = FetchType.EAGER) @ManyToMany(cascade = {CascadeType.PERSIST,CascadeType.REFRESH},fetch = FetchType.EAGER)
@JoinTable( @JoinTable(

@ -10,7 +10,7 @@ import lombok.NonNull;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Data @Data
@Table(name = "Empresa") @Table(name = "empresas")
public class Empresa { public class Empresa {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@ -30,7 +30,7 @@ public class Empresa {
@NonNull @NonNull
@Column(length = 45) @Column(length = 45)
private String telefono1; private String telefono;
@NonNull @NonNull
@ -45,7 +45,7 @@ public class Empresa {
this.nombre = nombre; this.nombre = nombre;
this.cif = cif; this.cif = cif;
this.correo = correo; this.correo = correo;
this.telefono1 = telefono1; this.telefono = telefono1;
this.keywords = keywords; this.keywords = keywords;
this.sector = sector; this.sector = sector;
} }

@ -2,6 +2,16 @@ package com.example.proyectofinal.repositories.empresas;
import com.example.proyectofinal.models.empresas.Empresa; import com.example.proyectofinal.models.empresas.Empresa;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.ArrayList;
public interface EmpressaRepository extends JpaRepository<Empresa, Long> { public interface EmpressaRepository extends JpaRepository<Empresa, Long> {
//There is no value= here so Empresa is the table name
@Query("Select u from Empresa u where u.nombre LIKE ?1")
public Empresa getEmpressa(String empressa);
//there is value = and nativeQuery = true so the query is written in SQL refering to the table in the database
@Query(value = "Select * FROM empresas u where MATCH(u.nombre, u.keywords) AGAINST( ?1 in boolean mode)",nativeQuery = true)
public ArrayList<Empresa> getEmpressaByKeywordsOrName(String keyword1);
} }

@ -0,0 +1,67 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Buscador</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 10px;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
form {
display: flex;
flex-direction: column;
align-items: center;
width: 50%;
}
.search-container {
display: flex;
width: 100%;
justify-content: space-between;
}
input[type="text"] {
flex-grow: 1;
padding: 15px;
margin-right: 10px;
font-size: 18px;
}
.checkboxes {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
width: 50%;
margin-top: 20px;
}
</style>
</head>
<body>
<form action="/buscador/search" method="get" id="searchForm">
<div class="search-container" id="searchContainer">
<input type="text" name="query" placeholder="Buscar...">
<input type="submit" value="Buscar">
</div>
<div class="checkboxes">
<input type="checkbox" id="optionEmpresa" name="optempresa" value="OptEmpresa">
<label for="optionEmpresa"> Empresa por nombre y/o keywords</label><br>
<input type="checkbox" id="optionEmpresaPorSecot" name="optempporsector" value="optionEmpresaPorSecot">
<label for="optionEmpresaPorSecot"> Empresa por Sector</label><br>
<input type="checkbox" id="optionAlumno" name="optalumno" value="OptAlumno">
<label for="optionAlumno">Alumno</label><br>
<input type="checkbox" id="optionOferta" name="optoferta" value="OptOferta">
<label for="optionOferta"> Oferta</label><br>
<input type="checkbox" id="optionSkill" name="optskill" value="OptSkill" disabled>
<label for="optionSkill"> Skill</label><br>
</div>
</form>
<script>
window.onload = function() {
document.querySelector('form').reset();
};
</script>
</body>
</html>

@ -8,15 +8,21 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 100vh; height: 100vh;
margin: 0; margin: 10px;
background-color: #f0f0f0; background-color: #f0f0f0;
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
} }
form { form {
display: flex; display: flex;
justify-content: space-between; flex-direction: column;
align-items: center;
width: 50%; width: 50%;
} }
.search-container {
display: flex;
width: 100%;
justify-content: space-between;
}
input[type="text"] { input[type="text"] {
flex-grow: 1; flex-grow: 1;
padding: 15px; padding: 15px;
@ -25,8 +31,9 @@
} }
.checkboxes { .checkboxes {
display: flex; display: flex;
flex-direction: column; flex-direction: row;
justify-content: space-between; justify-content: space-between;
align-items: center;
width: 50%; width: 50%;
margin-top: 20px; margin-top: 20px;
} }
@ -34,16 +41,16 @@
</head> </head>
<body> <body>
<form action="#" method="get"> <form action="#" method="get">
<div class="search-container">
<input type="text" name="query" placeholder="Buscar..."> <input type="text" name="query" placeholder="Buscar...">
<input type="submit" value="Buscar"> <input type="submit" value="Buscar">
</div>
<div class="checkboxes">
<input type="checkbox" id="optionSkill" name="optskill" value="OptEmpresa">
<label for="optionSkill"> Skill</label><br>
<input type="checkbox" id="optionOferta" name="optoferta" value="OptOferta">
<label for="optionOferta"> Oferta</label><br>
</div>
</form> </form>
<div class="checkboxes">
<input type="checkbox" id="option1" name="option1" value="Option1">
<label for="option1"> Option 1</label><br>
<input type="checkbox" id="option2" name="option2" value="Option2">
<label for="option2"> Option 2</label><br>
<input type="checkbox" id="option3" name="option3" value="Option3">
<label for="option3"> Option 3</label><br>
</div>
</body> </body>
</html> </html>

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<meta charset="UTF-8">
<title>Title</title>
<style>
.keywords-cell {
max-width: 10px;
overflow-y: auto;
}
</style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
<div class="table">
<h1>Listado de Empresas</h1>
<table class ="table table-hover table-responsive-xl">
<thead class="thread-light">
<tr>
<th>Id</th>
<th>Nombre</th>
<th>Apellido 1</th>
<th>Apellido 2</th>
<th>Fecha Nacimiento</th>
<th>NIA</th>
<th>Keywords</th>
<th>Skills</th>
<th>Ciclo</th>
</tr>
</thead>
<tbody>
<tr th:each="alumno :${alumnos}">
<td>[[${alumno.id}]]</td>
<td>[[${alumno.nombre}]]</td>
<td>[[${alumno.apellido}]]</td>
<td>[[${alumno.apellido2}]]</td>
<td>[[${alumno.fechaNacimiento}]]</td>
<td>[[${alumno.genero}]]</td>
<td>[[${alumno.nia}]]</td>
<td class="keywords-cell" th:each="keyword : ${#strings.arraySplit(empresa.keywords, ',')}">[[${keyword}]]</td>
<td>[[${alumno.ciclo}]]</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<meta charset="UTF-8">
<title>Title</title>
<style>
.keywords-cell {
max-height: 50px; /* Adjust as needed */
overflow-y: auto;
}
</style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
<div class="table">
<h1>Listado de Empresas</h1>
<table class ="table table-hover table-responsive-xl">
<thead class="thread-light">
<tr>
<th>Id</th>
<th>Nombre</th>
<th>Cif</th>
<th>Correo</th>
<th>Telefono</th>
<th class="keywords-cell">Keywords</th>
<th>Sector</th>
</tr>
</thead>
<tbody>
<tr th:each="empresa :${empresas}">
<td>[[${empresa.id}]]</td>
<td>[[${empresa.nombre}]]</td>
<td>[[${empresa.cif}]]</td>
<td>[[${empresa.correo}]]</td>
<td>[[${empresa.telefono}]]</td>
<td class="keywords-cell">
<div th:each="keyword : ${#strings.arraySplit(empresa.keywords, ',')}">[[${keyword}]]</div>
</td>
<td>[[${empresa.sector.nombre}]]</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.