##required: catalogid, detail, view, fieldname
##optional: value, foreignkeyid and foreignkeyvalue
#set ($catalogidother = $context.getRequestParameter('catalogid'))
#if($catalogidother)
#set ($catalogid = $catalogidother)
#end
#ifnull ($fieldname)
#set ($fieldname = $context.getRequestParameter('fieldname')) ##lastmodified
#end
#set ($view = $context.getRequestParameter('view'))
##we need to load up the existing detail object
#if( !$detail) ##this is new. To reduce complexity we want to just load up the detail all the time
#if(!$searchtype)
#set ( $searchtype = $context.getRequestParameter("searchtype") )
#end
#if( !$searchtype)
searchtype not found!
#end
#set( $originalsearcher = $searcherManager.getSearcher($catalogid, $searchtype))
#set ($fieldname = $context.getRequestParameter('fieldname')) ##lastmodified
#set( $detail = $originalsearcher.getDetailForView($view, $fieldname, $user) )
#end
#set ($fieldname = $detail.id)
#set( $listid = $detail.getListId())
#set( $csslistid = "listdetail_$fieldname")
#set( $originalsearcher = $searcherManager.getSearcher($catalogid, $listid))
#set( $lsearcher = $searcherManager.getSearcher( $detail.getListCatalogId(), $listid ))
##require both
#set ($listfilterid = $detail.get("listfilterid") ) ##local field that we depend on to get the value, get the value
#if( $listfilterid)
#set( $listfilterdetail = $originalsearcher.getDetailForView($view, $listfilterid, $user) )
#set ($remotevalue = $context.getRequestParameter('foreignkeyvalue'))
#if(!$remotevalue)
#set( $remotevalue = $data.get($listfilterid) )
#end
#if(!$remotevalue)
#set ($remotevalue = $context.replaceProperty($detail.defaultvalue) ) ##not used much
#end
#if( $remotevalue)
#set($foreignkeyid = $detail.get("foreignkeyid") ) ##remove column that we search on. Use the value here
#if( !$foreignkeyid)
#set($foreignkeyid = $listfilterid)
#end
#set($query = $lsearcher.query().exact($foreignkeyid,$remotevalue).getQuery() )
#end
#else
#set($query = $lsearcher.query().all().getQuery() )
#end
#if($query)
$query.setSortBy($detail.getDefaultSort())
#end
####$lsearcher.addShowOnly($context, $query)
#set ($types = $lsearcher.search($context, $query))
#ifnull ($value)
#set ($value = $context.getRequestParameter('val'))
#end
#ifnull ($value)
#set ($value = $val)
#end
#ifnull ($value)
#set ($value = $context.replaceProperty($detail.defaultvalue) )
#end
#set($searchfield = $detail.getId() )
#set( $valueid = "$fieldname" )
#if($types)
## Set large limit for available options
$types.setHitsPerPage(200)
#if($types && $types.size() > 200)
#set($ajaxMode = true)
#end
#if($detail.get("autocomplete") == "true")
#set($ajaxMode = true)
#end
#set($ajaxfield = "name")
#if($lsearcher.getDetail("description"))
#set($ajaxfield = "description")
#end
$context.putPageValue("listresults", $types)
#else
[[No values found]]
#end