Skip to content

Commit

Permalink
pesquisa por regex
Browse files Browse the repository at this point in the history
  • Loading branch information
AdsonEsteves committed Jan 23, 2021
1 parent 36b65ea commit f9c89d3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 23 deletions.
Binary file modified board.bkp
Binary file not shown.
15 changes: 12 additions & 3 deletions src/main/java/sacip/rest/RestTutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -58,20 +59,28 @@ public String getInfo(){
}
}

@GetMapping("/buscarConteudo")
@PostMapping("/buscarConteudo")
public String getConteudos(@RequestBody JsonNode dados){
try {
ServiceWrapper wrapper = AgentServer.require("SACIP", "findContents");
ArrayNode tags = ((ArrayNode)dados.get("tags"));

wrapper.addParameter("name", dados.get("nome").asText());
if(dados.has("nome"))
wrapper.addParameter("~name", dados.get("nome").asText());
if(dados.has("topico"))
wrapper.addParameter("topic", dados.get("topico").asText());
if(dados.has("taxonomia"))
wrapper.addParameter("taxonomy", dados.get("taxonomia").asText());
if(dados.has("nivel"))
wrapper.addParameter("level", dados.get("nivel").asText());
if(dados.has("exercicio"))
wrapper.addParameter("exercise", dados.get("exercicio").asBoolean());
if(dados.has("tags"))
wrapper.addParameter("tags", new ObjectMapper().convertValue(tags, String[].class));

List run = wrapper.run();
if(run.isEmpty())
return run.toString();
return new ObjectMapper().valueToTree(run.get(0)).toString();
} catch (Exception e) {
LOG.error("Falhou ao pegar trilha", e);
return "Falhou ao pegar trilha: \n"+e.getLocalizedMessage();
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/sacip/sti/agents/RecommenderAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,14 @@ public int compare(Content o1, Content o2) {

List<Content> top10Conteudos = new ArrayList<>();

for (int i = 0; i < 10; i++) {
top10Conteudos.add(sortedContent.get(i));
if(sortedContent.size()>=10)
{
for (int i = 0; i < 10; i++) {
top10Conteudos.add(sortedContent.get(i));
}
}
else{
top10Conteudos.addAll(sortedContent);
}

//retornando conteudos
Expand Down
61 changes: 43 additions & 18 deletions src/main/java/sacip/sti/components/DBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ else if(entry.getValue() instanceof Integer[])
query.replace(query.length()-3, query.length(), "");
}
query.append("\nRETURN n");

//realisa a busca
var result = cypher.readquery(query.toString(), attributes);
if(result.isEmpty())
Expand Down Expand Up @@ -461,33 +461,58 @@ private Object getContents(Map<String, Object> attributes)
StringBuilder query = new StringBuilder("MATCH (n:CONTENT)");
if(!attributes.isEmpty())
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
query.append("\nWHERE n.");
query.append(entry.getKey());
query.append(" IN [");
if(entry.getValue() instanceof String[])
query.append("\nWITH*");
query.append("\nWHERE ");
if(entry.getKey().equals("tags"))
{
String[] attrs = (String[]) entry.getValue();
for (String attr : attrs) {
query.append("'"+attr+"',");
query.append("all(tags IN ");
query.append("[ ");
String[] tags = (String[]) entry.getValue();
for (String tag : tags) {
query.append("'"+tag+"',");
}
query.deleteCharAt(query.length()-1);
query.append("] ");
query.append("WHERE tags IN n.tags) ");
}
else if(entry.getValue() instanceof Integer[])
else if(entry.getKey().equals("~name"))
{
Integer[] attrs = (Integer[]) entry.getValue();
for (Integer attr : attrs) {
query.append(attr+",");
}
query.deleteCharAt(query.length()-1);
query.append("n.name =~ ");
query.append("'(?i).*"+entry.getValue()+".*'");
}
else
{
query.append("'"+entry.getValue()+"'");
}
query.append("]");
query.append("n.");
query.append(entry.getKey());
query.append(" IN [");
if(entry.getValue() instanceof String[])
{
String[] attrs = (String[]) entry.getValue();
for (String attr : attrs) {
query.append("'"+attr+"',");
}
query.deleteCharAt(query.length()-1);
}
else if(entry.getValue() instanceof Integer[])
{
Integer[] attrs = (Integer[]) entry.getValue();
for (Integer attr : attrs) {
query.append(attr+",");
}
query.deleteCharAt(query.length()-1);
}
else if(entry.getValue() instanceof Boolean)
{
query.append(entry.getValue());
}
else
{
query.append("'"+entry.getValue()+"'");
}
query.append("]");
}
}
query.append("\nRETURN n");

//realisa a busca
var result = cypher.readquery(query.toString(), attributes);
if(result.isEmpty())
Expand Down

0 comments on commit f9c89d3

Please sign in to comment.