<commit_before>package uk.ac.ebi.quickgo.geneproduct.common;

import java.io.File;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.core.CoreContainer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.repository.support.SolrRepositoryFactory;
import org.springframework.data.solr.server.SolrServerFactory;
import org.springframework.data.solr.server.support.MulticoreSolrServerFactory;
import org.xml.sax.SAXException;

/**
 * Publishes the configuration beans of the ontology repository.
 */
@Configuration
public class RepoConfig {
    private static final String SOLR_CORE = "geneproduct";

    @Bean
    static PropertySourcesPlaceholderConfigurer propertyPlaceHolderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    @Bean(name = "solrServer")
    @Profile("httpServer")
    public SolrServer httpSolrServer(@Value("${solr.host}") String solrUrl)  {
        return new HttpSolrServer(solrUrl);
    }

    @Bean(name = "solrServer")
    @Profile("embeddedServer")
    public SolrServer embeddedSolrServer(SolrServerFactory solrServerFactory) {
        return solrServerFactory.getSolrServer();
    }

    @Bean
    @Profile("embeddedServer")
    public SolrServerFactory solrServerFactory(CoreContainer coreContainer)
            throws IOException, SAXException, ParserConfigurationException {
        EmbeddedSolrServer embeddedSolrServer = new EmbeddedSolrServer(coreContainer, SOLR_CORE);
        return new MulticoreSolrServerFactory(embeddedSolrServer);
    }

    @Bean
    @Profile("embeddedServer")
    public CoreContainer coreContainer(@Value("${solr.solr.home}") String solrHome) {
        CoreContainer container = new CoreContainer(new File(solrHome).getAbsolutePath());
        container.load();
        return container;
    }

    @Bean
    public SolrTemplate geneProductTemplate(SolrServer solrServer)  {
        return new SolrTemplate(solrServer, "geneproduct");
    }

    @Bean
    public GeneProductRepository geneProductRepository(SolrTemplate geneProductTemplate) {
        return new SolrRepositoryFactory(geneProductTemplate)
                .getRepository(GeneProductRepository.class);
    }
}<commit_msg>Reuse SOLR_CORE constant to declare core in geneProductTemplate.<commit_after>package uk.ac.ebi.quickgo.geneproduct.common;

import java.io.File;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.core.CoreContainer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.repository.support.SolrRepositoryFactory;
import org.springframework.data.solr.server.SolrServerFactory;
import org.springframework.data.solr.server.support.MulticoreSolrServerFactory;
import org.xml.sax.SAXException;

/**
 * Publishes the configuration beans of the ontology repository.
 */
@Configuration
public class RepoConfig {
    private static final String SOLR_CORE = "geneproduct";

    @Bean
    static PropertySourcesPlaceholderConfigurer propertyPlaceHolderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    @Bean(name = "solrServer")
    @Profile("httpServer")
    public SolrServer httpSolrServer(@Value("${solr.host}") String solrUrl)  {
        return new HttpSolrServer(solrUrl);
    }

    @Bean(name = "solrServer")
    @Profile("embeddedServer")
    public SolrServer embeddedSolrServer(SolrServerFactory solrServerFactory) {
        return solrServerFactory.getSolrServer();
    }

    @Bean
    @Profile("embeddedServer")
    public SolrServerFactory solrServerFactory(CoreContainer coreContainer)
            throws IOException, SAXException, ParserConfigurationException {
        EmbeddedSolrServer embeddedSolrServer = new EmbeddedSolrServer(coreContainer, SOLR_CORE);
        return new MulticoreSolrServerFactory(embeddedSolrServer);
    }

    @Bean
    @Profile("embeddedServer")
    public CoreContainer coreContainer(@Value("${solr.solr.home}") String solrHome) {
        CoreContainer container = new CoreContainer(new File(solrHome).getAbsolutePath());
        container.load();
        return container;
    }

    @Bean
    public SolrTemplate geneProductTemplate(SolrServer solrServer)  {
        return new SolrTemplate(solrServer, SOLR_CORE);
    }

    @Bean
    public GeneProductRepository geneProductRepository(SolrTemplate geneProductTemplate) {
        return new SolrRepositoryFactory(geneProductTemplate)
                .getRepository(GeneProductRepository.class);
    }
}
{'fraction_non_alphanumeric': 0.08812398630383853, 'fraction_numerical': 0.0, 'mean_word_length': 4.848261327713383, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5760512', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1511, 'n_words': 271}