<commit_before>package com.ejl.searcher;

import com.ejl.searcher.dialect.MySqlDialect;
import com.ejl.searcher.implement.MainSearchParamResolver;
import com.ejl.searcher.implement.MainSearchResultResolver;
import com.ejl.searcher.implement.MainSearchSqlResolver;
import com.ejl.searcher.implement.MainSearcher;
import com.ejl.searcher.util.DefaultFieldConvertor;

/***
 * 检索器 Builder
 * 
 * @author Troy.Zhou @ 2017-03-20
 * 
 * */
public class SearcherBuilder {

	private SearchParamResolver searchParamResolver;
	
	private SearchSqlResolver searchSqlResolver;
	
	private SearchSqlExecutor searchSqlExecutor;
	
	private SearchResultResolver searchResultResolver;
	
	private int prifexSeparatorLength = 1;
	
	public static SearcherBuilder builder() {
		return new SearcherBuilder();
	}
	
	public SearcherBuilder configSearchParamResolver(SearchParamResolver searchParamResolver) {
		this.searchParamResolver = searchParamResolver;
		return this;
	}
	
	public SearcherBuilder configSearchSqlResolver(SearchSqlResolver searchSqlResolver) {
		this.searchSqlResolver = searchSqlResolver;
		return this;
	}
	
	public SearcherBuilder configSearchSqlExecutor(SearchSqlExecutor searchSqlExecutor) {
		this.searchSqlExecutor = searchSqlExecutor;
		return this;
	}
	
	public SearcherBuilder configSearchResultResolver(SearchResultResolver searchResultResolver) {
		this.searchResultResolver = searchResultResolver;
		return this;
	}
	
	public SearcherBuilder configPrifexSeparatorLength(int length) {
		this.prifexSeparatorLength = length;
		return this;
	}
	
	
	public Searcher build() {
		MainSearcher mainSearcher = new MainSearcher();
		if (searchParamResolver != null) {
			mainSearcher.setSearchParamResolver(searchParamResolver);
		} else {
			mainSearcher.setSearchParamResolver(new MainSearchParamResolver());
		}
		if (searchSqlResolver != null) {
			mainSearcher.setSearchSqlResolver(searchSqlResolver);
		} else {
			MainSearchSqlResolver searchSqlResolver = new MainSearchSqlResolver();
			searchSqlResolver.setDialect(new MySqlDialect());
			mainSearcher.setSearchSqlResolver(searchSqlResolver);
		}
		if (searchSqlExecutor != null) {
			mainSearcher.setSearchSqlExecutor(searchSqlExecutor);
		} else {
			throw new SearcherBuildFailureException("你必须配置一个 searchSqlExecutor，才能建立一个检索器！ ");
		}
		if (searchResultResolver != null) {
			mainSearcher.setSearchResultResolver(searchResultResolver);
		} else {
			MainSearchResultResolver searchResultResolver = new MainSearchResultResolver();
			searchResultResolver.setFieldConvertor(new DefaultFieldConvertor());
			mainSearcher.setSearchResultResolver(searchResultResolver);
		}
		mainSearcher.setPrifexSeparatorLength(prifexSeparatorLength);<commit_msg>SearcherBuilder 添加 Searcher build(MainSearcher) 方法<commit_after>package com.ejl.searcher;

import com.ejl.searcher.dialect.MySqlDialect;
import com.ejl.searcher.implement.MainSearchParamResolver;
import com.ejl.searcher.implement.MainSearchResultResolver;
import com.ejl.searcher.implement.MainSearchSqlResolver;
import com.ejl.searcher.implement.MainSearcher;
import com.ejl.searcher.util.DefaultFieldConvertor;

/***
 * 检索器 Builder
 * 
 * @author Troy.Zhou @ 2017-03-20
 * 
 * */
public class SearcherBuilder {

	private SearchParamResolver searchParamResolver;
	
	private SearchSqlResolver searchSqlResolver;
	
	private SearchSqlExecutor searchSqlExecutor;
	
	private SearchResultResolver searchResultResolver;
	
	private int prifexSeparatorLength = 1;
	
	public static SearcherBuilder builder() {
		return new SearcherBuilder();
	}
	
	public SearcherBuilder configSearchParamResolver(SearchParamResolver searchParamResolver) {
		this.searchParamResolver = searchParamResolver;
		return this;
	}
	
	public SearcherBuilder configSearchSqlResolver(SearchSqlResolver searchSqlResolver) {
		this.searchSqlResolver = searchSqlResolver;
		return this;
	}
	
	public SearcherBuilder configSearchSqlExecutor(SearchSqlExecutor searchSqlExecutor) {
		this.searchSqlExecutor = searchSqlExecutor;
		return this;
	}
	
	public SearcherBuilder configSearchResultResolver(SearchResultResolver searchResultResolver) {
		this.searchResultResolver = searchResultResolver;
		return this;
	}
	
	public SearcherBuilder configPrifexSeparatorLength(int length) {
		this.prifexSeparatorLength = length;
		return this;
	}
	
	
	public Searcher build() {
		return build(new MainSearcher());
	}
	
	public Searcher build(MainSearcher mainSearcher) {
		if (searchParamResolver != null) {
			mainSearcher.setSearchParamResolver(searchParamResolver);
		} else {
			mainSearcher.setSearchParamResolver(new MainSearchParamResolver());
		}
		if (searchSqlResolver != null) {
			mainSearcher.setSearchSqlResolver(searchSqlResolver);
		} else {
			MainSearchSqlResolver searchSqlResolver = new MainSearchSqlResolver();
			searchSqlResolver.setDialect(new MySqlDialect());
			mainSearcher.setSearchSqlResolver(searchSqlResolver);
		}
		if (searchSqlExecutor != null) {
			mainSearcher.setSearchSqlExecutor(searchSqlExecutor);
		} else {
			throw new SearcherBuildFailureException("你必须配置一个 searchSqlExecutor，才能建立一个检索器！ ");
		}
		if (searchResultResolver != null) {
			mainSearcher.setSearchResultResolver(searchResultResolver);
		} else {
			MainSearchResultResolver searchResultResolver = new MainSearchResultResolver();
			searchResultResolver.setFieldConvertor(new DefaultFieldConvertor());
			mainSearcher.setSearchResultResolver(searchResultResolver);
		}
		mainSearcher.setPrifexSeparatorLength(prifexSeparatorLength);
{'fraction_non_alphanumeric': 0.07629278951201748, 'fraction_numerical': 0.0032774945375091042, 'mean_word_length': 6.333778371161548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4435685', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1596, 'n_words': 272}