Skip to content

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

Merged
merged 14 commits into from
Jul 4, 2018
Merged

Conversation

danielbm
Copy link
Contributor

This PR adds the support for options on the full text search, namely: $caseSensitive, $language and $diacriticSensitive.

@codecov
Copy link

codecov bot commented May 22, 2018

Codecov Report

Merging #573 into master will increase coverage by <.01%.
The diff coverage is 89.65%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/ParseQuery.js 93.8% <89.65%> (-0.43%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update acdb645...249edb1. Read the comment docs.

@dplewis
Copy link
Member

dplewis commented May 22, 2018

@flovilmart Can you take a look at travis?

@flovilmart
Copy link
Contributor

@dplewis seems that integration tests are failing. Not sure why or if we broke something else.

@dplewis
Copy link
Member

dplewis commented May 22, 2018

@flovilmart Thanks for fixing the tests

@flovilmart
Copy link
Contributor

NP!

* @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 {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Member

@dplewis dplewis May 22, 2018

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)?

Copy link
Contributor Author

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;
      }
    }

Copy link
Member

@dplewis dplewis May 23, 2018

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?

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Sweet!

Copy link
Contributor Author

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.

@dplewis
Copy link
Member

dplewis commented May 23, 2018

@flovilmart is there an easy way to view generated docs for a PR without pulling it down?

@flovilmart
Copy link
Contributor

Not really ;/ you’ll have to pull it

@dplewis
Copy link
Member

dplewis commented May 23, 2018

@flovilmart I think the CONTRIBUTION.md looks outdated. Doesn’t say how to run those unit jest test, integration test, generate docs, etc.

@flovilmart
Copy link
Contributor

@dplewis you're right ;) we need to do somethings about that

Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

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

A few nits

}
}

if (options && options.hasOwnProperty('$diacriticSensitive')) {
Copy link
Member

@dplewis dplewis May 23, 2018

Choose a reason for hiding this comment

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

Remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops =|

@@ -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" });
Copy link
Member

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

* @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
Copy link
Member

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

Copy link
Contributor Author

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.
  */

Copy link
Member

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 {
Copy link
Member

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

Copy link
Contributor Author

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.

});
});

it('can perform a full text search with case sensistive options', (done) => {
Copy link
Member

Choose a reason for hiding this comment

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

*case sensitive

q.fullText('comment', 'preparar', { language: "portuguese" });
return q.find();
}).then((results) => {
assert.equal(results.length, 4);
Copy link
Member

@dplewis dplewis May 24, 2018

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();
});

}
Parse.Object.saveAll(objects).then(() => {
const q = new Parse.Query(TestObject);
q.fullText('comment', 'Preparar', { language: "portuguese", caseSensistive: true });
Copy link
Member

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.

@dplewis
Copy link
Member

dplewis commented May 24, 2018

@danielbm I added a few more comments on your test cases

@cleever
Copy link

cleever commented Jun 26, 2018

Any news on this?

@danielbm
Copy link
Contributor Author

danielbm commented Jun 26, 2018

@cleever Not really. I'm just having difficulties to find time to fix this PR.

@dplewis
Copy link
Member

dplewis commented Jun 26, 2018

@danielbm I can finish off this PR for you, if thats cool.

@danielbm
Copy link
Contributor Author

@dplewis Sure! Feel free to do it!

dplewis added 2 commits June 30, 2018 17:32
Indexes don't get deleted between tests so new classes are created as a workaround. Also I can't seem to use language options with case sensitive or diacritic sensitive
@dplewis dplewis closed this Jul 4, 2018
@dplewis dplewis reopened this Jul 4, 2018
@flovilmart
Copy link
Contributor

@dplewis where are we at on this one?

@dplewis
Copy link
Member

dplewis commented Jul 4, 2018

@danielbm how does this look?

Copy link
Contributor

@flovilmart flovilmart left a comment

Choose a reason for hiding this comment

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

LGTM too

@dplewis dplewis merged commit de4bc1c into parse-community:master Jul 4, 2018
@danielbm
Copy link
Contributor Author

danielbm commented Jul 4, 2018

@dplewis @flovilmart thanks!

@flovilmart
Copy link
Contributor

Thanks @danielbm for getting it started!

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.

4 participants