Java tutorial
/* * Copyright 2007-2107 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.ymate.platform.module.search.support; import net.ymate.platform.commons.util.ExpressionUtils; import net.ymate.platform.commons.util.RuntimeUtils; import net.ymate.platform.configuration.Cfgs; import org.apache.commons.lang.StringUtils; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.util.Version; import net.ymate.platform.module.search.ISearchConfig; /** * <p> * DefaultSearchConfig * </p> * <p> * * </p> * * @author (suninformation@163.com) * @version 0.0.0 * <table style="border:1px solid gray;"> * <tr> * <th width="100px">?</th><th width="100px"></th><th * width="100px"></th><th width="100px"></th> * </tr> * <!-- Table ?? --> * <tr> * <td>0.0.0</td> * <td></td> * <td></td> * <td>201439?2:07:50</td> * </tr> * </table> */ public class DefaultSearchConfig implements ISearchConfig { private String directoryPath; private Version luceneVersion; private Analyzer analyzerImpl; private int threadPoolSize; private double bufferSize; private int scheduledPeriod; /** * */ public DefaultSearchConfig() { } /** * * * @param directoryPath * @param luceneVersion * @param analyzerImpl * @param threadPoolSize * @param bufferSize * @param scheduledPeriod */ public DefaultSearchConfig(String directoryPath, Version luceneVersion, Analyzer analyzerImpl, int threadPoolSize, double bufferSize, int scheduledPeriod) { this.directoryPath = doParseVariableUserDir(StringUtils.defaultIfEmpty(directoryPath, "")); this.luceneVersion = luceneVersion; this.analyzerImpl = analyzerImpl; this.threadPoolSize = threadPoolSize; this.bufferSize = bufferSize; this.scheduledPeriod = scheduledPeriod; } /** * @param origin * @return ?${user.dir}?? */ protected String doParseVariableUserDir(String origin) { if (Cfgs.isInited()) { return ExpressionUtils.bind(origin).set("user.dir", Cfgs.getUserDir()).getResult(); } return ExpressionUtils.bind(origin).set("user.dir", RuntimeUtils.getRootPath()).getResult(); } /* (non-Javadoc) * @see net.ymate.platform.search.ISearchConfig#getDirectoryPath() */ public String getDirectoryPath() { return directoryPath; } public void setDirectoryPath(String directoryPath) { this.directoryPath = doParseVariableUserDir(StringUtils.defaultIfEmpty(directoryPath, "")); } /* (non-Javadoc) * @see net.ymate.platform.search.ISearchConfig#getLuceneVersion() */ public Version getLuceneVersion() { return luceneVersion == null ? Version.LUCENE_46 : luceneVersion; } public void setLuceneVersion(Version luceneVersion) { this.luceneVersion = luceneVersion; } /* (non-Javadoc) * @see net.ymate.platform.search.ISearchConfig#getAnalyzerImpl() */ public Analyzer getAnalyzerImpl() { if (analyzerImpl == null) { return new StandardAnalyzer(getLuceneVersion()); } return analyzerImpl; } public void setAnalyzerImpl(Analyzer analyzerImpl) { this.analyzerImpl = analyzerImpl; } /* (non-Javadoc) * @see net.ymate.platform.search.ISearchConfig#getThreadPoolSize() */ public int getThreadPoolSize() { if (threadPoolSize <= 0) { return Runtime.getRuntime().availableProcessors() * 2 + 1; } return threadPoolSize; } public void setThreadPoolSize(int threadPoolSize) { this.threadPoolSize = threadPoolSize; } /* (non-Javadoc) * @see net.ymate.platform.search.ISearchConfig#getBufferSize() */ public double getBufferSize() { return bufferSize > 0 ? bufferSize : 16; } public void setBufferSize(double bufferSize) { this.bufferSize = bufferSize; } /* (non-Javadoc) * @see net.ymate.platform.search.ISearchConfig#getScheduledPeriod() */ public int getScheduledPeriod() { return scheduledPeriod > 0 ? scheduledPeriod : 30; } public void setScheduledPeriod(int scheduledPeriod) { this.scheduledPeriod = scheduledPeriod; } }