SearchService.Query() does not throw exception on empty query


The problem is these lines:

            if (string.IsNullOrWhiteSpace(query))
                return new PageOfItems<T>(Enumerable.Empty<T>());

            var searchBuilder = Search(index).Parse(searchFields, query);
the Parse() method throws an exception when the query is empty. But, this exception does now not get thrown because of the if above that call.

So, when the user searches for "" (zerolength string), then he will get no information. And also no results. This is not clear, the exception thrown is good. So the if needs to go.


AimOrchard wrote Sep 25, 2013 at 11:37 AM

Isn't the question: What does the caller expect?

Imho returning 'no' results for 'no' query seems a fine way to handle things.

hkui wrote Sep 25, 2013 at 1:36 PM

BUT the user does not get any information about this.

AimOrchard wrote Sep 25, 2013 at 2:15 PM

If I supply google with no search terms, it won't tell me neither?

I really do not see the issue. What is your specific scenario that demands that specific location to trigger an exception (that cannot be handled by you yourself checking for an empty query before calling the method in the first place)

hkui wrote Sep 25, 2013 at 2:47 PM

The SearchController provides no way of me extending it, to fix it. So it has to be fixed there.

Google doing that, does not make that "feature" the right way to do it.

From a user's perspective, it's weird. Also, a while ago it did work that way: When entering no search query, there was a message "You need to specify a search query." or something.

hkui wrote Sep 25, 2013 at 2:55 PM

Hm, I thought this was a change.

But apparently it was also done this way back in 1.6.

However, though, it WOULD be nice to inform the user; there's a difference between actually having 0 results, or doing no search because the user entered no text.

Right now, there are 0 results on a "" search query, BUT no search was actually performed. Lucene wasn't even touched. It would be nice to make the user experience according to that difference.