[MSHOP-127] Product search on an empty string (or spaces only) results in a queryParser.ParseException in the log Created: 09/Mar/14  Updated: 09/Jul/14  Resolved: 11/Apr/14

Status: Closed
Project: Magnolia Shop (closed)
Component/s: None
Affects Version/s: 1.1.4
Fix Version/s: 1.1.5, 2.0.1

Type: Bug Priority: Neutral
Reporter: Edgar Vonk Assignee: Jaroslav Simak
Resolution: Fixed Votes: 0
Labels: quickwin
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File error.txt    
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled

 Description   

When you perform a shop product search on an empty string (or a string consisting of spaces only) an error is written to the log:
2014-03-09 19:55:27,424 ERROR
.magnolia.module.shop.accessors.ShopProductAccesor: Cant read Products

caused by a org.apache.lucene.queryParser.ParseException. See the attached log file for details.

I think the ShopProductSearchResultParagraphModel should check for empty search strings and disallow them.



 Comments   
Comment by Edgar Vonk [ 13/Mar/14 ]

I implemented the search method in question as follows:

/**
	 * Performs a full text search on the products of the current shop.
	 *
	 * Does nothing and returns null if the search request parameter is empty or contains spaces only.
	 * 
	 * The method is very similar to {@link info.magnolia.module.shop.paragraphs.ShopProductSearchResultParagraphModel#search()}
	 * but improves on it by checking against empty search strings.
	 *
	 * @return the list of search result nodes; null if the search parameter was empty
	 */
	@Override
	protected List<Node> search() {
		List<Node> searchResults = null;
		String queryStr = MgnlContext.getParameter("queryProductsStr");
		if (null != queryStr) {
			queryStr = queryStr.trim();
			if (!queryStr.isEmpty()) {
				searchResults = ShopProductAccesor.getProductsByFulltext(queryStr);
			}
		}
		return searchResults;
	}
Generated at Mon Feb 12 07:09:35 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.