Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Fixed bug when commas are inside queries #31

Closed
wants to merge 1 commit into from
Closed

Fixed bug when commas are inside queries #31

wants to merge 1 commit into from

Conversation

BastianKubaile
Copy link
Contributor

Fixes #28. The idea is from @tmokenc, but his solution wasn't bug free. This code should work.

req_q.split(',').forEach(i => (q[i.split(':')[0]] = i.split(':')[1]));
req_q.split(',')
.reduce((acc, curr) => {
curr.includes(":") ? acc.push(curr) : acc[acc.length - 1] += ("," + curr);
Copy link
Contributor

Choose a reason for hiding this comment

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

This may just be my personal opinion or preference, but I would like to see an explanation for this logic, so other contributors don't need to reverse engineer it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's say the query is name:Hello, Jsonbox,age:>15. Normally, this would be split up into this array ["name:Hello", "Jsonbox", "age:>15" ]. This isn't the right array and the reduce function solves this, by iterating over the false array. If the element in the array includes a :, the reduce function leaves it untouched, otherwise the reduce function appends the element to the previous one.
Dunno what's so hard to understand about it, much of the codebase is written in similiar way without any comments.

@vasanthv
Copy link
Owner

vasanthv commented Oct 1, 2019

@BastianKubaile Now it will still be not working if we want to search a string with :. Need to figure out if there is a better way to handle it.

@vasanthv vasanthv closed this Mar 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Find records contains a comma
3 participants