question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When implementing code for initial empty query, search breaks on single char queries

See original GitHub issue

Do you want to request a feature or report a bug? Bug. I’m not certain if this is related to my implementation or if I have uncovered a bug in instant search.

Bug: What is the current behavior? I’ve implemented the “initial empty query” behaviour that was discussed in this ticket #4 where the user can have no results when the page is first loaded. I’m using the following code to do that:

var search = instantsearch({
	searchFunction: function(helper) {
		if (helper.state.query === "") {
			return;
		}
		helper.search();
	}
});

search.addWidget(
	instantsearch.widgets.searchbox({
		queryHook: function(query, search) {
			if (query === "") {
				search();
			} else {
				search(query);
			}
		}
	})
);

View my example here: https://codepen.io/Giovanni-Mattucci/pen/zwRrGo

Do the following steps:

  1. Search for “nursing”
  2. Remove your search term
  3. Type a single letter Notice that the search doesn’t happen.

animation2

Bug: What is the expected behavior? That after clearing search, searching by a single letter works.

Bug: What browsers are impacted? Which versions? All browsers.

What is the version you are using? Always use the latest one before opening a bug issue. Instantsearch.js 1.11.13

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Giovanni-Mattuccicommented, Jun 12, 2017

Ahh, so there is an additional step of hiding the hits area! Ok good to know. Thanks for the help, I think I got it figured out 😃

1reaction
bobylitocommented, Jun 12, 2017

Oh ok then that something that you can do. When you catch that the query is empty then you can hide the part that display the results and the filters and when it’s not empty you display them back.

To go even further, you can use the event render on instantsearch.js to change what is displayed in a smoother way. You can find of fork of your example on codepen. I mainly changed the searchFunction:

searchFunction: function(helper) {
	if (helper.state.query === "") {
		hideHits();
		return;
	}
	this.once('render', function() {
		showHits();
	});
	helper.search();
	if (!clearExecuted) {
		// run once on init
		clearExecuted = true;
		clearSearch(helper);
	}
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I set Algolia to not return any results if the query is ...
The behaviour I want is: if the visitor hasn't entered anything in the search box then no results are returned. However, the Algolia...
Read more >
Chapter 4. Query Performance Optimization - O'Reilly
In the previous chapter, we explained how to optimize a schema, which is one of the necessary conditions for high performance.
Read more >
Operators available for filters and queries
The system provides a set of operators for use with filters, condition builders, and encoded queries. The data type of a field determines ......
Read more >
Full-text query types and options - OpenSearch
Full-text query types and options. This page lists all full-text query types and common options. There are many optional fields that you can...
Read more >
Given two strings, find if first string is a Subsequence of second
// Driver program to check whether str1 is subsequence of str2 or not. int main(). {. char str1[] = "gksrek ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found