Java tutorial
/** * Copyright 2010 * * 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 framework.retrieval.engine.context; import org.apache.lucene.index.IndexWriter; import framework.base.snoic.base.util.StringClass; import framework.retrieval.engine.RetrievalType; import framework.retrieval.engine.facade.IRDocOperatorFacade; import framework.retrieval.engine.facade.IRIndexOperatorFacade; import framework.retrieval.engine.facade.IRQueryFacade; import framework.retrieval.engine.facade.RetrevalIndexInit; import framework.retrieval.engine.facade.impl.RDocOperatorFacade; import framework.retrieval.engine.facade.impl.RIndexOperatorFacade; import framework.retrieval.engine.facade.impl.RQueryFacade; import framework.retrieval.engine.index.create.impl.RIndexWriteProvider; import framework.retrieval.engine.index.doc.NormalIndexDocument; import framework.retrieval.engine.index.doc.database.DatabaseIndexDocument; import framework.retrieval.engine.index.doc.database.RDatabaseIndexAllItem; import framework.retrieval.engine.index.doc.file.FileIndexDocument; import framework.retrieval.engine.index.doc.file.RFileIndexAllItem; import framework.retrieval.engine.query.item.QueryItem; /** * * * @author * */ public class RFacade { private RetrievalApplicationContext retrievalApplicationContext; RFacade(RetrievalApplicationContext retrievalApplicationContext) { this.retrievalApplicationContext = retrievalApplicationContext; } /** * ? * * @param indexPathTypes * ?? */ public void initIndex(String[] indexPathTypes) { new RetrevalIndexInit().init(retrievalApplicationContext.getRetrievalFactory().getAnalyzerFactory(), retrievalApplicationContext.getRetrievalProperties().getLuceneProperties(), indexPathTypes); } /** * ? * * @param indexPathType * ?? */ public void initIndex(String indexPathType) { new RetrevalIndexInit().init(retrievalApplicationContext.getRetrievalFactory().getAnalyzerFactory(), retrievalApplicationContext.getRetrievalProperties().getLuceneProperties(), new String[] { indexPathType }); } /** * QueryItem * @param docItemType * @param name * @param keyWord * @return */ public QueryItem createQueryItem(RetrievalType.RDocItemType docItemType, Object name, String keyWord) { QueryItem queryItem = new QueryItem(retrievalApplicationContext.getRetrievalFactory().getAnalyzerFactory(), docItemType, name, keyWord); return queryItem; } /** * QueryItem * @param docItemType * @param name * @param keyWord * @param score * @return */ public QueryItem createQueryItem(RetrievalType.RDocItemType docItemType, Object name, String keyWord, Float score) { QueryItem queryItem = new QueryItem(retrievalApplicationContext.getRetrievalFactory().getAnalyzerFactory(), docItemType, name, keyWord, score); return queryItem; } /** * QueryItem * @param docItemType * @param name * @param keyWord * @param regex * @return */ public QueryItem createQueryItem(RetrievalType.RDocItemType docItemType, Object name, String keyWord, boolean regex) { QueryItem queryItem = new QueryItem(retrievalApplicationContext.getRetrievalFactory().getAnalyzerFactory(), docItemType, name, keyWord, regex); return queryItem; } /** * ??Document * @param fullContentFlag ????? * @return */ public DatabaseIndexDocument createDatabaseIndexDocument(boolean fullContentFlag) { return new DatabaseIndexDocument(fullContentFlag); } /** * ?Document * @param fullContentFlag ????? * @param charsetName * @return */ public FileIndexDocument createFileIndexDocument(boolean fullContentFlag, String charsetName) { return new FileIndexDocument(fullContentFlag, charsetName); } /** * Document * @param fullContentFlag ????? * @return */ public NormalIndexDocument createNormalIndexDocument(boolean fullContentFlag) { return new NormalIndexDocument(fullContentFlag); } /** * ? * @param fullContentFlag ????? * @param charsetName */ public RFileIndexAllItem createFileIndexAllItem(boolean fullContentFlag, String charsetName) { charsetName = StringClass.getString(charsetName); if (charsetName.equals("")) { charsetName = retrievalApplicationContext.getRetrievalProperties() .getPropertyValueIndexDefaultCharset(); } RFileIndexAllItem fileIndexAllItem = new RFileIndexAllItem(createQueryFacade(), createDocOperatorFacade(), fullContentFlag, retrievalApplicationContext.getRetrievalProperties().getPropertyValueIndexMaxFileDocumentPageSize(), charsetName); return fileIndexAllItem; } /** * RFileIndexAllItem * @param fullContentFlag ????? */ public RDatabaseIndexAllItem createDatabaseIndexAllItem(boolean fullContentFlag) { RDatabaseIndexAllItem databaseIndexAllItem = new RDatabaseIndexAllItem(createQueryFacade(), createDocOperatorFacade(), fullContentFlag, retrievalApplicationContext.getRetrievalProperties().getPropertyValueIndexMaxDBDocumentPageSize()); return databaseIndexAllItem; } /** * ?? * * @return */ public IRQueryFacade createQueryFacade() { return new RQueryFacade(retrievalApplicationContext.getRetrievalProperties().getLuceneProperties(), retrievalApplicationContext.getRetrievalFactory().getAnalyzerFactory(), retrievalApplicationContext.getRetrievalFactory().getHighlighterFactory(), retrievalApplicationContext.getRetrievalProperties().getPropertyValueQueryResultTopDocsNum(), retrievalApplicationContext.getBaseIndexpath()); } /** * ?? * * @return */ public IRDocOperatorFacade createDocOperatorFacade() { return new RDocOperatorFacade(retrievalApplicationContext.getRetrievalFactory().getDatabaseIndexAll(), retrievalApplicationContext.getRetrievalFactory().getFileContentParserManager(), retrievalApplicationContext.getRetrievalFactory().getAnalyzerFactory(), retrievalApplicationContext.getRetrievalProperties().getLuceneProperties(), retrievalApplicationContext.getDefaultRetrievalProperties()); } /** * ?? * * @param indexPathType * @return */ public IRIndexOperatorFacade createIndexOperatorFacade(String indexPathType) { return new RIndexOperatorFacade(retrievalApplicationContext.getRetrievalFactory().getAnalyzerFactory(), retrievalApplicationContext.getRetrievalProperties().getLuceneProperties(), indexPathType); } public IndexWriter createIndexWriter(String indexPathType) { RIndexWriteProvider indexWriteProvider = new RIndexWriteProvider( retrievalApplicationContext.getRetrievalFactory().getAnalyzerFactory(), retrievalApplicationContext.getRetrievalProperties().getLuceneProperties()); return indexWriteProvider.createNormalIndexWriter(indexPathType); } public void closeIndexWriter(IndexWriter indexWriter) { if (indexWriter != null) { try { indexWriter.commit(); } catch (Exception e) { e.printStackTrace(); } try { indexWriter.close(); } catch (Exception e) { e.printStackTrace(); } } } }