 				return cb err if err
 				return cb null, FOUND_LINKS
 
-	# Swagger interface
 	app.get '/search', (req, res, next) ->
 		locals = links: [], query: req.query
-		if not req.query.id
+		if not req.query.id and not req.query.title
 			return res.render 'simple-search', locals
-		req.query.id = _denoise_id(req.query.id)
-		# Enable regex search with "?regex=on"
-		if not req.query.regex
-			needle = req.query.id
-		else
-			needle = '$regex': req.query.id
 		needleQuery = $or: []
-		needleQuery.$or.push _id: needle
-		needleQuery.$or.push identifier: needle
-		needleQuery.$or.push identifiers: needle
-		needleQuery.entityType = req.query.from_type || 'publication'
+		if req.query.id
+			req.query.id = _denoise_id(req.query.id)
+			# Enable regex search with "?regex=on"
+			if not req.query.regex
+				needle = req.query.id
+			else
+				needle = '$regex': req.query.id
+			needleQuery.$or.push _id: needle
+			needleQuery.$or.push identifier: needle
+			needleQuery.$or.push identifiers: needle
+		if req.query.title
+			needleQuery.$or.push name: '$regex': req.query.title
+		needleQuery.entityType = req.query.type || 'publication'
 		unless needleQuery.entityType in ['dataset', 'publication']
-			return next "from_type must be dataset or publication"
-		_find_links needleQuery, (err, links) ->
-			if err
-				next err
-			else
+			return next "type must be dataset or publication"
+		limit = parseInt(req.query.limit or 1000)
+		_find_links needleQuery, limit, (err, links) ->
+			return next err if err
+			if Accepts(req).type('text/html')
 				locals.links = links
 				return res.render 'simple-search', locals
+			else
+				return res.send links
 
 	done()

				return cb err if err
				return cb null, FOUND_LINKS

	_find_links = (needleQuery, cb) ->
		log.debug("Entity query:". needleQuery)
		FOUND_LINKS = []
		Entity.find(needleQuery).limit(1000).exec (err, entities) ->
			return cb err if err
			return cb null, [] if entities.length == 0
			Async.eachSeries entities, (fromEntity, cbEntities1) ->
				#
				# Query1 (publication -> dataset)
				#
				# log.debug "fromEntity", fromEntity.uri()
				if fromEntity.entityType is 'publication'
					_find_links_from_publication fromEntity, (err, links) ->
						return cbEntities1 err if err
						FOUND_LINKS.push x for x in links
						return cbEntities1()

CONFIG = require '../config'
Async  = require 'async'
log = require('../log')(module)
Accepts    = require 'accepts'

_denoise_id = (s) ->
	sold = s
	s = s.replace(/doi:/i, '')
	s = s.replace(new RegExp("https?://(dx\\.)?doi.org/?"), '')
	# log.debug("_denoise_id: #{sold} -> #{s}")
	return s

_get_id = (s) ->
	snew = s.substr(s.lastIndexOf('/') + 1)
	# log.debug("_get_id: #{s} -> #{snew}")
	return snew

#publication -> entityLink -> dataset
