def testGetSearchResults(self): global search_results facade = SearchFacade(self.dmd) search_results = createResultsFromRange(25) results = facade.getSearchResults( "testquery", None ) results = results['results'] dummyIds = [result.id for result in results if isinstance(result, DummyResult)] self.assertEquals( set(range(1,26)), set(dummyIds) )
def testSortByExcerpt(self): ids = [6, 4, 3, 2, 8, 5, 9, 7, 1] global search_results search_results = createResultsFromIds(ids) facade = SearchFacade(self.dmd) results = facade.getSearchResults("testquery", category=None) results = results['results'] resultIds = [result.id for result in results] self.assertEquals(range(1, 10), resultIds)
def testSortByExcerpt(self): ids = [6,4,3,2,8,5,9,7,1] global search_results search_results = createResultsFromIds(ids) facade = SearchFacade(self.dmd) results = facade.getSearchResults( "testquery", category=None ) results = results['results'] resultIds = [result.id for result in results] self.assertEquals( range(1,10), resultIds )
def testGetSearchResults(self): global search_results facade = SearchFacade(self.dmd) search_results = createResultsFromRange(25) results = facade.getSearchResults("testquery", None) results = results['results'] dummyIds = [ result.id for result in results if isinstance(result, DummyResult) ] self.assertEquals(set(range(1, 26)), set(dummyIds))
def testCategoryCountFilter(self): global search_results search_results = createResultsFromRange(8,'cat1') search_results.extend( createResultsFromRange(7,'cat2') ) facade = SearchFacade(self.dmd) sorter = DefaultSearchResultSorter( 20, 5 ) results = facade.getQuickSearchResults( "testquery", sorter ) results = results['results'] cat1Ids = [result.id for result in results if result.category == 'cat1'] self.assertEquals( set(range(1,6)), set(cat1Ids) )
def testGetQuickSearchResults(self): global search_results facade = SearchFacade(self.dmd) search_results = createResultsFromRange(20) sorter = DefaultSearchResultSorter(10) results = facade.getQuickSearchResults( "testquery", sorter ) results = results['results'] # Should only have 10 results dummyIds = [result.id for result in results if isinstance(result, DummyResult)] self.assertEquals( set(range(1,11)), set(dummyIds) )
def testGetQuickSearchResults(self): global search_results facade = SearchFacade(self.dmd) search_results = createResultsFromRange(20) sorter = DefaultSearchResultSorter(10) results = facade.getQuickSearchResults("testquery", sorter) results = results['results'] # Should only have 10 results dummyIds = [ result.id for result in results if isinstance(result, DummyResult) ] self.assertEquals(set(range(1, 11)), set(dummyIds))
def testCategoryCountFilter(self): global search_results search_results = createResultsFromRange(8, 'cat1') search_results.extend(createResultsFromRange(7, 'cat2')) facade = SearchFacade(self.dmd) sorter = DefaultSearchResultSorter(20, 5) results = facade.getQuickSearchResults("testquery", sorter) results = results['results'] cat1Ids = [ result.id for result in results if result.category == 'cat1' ] self.assertEquals(set(range(1, 6)), set(cat1Ids))
def testCategorySortAndLimit2(self): global search_results maxPerCategory = 4 device_results = createResultsFromRange(2 * maxPerCategory, 'Device') event_results = createResultsFromRange(2 * maxPerCategory, 'Event') other1_results = createResultsFromRange(2 * maxPerCategory, 'Category1') other2_results = createResultsFromRange(2 * maxPerCategory, 'Category2') search_results = other2_results + event_results + device_results + \ other1_results facade = SearchFacade(self.dmd) sorter = DefaultSearchResultSorter( 2 * maxPerCategory, maxPerCategory ) results = facade.getQuickSearchResults( 'testquery', sorter ) results = results['results'] expected = device_results[:maxPerCategory] + \ event_results[:maxPerCategory] self.assertEquals( expected, list(results) )
def testCategorySortAndLimit2(self): global search_results maxPerCategory = 4 device_results = createResultsFromRange(2 * maxPerCategory, 'Device') event_results = createResultsFromRange(2 * maxPerCategory, 'Event') other1_results = createResultsFromRange(2 * maxPerCategory, 'Category1') other2_results = createResultsFromRange(2 * maxPerCategory, 'Category2') search_results = other2_results + event_results + device_results + \ other1_results facade = SearchFacade(self.dmd) sorter = DefaultSearchResultSorter(2 * maxPerCategory, maxPerCategory) results = facade.getQuickSearchResults('testquery', sorter) results = results['results'] expected = device_results[:maxPerCategory] + \ event_results[:maxPerCategory] self.assertEquals(expected, list(results))
def testCategoryLimit(self): global search_results device_results = createResultsFromRange(9, 'Device') event_results = createResultsFromRange(9, 'Event') other1_results = createResultsFromRange(9, 'Category1') other2_results = createResultsFromRange(9, 'Category2') search_results = other2_results + event_results + device_results + \ other1_results facade = SearchFacade(self.dmd) maxPerCategory = 5 sorter = DefaultSearchResultSorter( maxResultsPerCategory=maxPerCategory) results = facade.getQuickSearchResults('testquery', sorter) results = results['results'] expected = device_results[:maxPerCategory] + \ event_results[:maxPerCategory] + \ other1_results[:maxPerCategory] + \ other2_results[:maxPerCategory] results = list(results) self.assertEqual(len(expected), len(results)) self.assertEquals(expected, results)
def testCategoryLimit(self): global search_results device_results = createResultsFromRange(9, 'Device') event_results = createResultsFromRange(9, 'Event') other1_results = createResultsFromRange(9, 'Category1') other2_results = createResultsFromRange(9, 'Category2') search_results = other2_results + event_results + device_results + \ other1_results facade = SearchFacade(self.dmd) maxPerCategory = 5 sorter = DefaultSearchResultSorter( maxResultsPerCategory=maxPerCategory ) results = facade.getQuickSearchResults( 'testquery', sorter ) results = results['results'] expected = device_results[:maxPerCategory] + \ event_results[:maxPerCategory] + \ other1_results[:maxPerCategory] + \ other2_results[:maxPerCategory] results = list(results) self.assertEqual(len(expected), len(results)) self.assertEquals( expected, results )