# fullSearch (Query method)

### Repository

Tudo permanece o mesmo, só trocamos o retorno.

```java
@Query("{ $and: [ { date: {$gte: ?1} }, { date: { $lte: ?2} } , { $or: [ { 'title': { $regex: ?0, $options: 'i' } }, { 'body': { $regex: ?0, $options: 'i' } }, { 'comments.text': { $regex: ?0, $options: 'i' } } ] } ] }")
Flux<Post> fullSearch(String text, Instant minDate, Instant maxDate);
```

### **Service**

**Antes**

```java
public List<PostDTO> fullSearch(String text, Instant minDate, Instant maxDate) {
    maxDate = maxDate.plusSeconds(86400); // 24 * 60 * 60
    List<PostDTO> result = repository.fullSearch(text, minDate, maxDate).stream().map(x -> new PostDTO(x)).toList();
    return result;
}
```

**Depois**

```java
public Flux<PostDTO> fullSearch(String text, Instant minDate, Instant maxDate) {
    maxDate = maxDate.plusSeconds(86400); // 24 * 60 * 60
    return repository.fullSearch(text, minDate, maxDate)
            .map(PostDTO::new)
            .switchIfEmpty(Mono.error(new ResourceNotFoundException("Recurso não encontrado")));
}
```

### **Controller**

**Antes**

```java
@GetMapping(value = "/fullsearch")
public ResponseEntity<List<PostDTO>> fullSearch(
			@RequestParam(value = "text", defaultValue = "") String text,
			@RequestParam(value = "minDate", defaultValue = "") String minDate,
			@RequestParam(value = "maxDate", defaultValue = "") String maxDate) throws UnsupportedEncodingException, ParseException {
		
    text = URL.decodeParam(text);
    Instant min = URL.convertDate(minDate, Instant.EPOCH);
    Instant max = URL.convertDate(maxDate, Instant.now());
		
    List<PostDTO> list = service.fullSearch(text, min, max);
    return ResponseEntity.ok(list);
}
```

**Depois**

```java
@GetMapping(value = "/fullsearch")
public Flux<PostDTO> fullSearch(
			@RequestParam(value = "text", defaultValue = "") String text,
			@RequestParam(value = "minDate", defaultValue = "") String minDate,
			@RequestParam(value = "maxDate", defaultValue = "") String maxDate) throws UnsupportedEncodingException, ParseException {
		
    text = URL.decodeParam(text);
    Instant min = URL.convertDate(minDate, Instant.EPOCH);
    Instant max = URL.convertDate(maxDate, Instant.now());
		
    return service.fullSearch(text, min, max);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://olavo-moreira.gitbook.io/studies/spring-webflux-mongodb/endpoints-com-mongo-reativo/post/fullsearch-query-method.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
