--[[----------------------------------------------------------------------------

WFCatOnlineSearchResultTableHandler.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2015 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remains the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and are protected by all applicable
intellectual property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

------------------------------------------------------------------------------]]

local WFRxRunUntilDone = require 'WFRxRunUntilDone'
local WFCatSearchAndSortConstants = require 'WFCatSearchAndSortConstants'

local WFCatOnlineSearchResultTableHandler = {}
--------------------------------------------------------------------------------
-- check for this value in WFCatOnlineSearchResultTable.lua
local ONLINESEARCH_TEMP_TABLE_NAME = WFCatSearchAndSortConstants.ONLINESEARCH_TEMP_TABLE_NAME

--------------------------------------------------------------------------------
function WFCatOnlineSearchResultTableHandler.updateSearchTable( catalog, queryId, assetsWithScoreList )
	
	assetsWithScoreList = assetsWithScoreList or {}
	
	for _, info in ipairs( assetsWithScoreList ) do
		info[ #info + 1 ] = queryId
	end
	
	if assetsWithScoreList and #assetsWithScoreList > 0 then
		
		return catalog:indexStore()
			:bulkInsertManualTable( ONLINESEARCH_TEMP_TABLE_NAME, assetsWithScoreList )
			:call( WFRxRunUntilDone )
	
	end
	
end
			
--------------------------------------------------------------------------------		
function WFCatOnlineSearchResultTableHandler.clearSearchTable( catalog )
			
	return catalog:indexStore()
		:clearManualTable( ONLINESEARCH_TEMP_TABLE_NAME )
		:call( WFRxRunUntilDone )
	
end

--------------------------------------------------------------------------------
return WFCatOnlineSearchResultTableHandler
