<commit_before>package eu.socialsensor.framework.client.search.solr;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.SolrQuery.ORDER;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.FacetField;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;

import com.google.gson.Gson;

import eu.socialsensor.framework.client.search.Bucket;
import eu.socialsensor.framework.client.search.Facet;
import eu.socialsensor.framework.client.search.SearchEngineResponse;
import eu.socialsensor.framework.common.domain.dysco.Dysco;

/**
 *
 * @author etzoannos - <EMAIL>
 */
public class SolrDyscoHandler {
	public final Logger logger = Logger.getLogger(SolrDyscoHandler.class);

    SolrServer server;
    private static final Map<String, SolrDyscoHandler> INSTANCES = new HashMap<String, SolrDyscoHandler>();

    // Private constructor prevents instantiation from other classes
    private SolrDyscoHandler(String collection) {
        try {

//                Logger.getRootLogger().info("going to create SolrServer: " + ConfigReader.getSolrHome() + "/dyscos");
        	server = new HttpSolrServer( collection );
           
        } catch (Exception e) {
        	
            Logger.getRootLogger().info(e.getMessage());
        }
    }
    //implementing Singleton pattern

    public static SolrDyscoHandler getInstance(String collection) {
    	SolrDyscoHandler INSTANCE = INSTANCES.get(collection);
    	if(INSTANCE == null) {
    		INSTANCE = new SolrDyscoHandler(collection);
    		INSTANCES.put(collection, INSTANCE);
    	}
        return INSTANCE;
    }

    public boolean insertDysco(Dysco dysco) {

        boolean status = false;
        try {
        	
            SolrDysco solrDysco = new SolrDysco(dysco);
            
            server.addBean(solrDysco);
           
            UpdateResponse response = server.commit();<commit_msg>change insertion for custom dysco and trending dysco<commit_after>package eu.socialsensor.framework.client.search.solr;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.SolrQuery.ORDER;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.FacetField;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;

import com.google.gson.Gson;

import eu.socialsensor.framework.client.search.Bucket;
import eu.socialsensor.framework.client.search.Facet;
import eu.socialsensor.framework.client.search.SearchEngineResponse;
import eu.socialsensor.framework.common.domain.dysco.CustomDysco;
import eu.socialsensor.framework.common.domain.dysco.Dysco;
import eu.socialsensor.framework.common.domain.dysco.Dysco.DyscoType;

/**
 *
 * @author etzoannos - <EMAIL>
 */
public class SolrDyscoHandler {
	public final Logger logger = Logger.getLogger(SolrDyscoHandler.class);

    SolrServer server;
    private static final Map<String, SolrDyscoHandler> INSTANCES = new HashMap<String, SolrDyscoHandler>();

    // Private constructor prevents instantiation from other classes
    private SolrDyscoHandler(String collection) {
        try {

//                Logger.getRootLogger().info("going to create SolrServer: " + ConfigReader.getSolrHome() + "/dyscos");
        	server = new HttpSolrServer( collection );
           
        } catch (Exception e) {
        	
            Logger.getRootLogger().info(e.getMessage());
        }
    }
    //implementing Singleton pattern

    public static SolrDyscoHandler getInstance(String collection) {
    	SolrDyscoHandler INSTANCE = INSTANCES.get(collection);
    	if(INSTANCE == null) {
    		INSTANCE = new SolrDyscoHandler(collection);
    		INSTANCES.put(collection, INSTANCE);
    	}
        return INSTANCE;
    }

    public boolean insertDysco(Dysco dysco) {

        boolean status = false;
        try {
        	SolrDysco solrDysco = null;
        	if(dysco.getDyscoType().equals(DyscoType.TRENDING))
        		solrDysco = new SolrDysco(dysco);
        	else{
        		CustomDysco customDysco = (CustomDysco) dysco;
        		solrDysco = new SolrDysco(customDysco);
        	}
        		
            server.addBean(solrDysco);
           
            UpdateResponse response = server.commit();
{'fraction_non_alphanumeric': 0.10153482880755609, 'fraction_numerical': 0.0003935458480913026, 'mean_word_length': 3.4315605928509156, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5566636', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1624, 'n_words': 279}