Skip to content
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

Add the new fullTextSearch method with the associated tests. #470

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions src/ParseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -1032,37 +1032,37 @@ export default class ParseQuery {
return this._addCondition(key, '$geoIntersects', { '$point': point });
}

/**
* Method to find by full text.
* The key and the search fields are required the others are optionals.
* @method fullTextSearch
* @param {String} key The key to structure the where query
* @param {String} search The string to search
* @param {String} language Determine the list of stop words
* @param {Boolean} caseSensitive Dis/en-able the case sensitive search
* @param {Boolean} diacriticSensitive Dis/en-able diacritic sensitive search
* @return {Parse.Query} Returns the query, so you can chain this call.
*/
fullTextSearch(key: string, search: string, language: string, caseSensitive: boolean, diacriticSensitive: boolean): ParseQuery {
if (typeof key === 'undefined' || !key) {
throw new Error('A key is required.');
}
if (typeof search === 'undefined' || !search) {
throw new Error('You have to add one string to search.');
}
var options = { '$term': search };
if (typeof language !== "undefined" || language !== null) {
options['$language'] = language;
}
if (typeof caseSensitive !== "undefined" || caseSensitive !== null) {
options['$caseSensitive'] = caseSensitive;
}
if (typeof diacriticSensitive !== "undefined" || diacriticSensitive !== null) {
options['$diacriticSensitive'] = diacriticSensitive;
}
return this._addCondition(key, '$text', { '$search': options });
}
/**
* Method to find by full text.
* The key and the search fields are required the others are optionals.
* @method fullTextSearch
* @param {String} key The key to structure the where query
* @param {String} search The string to search
* @param {String} language Determine the list of stop words
* @param {Boolean} caseSensitive Dis/en-able the case sensitive search
* @param {Boolean} diacriticSensitive Dis/en-able diacritic sensitive search
* @return {Parse.Query} Returns the query, so you can chain this call.
*/
fullTextSearch(key: string, search: string, language: string, caseSensitive: boolean, diacriticSensitive: boolean): ParseQuery {
if (!key) {
throw new Error('A key is required.');
}
if (typeof search !== 'string') {
throw new Error('The value being searched for must be a string.');
}
var options = { '$term': search };
if (typeof language === 'string') {
options['$language'] = language;
}
if (typeof caseSensitive === "boolean") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should wrap "boolean" with single quotes like the ones above.

options['$caseSensitive'] = caseSensitive;
}
if (typeof diacriticSensitive === "boolean") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here as above

options['$diacriticSensitive'] = diacriticSensitive;
}
return this._addCondition(key, '$text', { '$search': options });
}

/** Query Orderings **/

/**
Expand Down