-
-
Notifications
You must be signed in to change notification settings - Fork 597
Add options to full text search #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## master #573 +/- ##
==========================================
+ Coverage 84.57% 84.57% +<.01%
==========================================
Files 48 48
Lines 4019 4039 +20
Branches 906 911 +5
==========================================
+ Hits 3399 3416 +17
- Misses 620 623 +3
Continue to review full report at Codecov.
|
@flovilmart Can you take a look at travis? |
@dplewis seems that integration tests are failing. Not sure why or if we broke something else. |
@flovilmart Thanks for fixing the tests |
NP! |
src/ParseQuery.js
Outdated
* @return {Parse.Query} Returns the query, so you can chain this call. | ||
*/ | ||
fullText(key: string, value: string): ParseQuery { | ||
fullText(key: string, value: string, options: ?Object): ParseQuery { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add something similar to other functions that use options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean something like this for every option.
var fullOptions = {};
if (options.hasOwnProperty('language')) {
fullOptions.$language = options.language;
}
Can you also write a test case for $caseSensitive, $diacriticSensitive, and options.unknown (this might throw an error)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this code would do the trick?
options = options || {};
var fullOptions = {};
for (var key in options) {
switch (key) {
case '$language':
fullOptions.$language = options[key];
break;
case '$caseSensitive':
fullOptions.$caseSensitive = options[key];
break;
case '$diacriticSensitive':
fullOptions.$diacriticSensitive = options[key];
break;
default:
throw new Error('Unknown option: ' + key);
break;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should do the trick. Also I don't think we should have the $
in the options getting passed in. $ is an internal thing. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielbm Can you write the test cases first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed a bit verbose to me too, but doing the validation for the three options separately, plus the validation for unknown options was also. As per the $
, I totally agree. I'll remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dplewis I just pushed the code with the options validations, more test cases.
@flovilmart is there an easy way to view generated docs for a PR without pulling it down? |
Not really ;/ you’ll have to pull it |
@flovilmart I think the CONTRIBUTION.md looks outdated. Doesn’t say how to run those unit jest test, integration test, generate docs, etc. |
@dplewis you're right ;) we need to do somethings about that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits
src/ParseQuery.js
Outdated
} | ||
} | ||
|
||
if (options && options.hasOwnProperty('$diacriticSensitive')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops =|
src/ParseQuery.js
Outdated
@@ -993,7 +993,7 @@ class ParseQuery { | |||
* | |||
* In order to sort you must use select and ascending ($score is required) | |||
* <pre> | |||
* query.fullText('term'); | |||
* query.fullText('field', 'term', { $language: "spanish" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For documentation purposes leave an example of with and w/o options.
Docs are auto generated by using npm run docs
. Use it to check your formatting.
$language
is now language
src/ParseQuery.js
Outdated
* @param {Object} options (Optional) See https://docs.mongodb.com/manual/reference/operator/query/text/#text-query-operator-behavior | ||
* @param {String} options.language | ||
* @param {String} options.caseSensitive | ||
* @param {String} options.diacriticSensitive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diacritic and case are Boolean type. What happens if they aren't boolean 🤔?
Instead of the mongo docs, put a summary next to the options for readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this?
/**
* Adds a constraint for finding string values that contain a provided
* string. This may be slow for large datasets. Requires Parse-Server > 2.5.0
*
* In order to sort you must use select and ascending ($score is required)
* <pre>
* query.fullText('field', 'term');
* query.ascending('$score');
* query.select('$score');
* </pre>
*
* To retrieve the weight / rank
* <pre>
* object->get('score');
* </pre>
*
* You can define optionals by providing an object as a third parameter
* <pre>
* query.fullText('field', 'term', { language: "spanish", diacriticSensitive: true });
* </pre>
*
* @param {String} key The key that the string to match is stored in.
* @param {String} value The string to search
* @param {Object} options (Optional) See https://docs.mongodb.com/manual/reference/operator/query/text/#text
* @param {String} options.language The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer.
* @param {Boolean} options.caseSensitive A boolean flag to enable or disable case sensitive search.
* @param {Boolean} options.diacriticSensitive A boolean flag to enable or disable diacritic sensitive search.
* @return {Parse.Query} Returns the query, so you can chain this call.
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
|
||
return this._addCondition(key, '$text', { $search: { $term: value } }); | ||
} | ||
fullText(key: string, value: string, options: ?Object): ParseQuery { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is indented improperly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it was indented improperly before, and I fixed it.
integration/test/ParseQueryTest.js
Outdated
}); | ||
}); | ||
|
||
it('can perform a full text search with case sensistive options', (done) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*case sensitive
integration/test/ParseQueryTest.js
Outdated
q.fullText('comment', 'preparar', { language: "portuguese" }); | ||
return q.find(); | ||
}).then((results) => { | ||
assert.equal(results.length, 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write this like? It kinda confusing in the tests.
}).then((results) => {
assert.equal(results.length, 4);
done();
});
integration/test/ParseQueryTest.js
Outdated
} | ||
Parse.Object.saveAll(objects).then(() => { | ||
const q = new Parse.Query(TestObject); | ||
q.fullText('comment', 'Preparar', { language: "portuguese", caseSensistive: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how this test is passing when caseSensistive
is spelled wrong.
@danielbm I added a few more comments on your test cases |
Any news on this? |
@cleever Not really. I'm just having difficulties to find time to fix this PR. |
@danielbm I can finish off this PR for you, if thats cool. |
@dplewis Sure! Feel free to do it! |
@dplewis where are we at on this one? |
@danielbm how does this look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM too
@dplewis @flovilmart thanks! |
Thanks @danielbm for getting it started! |
This PR adds the support for options on the full text search, namely: $caseSensitive, $language and $diacriticSensitive.