Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 6d9b0887

Přidáno uživatelem smoldas15 před asi 4 roky(ů)

Re #7915: Zobrazení celého dokumentu na BE

- vytvořeno posílání jednoho dokumentu na FE
- úprava posílání názvů dokumentů na FE: nyní bez koncovky

Zobrazit rozdíly:

be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/IndexController.java
68 68
        return response;
69 69
    }
70 70

  
71
    @GetMapping("/documents/{documentName}")
72
    public DocumentDetailResponse listSingleDocument(@PathVariable String documentName) {
73
        LOG.trace("Method listSingleDocument called");
74
        String ret = "";
75

  
76
        try {
77
            LOG.debug("Calling SolrService and its listSingleFile method");
78
            ret = solrService.listSingleFile(documentName);
79
        } catch (Exception e) {
80
            LOG.error("Cannot get method listSingleFile from SolrService");
81
            LOG.error(e.toString());
82
        }
83
        return new DocumentDetailResponse(ret);
84
    }
85

  
71 86
    @GetMapping("/delete")
72 87
    public String delete() {
73 88
        LOG.trace("Method delete called");
be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/SolrService.java
46 46
    private static final String FIELD_TEXT_REGION_COORDS = "text_region" + SUFFIX_COORDS;
47 47
    private static final String FIELD_DOC_CONTENT = "doc_content";
48 48
    private static final String FIELD_IMG_CONTENT = "img_content";
49
    private static final float IMG_OUTPUT_QUALITY = 0.1f;
49
    private static final float IMG_OUTPUT_QUALITY = 0.5f;
50 50
    private static final Logger LOG = LoggerFactory.getLogger(IndexController.class);
51 51

  
52 52
    private static final int SEARCH_QUERY_ROWS = 100;
......
478 478
        solrQuery.set("q", FIELD_DOC_FILENAME + ":*");
479 479
        solrQuery.setRows(500); // todo not a magic number!
480 480
        SolrDocumentList docList = solrClientFiles.query(solrQuery).getResults();
481
        return docList.stream().map(doc -> doc.getFieldValue(FIELD_DOC_FILENAME).toString()).collect(Collectors.toList());
481
        return docList.stream().map(doc -> doc.getFieldValue(FIELD_DOC_FILENAME).toString().replaceAll(".xml", "")).collect(Collectors.toList());
482
    }
483

  
484
    public String listSingleFile(String documentName) throws IOException, SolrServerException {
485
        LOG.trace("SolrService method listSingleFile called");
486
        LOG.debug("Displaying single file in Solr");
487
        SolrQuery solrQuery = new SolrQuery();
488
        solrQuery.set("q", FIELD_DOC_FILENAME + ":*");
489
        //solrQuery.set("q", FIELD_DOC_FILENAME + ":" + documentName + ".xml");
490
        solrQuery.setRows(500); // todo not a magic number!
491
        SolrDocumentList docList = solrClientFiles.query(solrQuery).getResults();
492
        String ret = "";
493

  
494
        for (SolrDocument solrDocument : docList){
495
            if (solrDocument.getFieldValue(FIELD_DOC_FILENAME).toString().equals(documentName + ".xml")){
496
                String imgFilename = (String) solrDocument.getFieldValue(FIELD_IMG_FILENAME);
497
                byte[] imageBytes = getImageFromFilesCore(imgFilename);
498

  
499
                BufferedImage img = ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(imageBytes)));
500
                Image cropImg = new Image(img);
501
                cropImg.setOutputQuality(IMG_OUTPUT_QUALITY);
502

  
503
                imageBytes = cropImg.getByteArray();
504
                imageBytes = Base64.getEncoder().encode(imageBytes);
505
                ret = new String(imageBytes);
506
                break;
507
            }
508
        }
509
        if (ret.equals("")){
510
            LOG.error("File was NOT found in Solr");
511
        } else{
512
            LOG.debug("File was found in Solr");
513
        }
514
        return ret;
482 515
    }
483 516

  
484 517
}
be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/model/DocumentDetailResponse.java
1
package cz.zcu.kiv.aswi.fulltextsearch.model;
2

  
3
import java.util.Date;
4

  
5
public class DocumentDetailResponse {
6
    private String documentName;
7

  
8
    public DocumentDetailResponse(String documentName) {
9
        this.documentName = documentName;
10
    }
11

  
12
    public String getDocumentName() {
13
        return documentName;
14
    }
15

  
16
    public void setDocumentName(String documentName) {
17
        this.documentName = documentName;
18
    }
19
}

Také k dispozici: Unified diff