<commit_before>/*
 * Copyright 2016 Crown Copyright
 *
 * 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 stroom.search.impl.shard;

import stroom.index.shared.IndexShard;
import stroom.query.api.v2.QueryKey;
import stroom.query.common.v2.SearchProgressLog;
import stroom.query.common.v2.SearchProgressLog.SearchPhase;
import stroom.task.api.TaskContext;
import stroom.task.api.TaskTerminatedException;
import stroom.util.NullSafe;
import stroom.util.logging.LambdaLogger;
import stroom.util.logging.LambdaLoggerFactory;

import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SimpleCollector;

import java.io.IOException;
import java.util.concurrent.atomic.LongAdder;
import java.util.function.Supplier;

class IndexShardHitCollector extends SimpleCollector {

    private static final LambdaLogger LOGGER = LambdaLoggerFactory.getLogger(IndexShardHitCollector.class);

    private final TaskContext taskContext;
    private final IndexShard indexShard;
    private final QueryKey queryKey;
    private final Query query;

    //an empty optional is used as a marker to indicate no more items will be added
    private final DocIdQueue docIdQueue;
    private final LongAdder totalHitCount;
    private final LongAdder localHitCount = new LongAdder();
    private int docBase;

    IndexShardHitCollector(final TaskContext taskContext,
                           final QueryKey queryKey,
                           final IndexShard indexShard,
                           final Query query,
                           final DocIdQueue docIdQueue,
                           final LongAdder totalHitCount) {
        this.taskContext = taskContext;
        this.indexShard = indexShard;
        this.queryKey = queryKey;
        this.query = query;
        this.docIdQueue = docIdQueue;
        this.totalHitCount = totalHitCount;

        info(() -> "Searching...");
    }<commit_msg>#2879 Prevent shards closing during read<commit_after>/*
 * Copyright 2016 Crown Copyright
 *
 * 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 stroom.search.impl.shard;

import stroom.index.shared.IndexShard;
import stroom.query.api.v2.QueryKey;
import stroom.query.common.v2.SearchProgressLog;
import stroom.query.common.v2.SearchProgressLog.SearchPhase;
import stroom.task.api.TaskContext;
import stroom.task.api.TaskTerminatedException;
import stroom.util.NullSafe;
import stroom.util.logging.LambdaLogger;
import stroom.util.logging.LambdaLoggerFactory;

import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SimpleCollector;

import java.io.IOException;
import java.util.concurrent.atomic.LongAdder;
import java.util.function.Supplier;

public class IndexShardHitCollector extends SimpleCollector {

    private static final LambdaLogger LOGGER = LambdaLoggerFactory.getLogger(IndexShardHitCollector.class);

    private final TaskContext taskContext;
    private final IndexShard indexShard;
    private final QueryKey queryKey;
    private final Query query;

    //an empty optional is used as a marker to indicate no more items will be added
    private final DocIdQueue docIdQueue;
    private final LongAdder totalHitCount;
    private final LongAdder localHitCount = new LongAdder();
    private int docBase;

    public IndexShardHitCollector(final TaskContext taskContext,
                                  final QueryKey queryKey,
                                  final IndexShard indexShard,
                                  final Query query,
                                  final DocIdQueue docIdQueue,
                                  final LongAdder totalHitCount) {
        this.taskContext = taskContext;
        this.indexShard = indexShard;
        this.queryKey = queryKey;
        this.query = query;
        this.docIdQueue = docIdQueue;
        this.totalHitCount = totalHitCount;

        info(() -> "Searching...");
    }
{'fraction_non_alphanumeric': 0.0692891373801917, 'fraction_numerical': 0.005191693290734824, 'mean_word_length': 3.1637572734829593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6546503', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1309, 'n_words': 419}