Resolving Error in Filter Parameters Due to Special Characters
TLDR Andrew encountered an error with filter parameters, suspecting it was due to many filters. Kishore Nallan pointed out the presence of parentheses may confuse the parser and suggested wrapping the string with backticks, which solved the issue. Andrew then asked about the potential impact of large filters on the cluster.
Jan 03, 2023 (11 months ago)
Andrew
03:59 AM
String ignore = StaticTSStrings.setBlockedUsers(user);
String similar = StaticTSStrings.setSimilarUsers(user);
final search = {
'searches': [
{
'collection': 'users',
'q': '*',
'query_by': 'name',
'page': '1',
'per_page': '10',
'sort_by': 'votes:desc',
'filter_by': '($ignore) && ($similar) && finishedOnboarding:true'
}
]
};
The part that causes a problem is the $similar. Basically, it is a string formed from the following (apologies for the gross code):
static String setSimilarUsers(User user) {
String similar = '';
if (user.firstUndergrad != '') {
similar += 'firstUndergrad:${user.firstUndergrad} || ';
}
if (user.secondUndergrad != '') {
similar += 'secondUndergrad:${user.secondUndergrad} || ';
}
if (user.thirdUndergrad != '') {
similar += 'thirdUndergrad:${user.thirdUndergrad} || ';
}
if (user.postGrad != '') {
similar += 'postGrad:${user.postGrad} || ';
}
if (user.firstStudentOrg != '') {
similar += 'firstStudentOrg:${user.firstStudentOrg} || ';
}
if (user.secondStudentOrg != '') {
similar += 'secondStudentOrg:${user.secondStudentOrg} || ';
}
if (user.thirdStudentOrg != '') {
similar += 'thirdStudentOrg:${user.thirdStudentOrg} || ';
}
if (user.fraternity != '') {
similar += 'fraternity:!=\'\' || ';
}
if (user.favoriteBar != '') {
similar += 'favoriteBar:${user.favoriteBar} || ';
}
if (user.favoriteSpot != '') {
similar += 'favoriteSpot:${user.favoriteSpot} || ';
}
if (user.assosiatedDorm != '') {
similar += 'assosiatedDorm:${user.assosiatedDorm} || ';
}
if (user.worstDorm != '') {
similar += 'worstDorm:${user.worstDorm} || ';
}
if (user.intramuralSport != '') {
similar += 'intramuralSport:${user.intramuralSport} || ';
}
//remove the last ' || ' if the string is not ''
if (similar != '') {
similar = similar.substring(0, similar.length - 4);
}
return similar;
}
What this can end up producing is a single string that looks like:
firstUndergrad:Accounting || firstStudentOrg:Horticulture Club || fraternity:!='' || favoriteBar:House Parties(South Park) || favoriteSpot:None
and somewhere in that String, an error is being made. Specifically error code 400, '"error" -> "Could not parse the filter query."'. Am i doing something wrong?
Kishore Nallan
04:04 AMKishore Nallan
04:06 AM(
in the filter value. The parantheses are used for nested filter expressions, so the parser might be getting confused.Kishore Nallan
04:06 AMfavoriteBar:`House Parties(South Park)`
Andrew
07:57 PMTypesense
Indexed 3015 threads (79% resolved)
Similar Threads
Phrase Search Relevancy and Weights Fix
Jan reported an issue with phrase search relevancy using Typesense Instantsearch Adapter. The problem occurred when searching phrases with double quotes. The team identified the issue to be related to weights and implemented a fix, improving the search results.
Fixing Multiple Document Retrieval in Typesense
Phil needed an efficient way to retrieve multiple documents by id. Kishore Nallan proposed a solution available in a pre-release build. After some bug fixing regarding id matching by Jason and Kishore Nallan, Phil successfully tested the solution.
Issue with Typo Correction/Prefix Search and the Role of max_candidates
John noticed inconsistent search results based on max_candidates settings, and Kishore Nallan clarified its role for multi-word queries. They resolved that increasing max_candidates ensures the query isn't prematurely limited.