TestModifiedEntryFilterpublic class TestModifiedEntryFilter extends TestCase
Fields Summary |
---|
IndexWriter | writer | IndexReader | reader | List | excludeList | String | feedID | String | fieldFeedId |
Methods Summary |
---|
protected void | setUp()
RAMDirectory dir = new RAMDirectory();
this.writer = new IndexWriter(dir,new StandardAnalyzer(),true);
Document doc = new Document();
doc.add(new Field(StorageEntryWrapper.FIELD_ENTRY_ID,"1",Field.Store.YES,Field.Index.UN_TOKENIZED));
doc.add(new Field(fieldFeedId,feedID,Field.Store.YES,Field.Index.UN_TOKENIZED));
Document doc1 = new Document();
doc1.add(new Field(StorageEntryWrapper.FIELD_ENTRY_ID,"2",Field.Store.YES,Field.Index.UN_TOKENIZED));
doc1.add(new Field(fieldFeedId,feedID,Field.Store.YES,Field.Index.UN_TOKENIZED));
this.writer.addDocument(doc);
this.writer.addDocument(doc1);
this.writer.close();
this.reader = IndexReader.open(dir);
this.excludeList = new ArrayList();
this.excludeList.add("1");
| protected void | tearDown()
super.tearDown();
| public void | testFilter()
Searcher s = new IndexSearcher(this.reader);
Query q = new TermQuery(new Term(fieldFeedId,feedID));
Hits hits = s.search(q);
assertEquals(2,hits.length());
hits = s.search(q,new ModifiedEntryFilter(this.excludeList.toArray(new String[0]),StorageEntryWrapper.FIELD_ENTRY_ID));
assertEquals(1,hits.length());
this.excludeList.add("2");
hits = s.search(q,new ModifiedEntryFilter(this.excludeList.toArray(new String[0]),StorageEntryWrapper.FIELD_ENTRY_ID));
assertEquals(0,hits.length());
this.excludeList.add(null);
this.excludeList.add("5");
hits = s.search(q,new ModifiedEntryFilter(this.excludeList.toArray(new String[0]),StorageEntryWrapper.FIELD_ENTRY_ID));
assertEquals(0,hits.length());
|
|