Fulltext Mysql with Spring Boot

Asked

Viewed 41 times

0

Good morning, I am trying to make a fulltext in mysql with spring boot, in mysql when I do the test with the sql command, the result brings back correctly, but when I pass the spring boot sql Native, it brings an empty list.

Positionrepository

@Query(nativeQuery = true, value = "SELECT * FROM position WHERE MATCH (name, area) AGAINST (':description' IN BOOLEAN MODE)")
List<Position> searchByNameAndArea(@Param("description") String name);

Positionservice

public List<Position> searchByNameAndArea(String name) {
    return positionRepository.searchByNameAndArea(name);
}

Positioncontroller

@GetMapping("/search")
public List<Position> searchByNameAndArea(@RequestParam String name) {
    return positionService.searchByNameAndArea(name);
}

After I run the project, I walk into the bank and turn the remote

ALTER TABLE position ADD FULLTEXT (NAME, AREA);

URL used in Postman

localhost:8080/position/search?name=position

Model da Position

@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Entity
@Table(name = "position")
public class Position {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@EqualsAndHashCode.Include
private Long id;

@NotNull
private String name;

@NotNull
private String area;

}

Could someone help me, please.

  • How is the mapping of the Position class

  • I updated the question with Model.

  • From what I noticed the sql command is not able to catch the name I pass as parameter, because if I leave the automatic word without parameter, it can bring the result.

  • @Query(nativeQuery = true, value = "SELECT * FROM position WHERE MATCH (name, area) AGAINST ('position' IN BOOLEAN MODE)")

1 answer

0

Good afternoon, everyone,

@Query(nativeQuery = true, value = "SELECT * FROM position WHERE MATCH (name, area) AGAINST (':description' IN BOOLEAN MODE)")
List<Position> searchByNameAndArea(@Param("description") String name);

I was able to solve my problem, in AGAINST (:Description IN BOOLEAN MODE) does not need the simple quotes in the word :Description, removing it, the result appears correctly.

  • How it works : SELECT * FROM position WHERE MATCH (name, area) AGAINST (?1 IN BOOLEAN MODE)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.