waitForIndexer();
/* Condition 1a: Enum (match) */
{
ISearchField field = fFactory.createSearchField(INews.STATE, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, EnumSet.of(State.READ));
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1);
}
/* Condition 1b: Enum (no match) */
{
ISearchField field = fFactory.createSearchField(INews.STATE, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, EnumSet.of(State.DELETED));
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertEquals(0, result.size());
}
/* Condition 2a: Integer (match) */
{
/* Rating */
ISearchField field = fFactory.createSearchField(INews.RATING, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, 10);
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news2);
/* Age in Days */
field = fFactory.createSearchField(INews.AGE_IN_DAYS, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, 0);
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1, news5);
field = fFactory.createSearchField(INews.AGE_IN_DAYS, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, 5);
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news3);
field = fFactory.createSearchField(INews.AGE_IN_DAYS, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, 1);
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news2);
}
/* Condition 2b: Integer (no match) */
{
/* Rating */
ISearchField field = fFactory.createSearchField(INews.RATING, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, 15);
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertEquals(0, result.size());
/* Age in Days */
field = fFactory.createSearchField(INews.AGE_IN_DAYS, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, 100);
result = fModelSearch.searchNews(list(condition), false);
assertEquals(0, result.size());
field = fFactory.createSearchField(INews.AGE_IN_DAYS, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, 8);
result = fModelSearch.searchNews(list(condition), false);
assertEquals(0, result.size());
}
/* Condition 3a: String (match) */
{
/* Categories */
ISearchField field = fFactory.createSearchField(INews.CATEGORIES, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "apple");
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1, news2, news3);
field = fFactory.createSearchField(INews.CATEGORIES, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "windows");
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news2, news3);
field = fFactory.createSearchField(INews.CATEGORIES, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "slash*");
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news3);
field = fFactory.createSearchField(INews.CATEGORIES, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "a*le");
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1, news2, news3);
field = fFactory.createSearchField(INews.CATEGORIES, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "apache lucene");
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news5);
/* Labels */
field = fFactory.createSearchField(INews.LABEL, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, label1.getName());
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1);
/* Source Name */
field = fFactory.createSearchField(INews.SOURCE, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "Source for News 5");
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news5);
}
/* Condition 3b: String (no match) */
{
/* Author */
ISearchField field = fFactory.createSearchField(INews.AUTHOR, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "Pasero Benjamin");
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertEquals(0, result.size());
/* Categories */
field = fFactory.createSearchField(INews.CATEGORIES, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "apple slashdot");
result = fModelSearch.searchNews(list(condition), false);
assertEquals(0, result.size());
field = fFactory.createSearchField(INews.CATEGORIES, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "sleshdod");
result = fModelSearch.searchNews(list(condition), false);
assertEquals(0, result.size());
field = fFactory.createSearchField(INews.CATEGORIES, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "lucene apache");
result = fModelSearch.searchNews(list(condition), false);
assertEquals(0, result.size());
/* Source Name */
field = fFactory.createSearchField(INews.SOURCE, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "Source for");
result = fModelSearch.searchNews(list(condition), false);
assertEquals(0, result.size());
}
/* Condition 4a: Date (match) */
{
ISearchField field = fFactory.createSearchField(INews.PUBLISH_DATE, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, news4Date);
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news4);
}
/* Condition 4b: Date (no match) */
{
Date wrongDate = new Date();
ISearchField field = fFactory.createSearchField(INews.PUBLISH_DATE, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, wrongDate);
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertEquals(0, result.size());
}
/* Condition 5a: Boolean (one match) */
{
ISearchField field = fFactory.createSearchField(INews.IS_FLAGGED, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, true);
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news5);
/* Attachments */
field = fFactory.createSearchField(INews.HAS_ATTACHMENTS, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, true);
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1, news2);
}
/* Condition 5b: Boolean (other matches) */
{
ISearchField field = fFactory.createSearchField(INews.IS_FLAGGED, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, false);
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1, news2, news3, news4);
/* Attachments */
field = fFactory.createSearchField(INews.HAS_ATTACHMENTS, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, false);
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news3, news4, news5);
}
/* Condition 6a: Link (match) */
{
/* News Link */
ISearchField field = fFactory.createSearchField(INews.LINK, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "http://www.news.com/news1.html");
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1);
field = fFactory.createSearchField(INews.LINK, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "http://www.news.com/news?.html");
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1, news2, news3, news4, news5);
field = fFactory.createSearchField(INews.LINK, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "*www.news.com/news1.html");
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1);
/* Source Link */
field = fFactory.createSearchField(INews.SOURCE, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "http://www.source.com");
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news4);
/* Feed Link */
field = fFactory.createSearchField(INews.FEED, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "http://www.feed.com/feed.xml");
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1, news2, news3, news4, news5);
field = fFactory.createSearchField(INews.FEED, fNewsEntityName);
condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "http://www.feed.com/*");
result = fModelSearch.searchNews(list(condition), false);
assertSame(result, news1, news2, news3, news4, news5);
}
/* Condition 6b: Link (no match) */
{
/* News Link */
ISearchField field = fFactory.createSearchField(INews.LINK, fNewsEntityName);
ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "http://www.news.com/news6.html");
List<SearchHit<NewsReference>> result = fModelSearch.searchNews(list(condition), false);
assertEquals(0, result.size());
field = fFactory.createSearchField(INews.LINK, fNewsEntityName);