Is there a way to have a collection limit the number of results it reveals? In other words, if the query finds 1,000 results, cut of the display of those at 50.
I looked at query_processor_options=-num_ranks=##, but that appears to be the number of results “per page” of results.
I looked at ui.modern.external_num_ranks_limit=##, but that doesn’t appear to do anything in my testing or appears to be a limiter over query_processor_options=-num_ranks=##
I would think it would be straightforward to collection – show NO more than the first 50 results for searches.
The short answer is to set those two settings you mention, and also take away someone’s ability to paginate.
query_processor_options=-num_ranks=50 // returns 50 results
ui.modern.external_num_ranks_limit=50 // limits to 50 if user types num_ranks into URL
A hook_pre_process.groovy script could be used to remove the pagination parameter (start_rank) from the inputParameterMap, if it exists. This would stop a user from manually typing in the start_rank to paginate if they happened to know how the URL works.
I think there might be another question here - is there something else that you’re trying to accomplish? Is this to prevent abuse from end users trying to retrieve too many results and putting load on the server, or something else?
Thanks for the reply. I will look into the Groovy script idea.
But, the use case is where we don’t want users to use a search result to scrape our data. Example is a People search. We don’t want Bad Actors to search and scrape every “Ann” and “Bob” and “Chris” (etc.) throughout our organization.
Following up for completeness here, below is a sample Groovy script that can be used in a hook_pre_process.groovy script.
The idea of this script is that it will remove the “start_rank” parameter if it is added to the URL. The “hook_pre_process” runs after the query is received from the user and before the query processor executes to ensures the “start_rank” is not passed to the query processor.
def question = transaction.question
// Remove the start_rank parameter if it is added to the URL
if (question.additionalParameters['start_rank'] != null) {
question.additionalParameters.remove('start_rank')
}
To all out there, his script worked, and we are on our way forward!
I was a combination of (a) limiting results per page, (2) removing pagination from the UI, and (3) putting in the Groovy Script to not allow anyone to hack the URL via an argument of &start_rank=###
You could also set a limit in the results template. I needed to do this for some proof of concept work I was doing. For example the following sets a limit of 20 and uses a decrementing counter to keep track of how many results have been displayed.
<#-- set a limit to the number of results returned -->
<#assign limit=20>
<ol id="search-results" class="list-unstyled" start="${response.resultPacket.resultsSummary.currStart}">
<@s.Results>
<#if s.result.class.simpleName == "TierBar">
<#else>
<#if limit gt 0>
<li>
<#if s.result.title??>
<#if show_result_url>
<h4><a href="${s.result.displayUrl}" class="text-success">${s.result.title}</a></h4>
</#if>
</#if>
<#if s.result.summary??>
<p>${s.result.summary}</p>
</#if>
</li>
<#assign limit-->
</#if>
</#if>
</@s.Results>
</ol>