class FAQServiceImpl implements FAQService, Constants {

    public Map<String, Object> getFAQSByWidget(String widgetId, String domainId)
            throws ServiceException {
        List<Map<String, Object>> faqs = new ArrayList<>();

        List<Map<String, Object>> faqByWidgetIdList;
        List<Map<String, Object>> releventfaqsByWidgetIdList = new ArrayList<>();
        try{
        faqByWidgetIdList= repository.getFAQSFromEs(
                widgetId, domainId);

        }catch(DataException e){
            throw new ServiceException(e);
        }
        List<String> faqId = new ArrayList<>();
        List<String> tags = new ArrayList<>();
        faqByWidgetIdList.parallelStream().forEach(faqDetailsMap -> {

            synchronized (faqId) {
                faqId.add('"' + faqDetailsMap.get("faqid").toString() + '"');
            }
            synchronized (tags) {
                tags.add('"' + faqDetailsMap.get("tag").toString() + '"');
            }

            Map<String, Object> faqDetails = new HashMap<>();
            faqDetails.put("faqName", faqDetailsMap.get("faqname"));
            faqDetails.put("faqAnswer", faqDetailsMap.get("answer"));
            synchronized (faqs) {
                faqs.add(faqDetails);
            }

        });
      try{  releventfaqsByWidgetIdList = repository.getRelevantFAQSFromEs(widgetId,
                domainId, tags, faqId, releventfaqsByWidgetIdList);
        }catch(DataException e){
            throw new ServiceException(e);
        }
        Map<String, Object> respoMap = new HashMap<>();
        respoMap.put("faq", faqs);
        respoMap.put("releventFaq", releventfaqsByWidgetIdList);
        if(respoMap.isEmpty()){
            throw new ServiceException(NO_DATA_FOUND);
        }
        return respoMap;
    }

}