Skip to content

Conversation

@Delicious-Bacon
Copy link
Contributor

@Delicious-Bacon Delicious-Bacon commented May 31, 2025

Problem

Currently the SQL parser errors when fuzzy=1 option is used with a defined table name (secondary option) like this:

SELECT * FROM authors
JOIN books
WHERE MATCH('john', authors) -- sql parser does not check for table name option
OPTIONS fuzzy=1;

A query like that returns The 'fuzzy' option requires a full-text query.

This should be supported as per Searching > Full text matching > Basic usage#MATCH | Manticore Search Manual.

On the other hand, the docs also mention it's an optional instruction in the MATCH clause (that it will default to the left table), but when I try to run the query without the table I gen an error message no such table ''.

Solution

Add an optional group match seeking table name in the regex pattern:
/MATCH\s*\(\'(.*?)\'(\s*,\s*\w*?)?\s*\)/ius.

This is later also checked and passed to the returning sprintf in getQueriesSQLRequest.

Side notes

I have modified an ambiguous message The 'fuzzy' option requires a full-text query. to provide details on what is needed in the query Use: MATCH('search query') or MATCH('search query', table_name).

I have added a check when table name in MATCH is missing, but there is a comma (,) in the clause:

		$searchTableName = $matches[2] ?? null;
		if (isset($searchTableName) && trim($searchTableName) === ',') {
			throw QueryParseError::create(
				"MATCH() clause has a trailing comma but table name is not defined. " .
					"Did you mean to specify a table? Eample: MATCH('search query', table_name)"
				);
		}

Let me know if this seems OK.

@sanikolaev
Copy link
Collaborator

Thanks for the PR @Delicious-Bacon !

@donhardman please review.

Copy link
Collaborator

@donhardman donhardman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like all good, but let's follow code style and fix CI issues.

You can run locally bin/codestyle and bin/codeanalyze to make sure ALL tests pass.

@Delicious-Bacon
Copy link
Contributor Author

I ran the codestyle, then codestyle-fix, codeanalyze and test. Everything looks clean.

My composer install/update updated the composer.lock so be sure to check or drop that.

@sanikolaev sanikolaev requested a review from donhardman June 9, 2025 03:29
Copy link
Collaborator

@donhardman donhardman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, thanks a lot for your pull request and great work.

@donhardman donhardman changed the base branch from main to fork/merge August 25, 2025 04:37
@donhardman donhardman merged commit 80fe1ad into manticoresoftware:fork/merge Aug 25, 2025
12 of 14 checks passed
donhardman added a commit that referenced this pull request Aug 25, 2025
* feat: update fuzzy search regex and error handling

* ran codestyle, codeanalyze, test

---------

Co-authored-by: Don Hardman <[email protected]>
sanikolaev pushed a commit to manticoresoftware/manticoresearch that referenced this pull request Aug 28, 2025
This commit increases Buddy version in deps.txt to 3.35.0

Related PR manticoresoftware/manticoresearch-buddy#552
Related PR #3708
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants