zoukankan      html  css  js  c++  java
  • lucene关于IndexReader总结

    IndexReader。使用过程中有时会出现document被删除,reader还是原来的reader没有改变,所以使用openifchanged保证,

    又因为IndexReader 初始化很耗费资源所以放在静态代码块里

    private static Directory directory = null;
        private static IndexReader reader = null;
        static {
            try {
                directory = FSDirectory.open(new File("E:/lucene/index02"));
                reader = IndexReader.open(directory);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    public IndexSearcher getIndexSearcher() {
            try {
                IndexReader tr = IndexReader.openIfChanged(reader);
                if (tr != null) {

          reader.close();
                    reader = tr;
                }
                return new IndexSearcher(reader);
            } catch (IOException e) {

                e.printStackTrace();
            }
            return null;
        }

  • 相关阅读:
    POJ 2251 Dungeon Master
    HDU 3085 Nightmare Ⅱ
    CodeForces 1060 B Maximum Sum of Digits
    HDU 1166 敌兵布阵(树状数组)
    HDOJ 2050 折线分割平面
    HDU 5879 Cure
    HDU 1878 欧拉回路
    HDU 6225 Little Boxes
    ZOJ 2971 Give Me the Number
    HDU 2680 Choose the best route
  • 原文地址:https://www.cnblogs.com/or2-/p/3495251.html
Copyright © 2011-2022 走看看