[Solved]Sorting result of simple search form return [OJS 2.4.7.1]

Hi Everyone:

We are currently using the simple search function in OJS 2.4.7.1 as a index of some keywords, the result is currently randomly ordered, i have read through several posts and the solution seems have to use lucene plugin which requires a solr server, however our web hosting service provider does not allow us to install one.

Just wondering if it is possible to do some code modification to just sort the result by published date, so i changed a line of code in ArticleSearchDAO.inc

	$result =& $this->retrieveCached(
		'SELECT	o.article_id
		FROM	articles a,
			published_articles pa,
			issues i,
			article_search_objects o NATURAL JOIN ' . $sqlFrom . '
		WHERE	pa.article_id = a.article_id AND
			a.status = ' . STATUS_PUBLISHED . ' AND
			pa.article_id = o.article_id AND
			i.issue_id = pa.issue_id AND
			i.published = 1 AND ' . $sqlWhere . '
		GROUP BY o.article_id
		ORDER BY pa.date_published ASC
		LIMIT ' . $limit,
		$params,
		3600 * $cacheHours // Cache for 24 hours
	);

From ORDER BY COUNT DESC
to ORDER BY pa.date_published ASC
and delete COUNT(*) AS count

Now in the search result articles seems all in a correct order, just a simple solution to share, if there is a risk please let me know

Thanks for reading

Evo

1 Like

This change will switch the ordering of the results from the largest number of matches to the earliest published match.