List of usage examples for org.apache.lucene.index IndexReader numDocs
public abstract int numDocs();
From source file:org.sakai.search.index.impl.test.ClusterFSIndexStorageEclipsetest.java
License:Educational Community License
public void testGetIndexReader() throws Exception { IndexReader ir = cfs.getIndexReader(); assertNotNull(ir);//from www . java 2s .c o m ir.numDocs(); ir.close(); }
From source file:org.sd.text.lucene.LuceneSearcher.java
License:Open Source License
public static void main(String[] args) throws IOException { //argi: path to lucene index dir for (int i = 0; i < args.length; ++i) { final LuceneSearcher luceneSearcher = new LuceneSearcher(args[i]); luceneSearcher.open();// ww w.ja v a 2s.c o m final IndexSearcher indexSearcher = luceneSearcher.getIndexSearcher(); final IndexReader indexReader = indexSearcher.getIndexReader(); System.out.println("numDocs(" + args[i] + ")=" + indexReader.numDocs()); luceneSearcher.close(); } }
From source file:org.sindice.siren.search.TestSirenExactPhraseScorer.java
License:Apache License
@Override protected void assertTo(final AssertFunctor functor, final String[] input, final String[] phraseTerms, final int expectedNumDocs, final int[] expectedNumTuples, final int[] expectedNumCells, final int[] expectedEntityID, final int[] expectedTupleID, final int[] expectedCellID, final int[] expectedPos) throws Exception { _helper.reset();//w ww .j a v a 2 s . c o m _helper.addDocuments(input); final IndexReader reader = _helper.getIndexReader(); assertEquals(expectedNumDocs, reader.numDocs()); final SirenExactPhraseScorer scorer = this.getExactScorer(QueryTestingHelper.DEFAULT_FIELD, phraseTerms); functor.run(scorer, expectedNumDocs, expectedNumTuples, expectedNumCells, expectedEntityID, expectedTupleID, expectedCellID, expectedPos); reader.close(); }
From source file:org.sindice.siren.search.TestSirenTermScorer.java
License:Apache License
@Override protected void assertTo(final AssertFunctor functor, final String[] input, final String[] terms, final int expectedNumDocs, final int[] expectedNumTuples, final int[] expectedNumCells, final int[] expectedEntityID, final int[] expectedTupleID, final int[] expectedCellID, final int[] expectedPos) throws Exception { _helper.reset();/* w w w . ja v a2 s . c o m*/ _helper.addDocuments(input); final IndexReader reader = _helper.getIndexReader(); assertEquals(expectedNumDocs, reader.numDocs()); SirenTermScorer scorer = null; for (final String t : terms) { scorer = this.getTermScorer(QueryTestingHelper.DEFAULT_FIELD, t); functor.run(scorer, expectedNumDocs, expectedNumTuples, expectedNumCells, expectedEntityID, expectedTupleID, expectedCellID, expectedPos); } reader.close(); }
From source file:org.sonatype.nexus.index.AbstractRepoNexusIndexerTest.java
License:Open Source License
public void testPackaging() throws Exception { IndexReader reader = context.getIndexReader(); for (int i = 0; i < reader.numDocs(); i++) { if (!reader.isDeleted(i)) { Document document = reader.document(i); String uinfo = document.get(ArtifactInfo.UINFO); if (uinfo != null) { String info = document.get(ArtifactInfo.INFO); assertFalse(info.startsWith("null")); }/*from w ww .j a v a2s .c o m*/ } } // { // Query query = new TermQuery( new Term( ArtifactInfo.PACKAGING, "jar" ) ); // FlatSearchResponse response = nexusIndexer.searchFlat(new FlatSearchRequest(query)); // assertEquals(response.getResults().toString(), 22, response.getTotalHits()); // } { Query query = new TermQuery(new Term(ArtifactInfo.PACKAGING, "tar.gz")); FlatSearchResponse response = nexusIndexer.searchFlat(new FlatSearchRequest(query)); assertEquals(response.getResults().toString(), 1, response.getTotalHits()); ArtifactInfo ai = response.getResults().iterator().next(); assertEquals("tar.gz", ai.packaging); assertEquals("tar.gz", ai.fextension); } { Query query = new TermQuery(new Term(ArtifactInfo.PACKAGING, "zip")); FlatSearchResponse response = nexusIndexer.searchFlat(new FlatSearchRequest(query)); assertEquals(response.getResults().toString(), 1, response.getTotalHits()); ArtifactInfo ai = response.getResults().iterator().next(); assertEquals("zip", ai.packaging); assertEquals("zip", ai.fextension); } }
From source file:org.sonatype.nexus.index.DefaultScannerListener.java
License:Open Source License
private void initialize(IndexingContext ctx) throws IOException, CorruptIndexException { IndexReader r = ctx.getIndexReader(); for (int i = 0; i < r.numDocs(); i++) { if (!r.isDeleted(i)) { Document d = r.document(i); String uinfo = d.get(ArtifactInfo.UINFO); if (uinfo != null) { uinfos.add(uinfo);// www. ja va2 s . c o m // add all existing groupIds to the lists, as they will // not be "discovered" and would be missing from the new list.. String groupId = uinfo.substring(0, uinfo.indexOf('|')); int n = groupId.indexOf('.'); groups.add(n == -1 ? groupId : groupId.substring(0, n)); allGroups.add(groupId); } } } }
From source file:org.sonatype.nexus.index.Nexus737NexusIndexerTest.java
License:Open Source License
public void testValidateUINFOs() throws Exception { IndexReader reader = context.getIndexReader(); int foundCount = 0; for (int i = 0; i < reader.numDocs(); i++) { Document document = reader.document(i); String uinfo = document.get(ArtifactInfo.UINFO); if ("org.sonatype.nexus|nexus-webapp|1.0.0-SNAPSHOT|NA".equals(uinfo) || "org.sonatype.nexus|nexus-webapp|1.0.0-SNAPSHOT|bundle|zip".equals(uinfo) || "org.sonatype.nexus|nexus-webapp|1.0.0-SNAPSHOT|bundle|tar.gz".equals(uinfo)) { foundCount++;/* w w w.j av a 2 s. c om*/ } } assertEquals(foundCount, 3); }
From source file:org.sonatype.nexus.index.updater.DefaultIndexUpdater.java
License:Open Source License
private static void filterDirectory(final Directory directory, final DocumentFilter filter) throws IOException { IndexReader r = null; try {//from w ww.j av a 2s. com r = IndexReader.open(directory); int numDocs = r.numDocs(); for (int i = 0; i < numDocs; i++) { if (r.isDeleted(i)) { continue; } Document d = r.document(i); if (!filter.accept(d)) { r.deleteDocument(i); } } } finally { IndexUtils.close(r); } IndexWriter w = null; try { // analyzer is unimportant, since we are not adding/searching to/on index, only reading/deleting w = new IndexWriter(directory, new NexusAnalyzer()); w.optimize(); w.flush(); } finally { IndexUtils.close(w); } }
From source file:org.sonatype.nexus.index.updater.IndexDataWriter.java
License:Open Source License
public int writeDocuments(IndexReader r, List<Integer> docIndexes) throws IOException { int n = 0;//w w w .j a v a 2 s . c o m if (docIndexes == null) { for (int i = 0; i < r.numDocs(); i++) { if (!r.isDeleted(i)) { writeDocument(r.document(i)); n++; } } } else { for (int i : docIndexes) { if (!r.isDeleted(i)) { writeDocument(r.document(i)); n++; } } } return n; }
From source file:org.springmodules.lucene.index.core.DefaultLuceneIndexTemplate.java
License:Apache License
public int getNumDocs() { IndexReader reader = IndexReaderFactoryUtils.getIndexReader(indexFactory); try {/*from w w w . ja v a 2 s . com*/ return reader.numDocs(); } finally { IndexReaderFactoryUtils.releaseIndexReader(indexFactory, reader); } }