solr LuceneContext

来源:互联网 发布:网络如何挣钱 编辑:程序博客网 时间:2024/06/08 07:30

    private static final Log log = LogFactory.getLog(LuceneContext.class);
    
    private static LuceneContext instance;
    private static Analyzer analyzer;
    private static Version version;
    private final static String URL = "http://127.0.0.1:8026/solr";
    //private static HttpSolrServer server = null;
    private static CommonsHttpSolrServer server = null;
    
    
    private LuceneContext(){}
    
    public synchronized static LuceneContext getInstance() {
        if(instance==null){
            log.error("init LuceneContext");
            init();
            instance = new LuceneContext();
        }
        return instance;
    }
    
    private static void init() {
        try {
            //server = new HttpSolrServer(URL);
            server = new CommonsHttpSolrServer (URL);
            version = Version.LUCENE_35;
            String dicUrl = LuceneContext.class.getClassLoader().getResource("data").getPath().toString();
            analyzer = new ComplexAnalyzer(dicUrl);
            
        } catch (Exception e) {
            log.error("",e);
        }
    }
    
    public SolrServer getServer() {
        return server;
    }
    
    public Version getVersion() {
        return version;
    }
    
    public Analyzer getAnalyzer() {
        return analyzer;
    }

原创粉丝点击