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

WFCatOnlineSearchResultTable.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 WFCatSearchAndSortConstants = require "WFCatSearchAndSortConstants"
--==============================================================================

local WFCatOnlineSearchResultTable = {}

	
local tableName = WFCatSearchAndSortConstants.ONLINESEARCH_TEMP_TABLE_NAME
--------------------------------------------------------------------------------

function WFCatOnlineSearchResultTable.generateIndexSchema( indexStoreSchema )

	indexStoreSchema:addTable {
		sql = string.format( "CREATE TABLE %s( docId, sortOrder )",tableName ),
		isManualTable = true
	}

	indexStoreSchema:addIndex( string.format("CREATE INDEX %s_docId ON %s (docId)", tableName, tableName ) )
	indexStoreSchema:addIndex( string.format("CREATE INDEX %s_sortOrder ON %s (sortOrder)",tableName, tableName ) )

end

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

function WFCatOnlineSearchResultTable.addSearchToSearchSchema( searchSchema )
	-- NOTE !!
	--[[
		Assertion failed: (vectorPtr->size() == 0 || (uint32_t) localId >= vectorPtr->back()),
		function buildSetF, 
		file /Users/ranik/MYData/nimbus/imported/adobe/wichitafoundation/sqlite/database/WFSQLiteSetLogic.cpp
	--]]
	-- The method which forms the result set from queries, as mentioned above expects  the results
	-- to be sent in the order for the first column data. i,e the docIds are expected to be sorted 
	
	local sqlString 
		= string.format("SELECT a.docId FROM assets a  INNER JOIN %s s ON a.assetId == s.docId ORDER BY a.docId ASC", 
						tableName)
	
	searchSchema:addSearchableData {
		term = 'onlineSearch',
		dataType = 'onlineSearchTerm',
		sql = sqlString,
	} 

end


--==============================================================================

return WFCatOnlineSearchResultTable
