<commit_before>package uk.ac.ebi.phis.service;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;


public class BasicService {


	protected HttpSolrServer solr;
	

	public BasicService(String solrUrl) {
		solr = new HttpSolrServer(solrUrl);
	}
	
	public QueryResponse getDocuments(int rows, int start) 
	throws SolrServerException{

		SolrQuery solrQuery = new SolrQuery();
		solrQuery.setQuery("*:*");
		solrQuery.setRows(rows);
		solrQuery.setStart(start);
		return solr.query(solrQuery);		
	}
	
	public QueryResponse getDocumentsById(String field, String fieldValue) 
	throws SolrServerException{

		SolrQuery solrQuery = new SolrQuery();
		solrQuery.setQuery(field + ":\"" + fieldValue +"\"");
		return solr.query(solrQuery);		
	}
	
	public String handleSpecialCharacters(String query){

		query = query.replace("\\", "\\\\");
		query = query.replace("%5C", "\\\\");
		
		query = query.replace("[", "\\[");
		query = query.replace("]", "\\]");
		query = query.replace("{", "\\{");
		query = query.replace("}", "\\}");
		query = query.replace("|", "\\|");
		query = query.replace("<", "\\<");
		query = query.replace(">", "\\>");
		query = query.replace("."  , "\\.");
		query = query.replace("("  , "\\(");
		query = query.replace(")"  , "\\)");
		query = query.replace("/", "\\/");
		query = query.replace("`", "\\`");
		query = query.replace("~"  , "\\~"); 
		query = query.replace("%"  , "\\%");

		query = query.replace("%7B", "\\{");
		query = query.replace("%7D", "\\}");
		query = query.replace("%7C", "\\|");
		query = query.replace("%3C", "\\<");
		query = query.replace("%3E", "\\>");
		query = query.replace("%2F", "\\/");
		query = query.replace("%60", "\\`");
		return query;
	}<commit_msg>Fix in handeling special characters for autosuggest.<commit_after>package uk.ac.ebi.phis.service;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;


public class BasicService {


	protected HttpSolrServer solr;
	

	public BasicService(String solrUrl) {
		solr = new HttpSolrServer(solrUrl);
	}
	
	public QueryResponse getDocuments(int rows, int start) 
	throws SolrServerException{

		SolrQuery solrQuery = new SolrQuery();
		solrQuery.setQuery("*:*");
		solrQuery.setRows(rows);
		solrQuery.setStart(start);
		return solr.query(solrQuery);		
	}
	
	public QueryResponse getDocumentsById(String field, String fieldValue) 
	throws SolrServerException{

		SolrQuery solrQuery = new SolrQuery();
		solrQuery.setQuery(field + ":\"" + fieldValue +"\"");
		return solr.query(solrQuery);		
	}
	
	public String handleSpecialCharacters(String query){

		if (query != null){
			
			query = query.replace("\\", "\\\\");
			query = query.replace("%5C", "\\\\");
			
			query = query.replace("[", "\\[");
			query = query.replace("]", "\\]");
			query = query.replace("{", "\\{");
			query = query.replace("}", "\\}");
			query = query.replace("|", "\\|");
			query = query.replace("<", "\\<");
			query = query.replace(">", "\\>");
			query = query.replace("."  , "\\.");
			query = query.replace("("  , "\\(");
			query = query.replace(")"  , "\\)");
			query = query.replace("/", "\\/");
			query = query.replace("`", "\\`");
			query = query.replace("~"  , "\\~"); 
			query = query.replace("%"  , "\\%");
	
			query = query.replace("%7B", "\\{");
			query = query.replace("%7D", "\\}");
			query = query.replace("%7C", "\\|");
			query = query.replace("%3C", "\\<");
			query = query.replace("%3E", "\\>");
			query = query.replace("%2F", "\\/");
			query = query.replace("%60", "\\`");
		
		}
	
		return query;

	}
{'fraction_non_alphanumeric': 0.22628304821150855, 'fraction_numerical': 0.004665629860031105, 'mean_word_length': 3.594047619047619, 'pattern_counts': {'":': 2, '<': 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': '530979', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1302, 'n_words': 223}