Java 类org.apache.lucene.analysis.miscellaneous.LimitTokenCountAnalyzer 实例源码

项目:eHMP    文件:LuceneSearchDataSource.java   
protected void init(boolean write) throws IOException {
    // configure/initialize lucene
       Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_44);
       IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_44, 
            new LimitTokenCountAnalyzer(analyzer, Integer.MAX_VALUE));

       // if index doesn't exist, create it (otherwise you get an error trying to open the reader)
       if (write || !DirectoryReader.indexExists(directory)) {
        this.writer = new IndexWriter(directory, conf);
        this.writer.commit(); // for ensuring the index exists the first time
       }
    this.reader = DirectoryReader.open(directory);
    this.searcher = new IndexSearcher(this.reader);
    this.parser = new QueryParser(Version.LUCENE_44, "description", analyzer);
    this.parser.setDefaultOperator(Operator.AND);

    // get the unique SAB's
    Set<String> sabs = new HashSet<>();
    Fields fields = MultiFields.getFields(this.reader);
    if (fields != null) {
        Terms terms = fields.terms("sab");
        TermsEnum itr = terms.iterator(null);
        BytesRef bytes = null;
        while((bytes = itr.next()) != null) {
            String term = new String(bytes.bytes, bytes.offset, bytes.length);
            sabs.add(term);
        }
    }
    this.systems = Collections.unmodifiableSet(sabs);
}
项目:eHMP    文件:LuceneSearchDataSource.java   
protected void init(boolean write) throws IOException {
    // configure/initialize lucene
       Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_44);
       IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_44, 
            new LimitTokenCountAnalyzer(analyzer, Integer.MAX_VALUE));

       // if index doesn't exist, create it (otherwise you get an error trying to open the reader)
       if (write || !DirectoryReader.indexExists(directory)) {
        this.writer = new IndexWriter(directory, conf);
        this.writer.commit(); // for ensuring the index exists the first time
       }
    this.reader = DirectoryReader.open(directory);
    this.searcher = new IndexSearcher(this.reader);
    this.parser = new QueryParser(Version.LUCENE_44, "description", analyzer);
    this.parser.setDefaultOperator(Operator.AND);

    // get the unique SAB's
    Set<String> sabs = new HashSet<>();
    Fields fields = MultiFields.getFields(this.reader);
    if (fields != null) {
        Terms terms = fields.terms("sab");
        TermsEnum itr = terms.iterator(null);
        BytesRef bytes = null;
        while((bytes = itr.next()) != null) {
            String term = new String(bytes.bytes, bytes.offset, bytes.length);
            sabs.add(term);
        }
    }
    this.systems = Collections.unmodifiableSet(sabs);
}