repEs.js 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
import axios from "axios";


class RepEs {

    constructor(config) {
        this.config = config
        this.index_url = config.index_url
        this.index_name = config.index_name
        this.url = this.index_url + '?index_name=' + this.index_name
    }

    query (keyword) {

        const url = this.url
        return new Promise(function(resolve,rejcet){
            axios.get(url,{
                params: {
                    keyword: encodeURI(keyword),
                }
            }).then(res => {

                if (res?.status === 200 && res?.data?.code === 200) {
                    const result = []
                    res?.data?.data?.hits.forEach(element => {
                        result.push({
                            page_content: element?._source?.content
                        })
                    });
                    resolve(result)

                }
                console.info(res)


            }).catch((err) => {
                console.error(err)
                rejcet()
            })
        })
        
    }

}

export default RepEs