LUCENE-3606: clear up some nocommits

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3606@1211005 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2011-12-06 16:36:41 +00:00
parent 8b80aac679
commit caedbf9ef9
9 changed files with 37 additions and 42 deletions

View File

@ -44,9 +44,8 @@ public class TestMatchAllDocsQuery extends LuceneTestCase {
addDoc("one", iw, 1f); addDoc("one", iw, 1f);
addDoc("two", iw, 20f); addDoc("two", iw, 20f);
addDoc("three four", iw, 300f); addDoc("three four", iw, 300f);
iw.close(); IndexReader ir = IndexReader.open(iw, true);
IndexReader ir = IndexReader.open(dir);
IndexSearcher is = newSearcher(ir); IndexSearcher is = newSearcher(ir);
ScoreDoc[] hits; ScoreDoc[] hits;
@ -70,13 +69,16 @@ public class TestMatchAllDocsQuery extends LuceneTestCase {
hits = is.search(bq, null, 1000).scoreDocs; hits = is.search(bq, null, 1000).scoreDocs;
assertEquals(1, hits.length); assertEquals(1, hits.length);
/* nocommit: fix this test to delete a document with IW iw.deleteDocuments(new Term("key", "one"));
// delete a document: is.close();
is.getIndexReader().deleteDocument(0); ir.close();
ir = IndexReader.open(iw, true);
is = newSearcher(ir);
hits = is.search(new MatchAllDocsQuery(), null, 1000).scoreDocs; hits = is.search(new MatchAllDocsQuery(), null, 1000).scoreDocs;
assertEquals(2, hits.length); assertEquals(2, hits.length);
*/
iw.close();
is.close(); is.close();
ir.close(); ir.close();
dir.close(); dir.close();

View File

@ -240,7 +240,6 @@ public class TestBufferedIndexInput extends LuceneTestCase {
} }
} }
/* nocommit: fix deletions to use IW
public void testSetBufferSize() throws IOException { public void testSetBufferSize() throws IOException {
File indexDir = _TestUtil.getTempDir("testSetBufferSize"); File indexDir = _TestUtil.getTempDir("testSetBufferSize");
MockFSDirectory dir = new MockFSDirectory(indexDir, random); MockFSDirectory dir = new MockFSDirectory(indexDir, random);
@ -257,25 +256,33 @@ public class TestBufferedIndexInput extends LuceneTestCase {
doc.add(newField("id", "" + i, TextField.TYPE_STORED)); doc.add(newField("id", "" + i, TextField.TYPE_STORED));
writer.addDocument(doc); writer.addDocument(doc);
} }
writer.close();
dir.allIndexInputs.clear(); dir.allIndexInputs.clear();
IndexReader reader = IndexReader.open(dir); IndexReader reader = IndexReader.open(writer, true);
Term aaa = new Term("content", "aaa"); Term aaa = new Term("content", "aaa");
Term bbb = new Term("content", "bbb"); Term bbb = new Term("content", "bbb");
Term ccc = new Term("content", "ccc");
assertEquals(37, reader.docFreq(ccc)); reader.close();
reader.deleteDocument(0);
assertEquals(37, reader.docFreq(aaa));
dir.tweakBufferSizes(); dir.tweakBufferSizes();
reader.deleteDocument(4); writer.deleteDocuments(new Term("id", "0"));
assertEquals(reader.docFreq(bbb), 37); reader = IndexReader.open(writer, true);
dir.tweakBufferSizes();
IndexSearcher searcher = newSearcher(reader); IndexSearcher searcher = newSearcher(reader);
ScoreDoc[] hits = searcher.search(new TermQuery(bbb), null, 1000).scoreDocs; ScoreDoc[] hits = searcher.search(new TermQuery(bbb), null, 1000).scoreDocs;
dir.tweakBufferSizes(); dir.tweakBufferSizes();
assertEquals(36, hits.length);
reader.close();
searcher.close();
dir.tweakBufferSizes();
writer.deleteDocuments(new Term("id", "4"));
reader = IndexReader.open(writer, true);
searcher = newSearcher(reader);
hits = searcher.search(new TermQuery(bbb), null, 1000).scoreDocs;
dir.tweakBufferSizes();
assertEquals(35, hits.length); assertEquals(35, hits.length);
dir.tweakBufferSizes(); dir.tweakBufferSizes();
hits = searcher.search(new TermQuery(new Term("id", "33")), null, 1000).scoreDocs; hits = searcher.search(new TermQuery(new Term("id", "33")), null, 1000).scoreDocs;
@ -284,13 +291,12 @@ public class TestBufferedIndexInput extends LuceneTestCase {
hits = searcher.search(new TermQuery(aaa), null, 1000).scoreDocs; hits = searcher.search(new TermQuery(aaa), null, 1000).scoreDocs;
dir.tweakBufferSizes(); dir.tweakBufferSizes();
assertEquals(35, hits.length); assertEquals(35, hits.length);
writer.close();
searcher.close(); searcher.close();
reader.close();
} finally { } finally {
_TestUtil.rmDir(indexDir); _TestUtil.rmDir(indexDir);
} }
} }
*/
private static class MockFSDirectory extends Directory { private static class MockFSDirectory extends Directory {

View File

@ -57,10 +57,9 @@ public abstract class IndexReaderFactory implements NamedListInitializedPlugin {
* Creates a new IndexReader instance using the given Directory. * Creates a new IndexReader instance using the given Directory.
* *
* @param indexDir indexDir index location * @param indexDir indexDir index location
* @param readOnly return readOnly IndexReader
* @return An IndexReader instance * @return An IndexReader instance
* @throws IOException * @throws IOException
*/ */
public abstract IndexReader newReader(Directory indexDir, boolean readOnly) public abstract IndexReader newReader(Directory indexDir)
throws IOException; throws IOException;
} }

View File

@ -314,12 +314,7 @@ public final class SolrCore implements SolrInfoMBean {
// gets a non-caching searcher // gets a non-caching searcher
public SolrIndexSearcher newSearcher(String name) throws IOException { public SolrIndexSearcher newSearcher(String name) throws IOException {
return newSearcher(name, false); return new SolrIndexSearcher(this, getNewIndexDir(), schema, getSolrConfig().mainIndexConfig, name, false, directoryFactory);
}
// gets a non-caching searcher
public SolrIndexSearcher newSearcher(String name, boolean readOnly) throws IOException {
return new SolrIndexSearcher(this, getNewIndexDir(), schema, getSolrConfig().mainIndexConfig, name, readOnly, false, directoryFactory);
} }
@ -1146,7 +1141,7 @@ public final class SolrCore implements SolrInfoMBean {
} else { } else {
// verbose("non-reopen START:"); // verbose("non-reopen START:");
tmp = new SolrIndexSearcher(this, newIndexDir, schema, getSolrConfig().mainIndexConfig, "main", true, true, directoryFactory); tmp = new SolrIndexSearcher(this, newIndexDir, schema, getSolrConfig().mainIndexConfig, "main", true, directoryFactory);
// verbose("non-reopen DONE: searcher=",tmp); // verbose("non-reopen DONE: searcher=",tmp);
} }
} catch (Throwable th) { } catch (Throwable th) {

View File

@ -29,13 +29,8 @@ import org.apache.lucene.store.Directory;
*/ */
public class StandardIndexReaderFactory extends IndexReaderFactory { public class StandardIndexReaderFactory extends IndexReaderFactory {
/* (non-Javadoc)
* @see org.apache.solr.core.IndexReaderFactory#newReader(org.apache.lucene.store.Directory, boolean)
*/
@Override @Override
public IndexReader newReader(Directory indexDir, boolean readOnly) public IndexReader newReader(Directory indexDir) throws IOException {
throws IOException {
assert readOnly; // nocommit: readOnly is ignored - remove
return IndexReader.open(indexDir, termInfosIndexDivisor); return IndexReader.open(indexDir, termInfosIndexDivisor);
} }
} }

View File

@ -107,9 +107,9 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
private Collection<String> storedHighlightFieldNames; private Collection<String> storedHighlightFieldNames;
private DirectoryFactory directoryFactory; private DirectoryFactory directoryFactory;
public SolrIndexSearcher(SolrCore core, String path, IndexSchema schema, SolrIndexConfig config, String name, boolean readOnly, boolean enableCache, DirectoryFactory directoryFactory) throws IOException { public SolrIndexSearcher(SolrCore core, String path, IndexSchema schema, SolrIndexConfig config, String name, boolean enableCache, DirectoryFactory directoryFactory) throws IOException {
// we don't need to reserve the directory because we get it from the factory // we don't need to reserve the directory because we get it from the factory
this(core, schema,name, core.getIndexReaderFactory().newReader(directoryFactory.get(path, config.lockType), readOnly), true, enableCache, false, directoryFactory); this(core, schema,name, core.getIndexReaderFactory().newReader(directoryFactory.get(path, config.lockType)), true, enableCache, false, directoryFactory);
} }
public SolrIndexSearcher(SolrCore core, IndexSchema schema, String name, IndexReader r, boolean closeReader, boolean enableCache, boolean reserveDirectory, DirectoryFactory directoryFactory) { public SolrIndexSearcher(SolrCore core, IndexSchema schema, String name, IndexReader r, boolean closeReader, boolean enableCache, boolean reserveDirectory, DirectoryFactory directoryFactory) {

View File

@ -61,9 +61,7 @@ public class AlternateDirectoryTest extends SolrTestCaseJ4 {
static volatile boolean newReaderCalled = false; static volatile boolean newReaderCalled = false;
@Override @Override
public IndexReader newReader(Directory indexDir, boolean readOnly) public IndexReader newReader(Directory indexDir) throws IOException {
throws IOException {
assert readOnly; // nocommit: readOnly is ignored - remove
TestIndexReaderFactory.newReaderCalled = true; TestIndexReaderFactory.newReaderCalled = true;
return IndexReader.open(indexDir); return IndexReader.open(indexDir);
} }

View File

@ -75,7 +75,7 @@ public class TestQuerySenderListener extends SolrTestCaseJ4 {
assertNotNull("Event is null", evt); assertNotNull("Event is null", evt);
assertTrue(evt + " is not equal to " + EventParams.FIRST_SEARCHER, evt.equals(EventParams.FIRST_SEARCHER) == true); assertTrue(evt + " is not equal to " + EventParams.FIRST_SEARCHER, evt.equals(EventParams.FIRST_SEARCHER) == true);
SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getNewIndexDir(), core.getSchema(), core.getSolrConfig().mainIndexConfig, "testQuerySenderListener", true, false, core.getDirectoryFactory()); SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getNewIndexDir(), core.getSchema(), core.getSolrConfig().mainIndexConfig, "testQuerySenderListener", false, core.getDirectoryFactory());
qsl.newSearcher(newSearcher, currentSearcher); qsl.newSearcher(newSearcher, currentSearcher);
evt = mock.req.getParams().get(EventParams.EVENT); evt = mock.req.getParams().get(EventParams.EVENT);

View File

@ -75,7 +75,7 @@ public class TestQuerySenderNoQuery extends SolrTestCaseJ4 {
assertNotNull("Mock is null", mock); assertNotNull("Mock is null", mock);
assertNull("Req (firstsearcher) is not null", mock.req); assertNull("Req (firstsearcher) is not null", mock.req);
SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getNewIndexDir(), core.getSchema(), core.getSolrConfig().mainIndexConfig, "testQuerySenderNoQuery", true, false, core.getDirectoryFactory()); SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getNewIndexDir(), core.getSchema(), core.getSolrConfig().mainIndexConfig, "testQuerySenderNoQuery", false, core.getDirectoryFactory());
qsl.newSearcher(newSearcher, currentSearcher); // get newSearcher. qsl.newSearcher(newSearcher, currentSearcher); // get newSearcher.
assertNull("Req (newsearcher) is not null", mock.req); assertNull("Req (newsearcher) is not null", mock.req);