mirror of https://github.com/apache/lucene.git
- Typo and tabs
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@487922 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9b2405c0cc
commit
d0f24d87da
|
@ -36,160 +36,160 @@ public class TestMultiThreadTermVectors extends TestCase {
|
||||||
private RAMDirectory directory = new RAMDirectory();
|
private RAMDirectory directory = new RAMDirectory();
|
||||||
public int numDocs = 100;
|
public int numDocs = 100;
|
||||||
public int numThreads = 3;
|
public int numThreads = 3;
|
||||||
|
|
||||||
public TestMultiThreadTermVectors(String s) {
|
public TestMultiThreadTermVectors(String s) {
|
||||||
super(s);
|
super(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
IndexWriter writer
|
IndexWriter writer
|
||||||
= new IndexWriter(directory, new SimpleAnalyzer(), true);
|
= new IndexWriter(directory, new SimpleAnalyzer(), true);
|
||||||
//writer.setUseCompoundFile(false);
|
//writer.setUseCompoundFile(false);
|
||||||
//writer.infoStream = System.out;
|
//writer.infoStream = System.out;
|
||||||
for (int i = 0; i < numDocs; i++) {
|
for (int i = 0; i < numDocs; i++) {
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
Fieldable fld = new Field("field", English.intToEnglish(i), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.YES);
|
Fieldable fld = new Field("field", English.intToEnglish(i), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.YES);
|
||||||
doc.add(fld);
|
doc.add(fld);
|
||||||
writer.addDocument(doc);
|
writer.addDocument(doc);
|
||||||
}
|
}
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test() {
|
public void test() {
|
||||||
|
|
||||||
IndexReader reader = null;
|
IndexReader reader = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader = IndexReader.open(directory);
|
reader = IndexReader.open(directory);
|
||||||
for(int i = 1; i <= numThreads; i++)
|
for(int i = 1; i <= numThreads; i++)
|
||||||
testTermPositionVectors(reader, i);
|
testTermPositionVectors(reader, i);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (IOException ioe) {
|
catch (IOException ioe) {
|
||||||
fail(ioe.getMessage());
|
fail(ioe.getMessage());
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
try {
|
try {
|
||||||
/** close the opened reader */
|
/** close the opened reader */
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTermPositionVectors(final IndexReader reader, int threadCount) {
|
public void testTermPositionVectors(final IndexReader reader, int threadCount) {
|
||||||
MultiThreadTermVectorsReader[] mtr = new MultiThreadTermVectorsReader[threadCount];
|
MultiThreadTermVectorsReader[] mtr = new MultiThreadTermVectorsReader[threadCount];
|
||||||
for (int i = 0; i < threadCount; i++) {
|
for (int i = 0; i < threadCount; i++) {
|
||||||
mtr[i] = new MultiThreadTermVectorsReader();
|
mtr[i] = new MultiThreadTermVectorsReader();
|
||||||
mtr[i].init(reader);
|
mtr[i].init(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** run until all threads finished */
|
/** run until all threads finished */
|
||||||
int threadsAlive = mtr.length;
|
int threadsAlive = mtr.length;
|
||||||
while (threadsAlive > 0) {
|
while (threadsAlive > 0) {
|
||||||
try {
|
try {
|
||||||
//System.out.println("Threads alive");
|
//System.out.println("Threads alive");
|
||||||
Thread.sleep(10);
|
Thread.sleep(10);
|
||||||
threadsAlive = mtr.length;
|
threadsAlive = mtr.length;
|
||||||
for (int i = 0; i < mtr.length; i++) {
|
for (int i = 0; i < mtr.length; i++) {
|
||||||
if (mtr[i].isAlive() == true) {
|
if (mtr[i].isAlive() == true) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
threadsAlive--;
|
threadsAlive--;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (InterruptedException ie) {}
|
} catch (InterruptedException ie) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
long totalTime = 0L;
|
long totalTime = 0L;
|
||||||
for (int i = 0; i < mtr.length; i++) {
|
for (int i = 0; i < mtr.length; i++) {
|
||||||
totalTime += mtr[i].timeElapsed;
|
totalTime += mtr[i].timeElapsed;
|
||||||
mtr[i] = null;
|
mtr[i] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//System.out.println("threadcount: " + mtr.length + " average term vector time: " + totalTime/mtr.length);
|
//System.out.println("threadcount: " + mtr.length + " average term vector time: " + totalTime/mtr.length);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MultiThreadTermVectorsReader implements Runnable {
|
class MultiThreadTermVectorsReader implements Runnable {
|
||||||
|
|
||||||
private IndexReader reader = null;
|
private IndexReader reader = null;
|
||||||
private Thread t = null;
|
private Thread t = null;
|
||||||
|
|
||||||
private final int runsToDo = 100;
|
private final int runsToDo = 100;
|
||||||
long timeElapsed = 0;
|
long timeElapsed = 0;
|
||||||
|
|
||||||
|
|
||||||
public void init(IndexReader reader) {
|
public void init(IndexReader reader) {
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
timeElapsed = 0;
|
timeElapsed = 0;
|
||||||
t=new Thread(this);
|
t=new Thread(this);
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAlive() {
|
public boolean isAlive() {
|
||||||
if (t == null) return false;
|
if (t == null) return false;
|
||||||
|
|
||||||
return t.isAlive();
|
return t.isAlive();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
// run the test 100 times
|
// run the test 100 times
|
||||||
for (int i = 0; i < runsToDo; i++)
|
for (int i = 0; i < runsToDo; i++)
|
||||||
testTermVectors();
|
testTermVectors();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testTermVectors() throws Exception {
|
private void testTermVectors() throws Exception {
|
||||||
// check:
|
// check:
|
||||||
int numDocs = reader.numDocs();
|
int numDocs = reader.numDocs();
|
||||||
long start = 0L;
|
long start = 0L;
|
||||||
for (int docId = 0; docId < numDocs; docId++) {
|
for (int docId = 0; docId < numDocs; docId++) {
|
||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
TermFreqVector [] vectors = reader.getTermFreqVectors(docId);
|
TermFreqVector [] vectors = reader.getTermFreqVectors(docId);
|
||||||
timeElapsed += System.currentTimeMillis()-start;
|
timeElapsed += System.currentTimeMillis()-start;
|
||||||
|
|
||||||
// verify vectors result
|
// verify vectors result
|
||||||
verifyVectors(vectors, docId);
|
verifyVectors(vectors, docId);
|
||||||
|
|
||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
TermFreqVector vector = reader.getTermFreqVector(docId, "field");
|
TermFreqVector vector = reader.getTermFreqVector(docId, "field");
|
||||||
timeElapsed += System.currentTimeMillis()-start;
|
timeElapsed += System.currentTimeMillis()-start;
|
||||||
|
|
||||||
vectors = new TermFreqVector[1];
|
vectors = new TermFreqVector[1];
|
||||||
vectors[0] = vector;
|
vectors[0] = vector;
|
||||||
|
|
||||||
verifyVectors(vectors, docId);
|
verifyVectors(vectors, docId);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyVectors(TermFreqVector[] vectors, int num) {
|
private void verifyVectors(TermFreqVector[] vectors, int num) {
|
||||||
StringBuffer temp = new StringBuffer();
|
StringBuffer temp = new StringBuffer();
|
||||||
String[] terms = null;
|
String[] terms = null;
|
||||||
for (int i = 0; i < vectors.length; i++) {
|
for (int i = 0; i < vectors.length; i++) {
|
||||||
terms = vectors[i].getTerms();
|
terms = vectors[i].getTerms();
|
||||||
for (int z = 0; z < terms.length; z++) {
|
for (int z = 0; z < terms.length; z++) {
|
||||||
temp.append(terms[z]);
|
temp.append(terms[z]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!English.intToEnglish(num).trim().equals(temp.toString().trim()))
|
if (!English.intToEnglish(num).trim().equals(temp.toString().trim()))
|
||||||
System.out.println("worng term result");
|
System.out.println("wrong term result");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue