LuceneServer implements IContentServer, ILuceneServer { @Override public DocumentFrequencyWritable getDocFreqs(final QueryWritable input, final String[] shards) throws IOException { Query luceneQuery = input.getQuery(); final Query rewrittenQuery = rewrite(luceneQuery, shards); final DocumentFrequencyWritable docFreqs = new DocumentFrequencyWritable(); final HashSet<Term> termSet = new HashSet<Term>(); rewrittenQuery.extractTerms(termSet); for (final String shard : shards) { final java.util.Iterator<Term> termIterator = termSet.iterator(); SearcherHandle handle = getSearcherHandleByShard(shard); IndexSearcher searcher = handle.getSearcher(); if (searcher != null) { try { while (termIterator.hasNext()) { final Term term = termIterator.next(); final int docFreq = searcher.docFreq(term); docFreqs.put(term.field(), term.text(), docFreq); } } finally { handle.finishSearcher(); } } docFreqs.addNumDocs(shardSize(shard)); } return docFreqs; } LuceneServer();  LuceneServer(String name, ISeacherFactory seacherFactory, float timeoutPercentage); @Override long getProtocolVersion(final String protocol, final long clientVersion); @Override void init(String nodeName, NodeConfiguration nodeConfiguration); String getNodeName(); float getTimeoutPercentage(); long getCollectorTiemout(long clientTimeout); @Override void addShard(final String shardName, final File shardDir); @Override void removeShard(final String shardName); @Override Collection<String> getShards(); @Override Map<String, String> getShardMetaData(String shardName); @Override void shutdown(); @Override HitsMapWritable search(QueryWritable query, DocumentFrequencyWritable freqs, String[] shardNames, long timeout); @Override HitsMapWritable search(final QueryWritable query, final DocumentFrequencyWritable freqs,
          final String[] shards, final long timeout, final int count); @Override HitsMapWritable search(QueryWritable query, DocumentFrequencyWritable freqs, String[] shards,
          final long timeout, int count, SortWritable sortWritable); @Override HitsMapWritable search(QueryWritable query, DocumentFrequencyWritable freqs, String[] shards,
          final long timeout, int count, FilterWritable filterWritable); @Override HitsMapWritable search(QueryWritable query, DocumentFrequencyWritable freqs, String[] shards,
          final long timeout, int count, SortWritable sortWritable, FilterWritable filterWritable); @Override DocumentFrequencyWritable getDocFreqs(final QueryWritable input, final String[] shards); @Override MapWritable getDetails(final String[] shards, final int docId); @Override MapWritable getDetails(final String[] shards, final int docId, final String[] fieldNames); @Override int getResultCount(final QueryWritable query, final String[] shards, long timeout); @Override int getResultCount(final QueryWritable query, FilterWritable filter, final String[] shards, long timeout); final static String CONF_KEY_SEARCHER_FACTORY_CLASS; final static String CONF_KEY_COLLECTOR_TIMOUT_PERCENTAGE; final static String CONF_KEY_COLLECTOR_TRACK_DOC_SCORES_ON_FIELD_SORT; final static String CONF_KEY_SEARCHER_THREADPOOL_CORESIZE; final static String CONF_KEY_SEARCHER_THREADPOOL_MAXSIZE; final static String CONF_KEY_FILTER_CACHE_ENABLED; }
@Test public void testSearch_MultiThread() throws Exception { LuceneServer server = new LuceneServer("ls", new DefaultSearcherFactory(), 0.75f); String[] shardNames = addIndexShards(server, TestResources.INDEX1); QueryWritable writable = new QueryWritable(parseQuery("foo: bar")); DocumentFrequencyWritable freqs = server.getDocFreqs(writable, shardNames); ExecutorService es = Executors.newFixedThreadPool(100); List<Future<HitsMapWritable>> tasks = new ArrayList<Future<HitsMapWritable>>(); for (int i = 0; i < 10000; i++) { QueryClient client = new QueryClient(server, freqs, writable, shardNames); Future<HitsMapWritable> future = es.submit(client); tasks.add(future); } HitsMapWritable last = null; for (Future<HitsMapWritable> future : tasks) { HitsMapWritable hitsMapWritable = future.get(); if (last == null) { last = hitsMapWritable; } else { Assert.assertEquals(last.getTotalHits(), hitsMapWritable.getTotalHits()); float lastScore = last.getHitList().get(0).getScore(); float currentScore = hitsMapWritable.getHitList().get(0).getScore(); Assert.assertEquals(lastScore, currentScore); } } }