0

How can I count a phrase instances in a field using OrientDB?

Let's say I have the following data:

Display_title | Description
My_data_12 | The quick brown fox jumps over the lazy dog
My_data_13 | The one

How can I count the number of 'the' instances, output similar to this:

Display_title | Count
My_data_12 | 2
My_data_13 | 1

Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
  • if you are using java this could be useful http://stackoverflow.com/questions/275944/how-do-i-count-the-number-of-occurrences-of-a-char-in-a-string – Ivan Mainetti May 10 '16 at 14:48
  • look at this http://stackoverflow.com/questions/4009756/how-to-count-string-occurrence-in-string – Ivan Mainetti May 10 '16 at 14:49
  • @IvanMainetti thanks but I'm looking for OrientDB SQL query/function, not using external language or module for it – Dor Cohen May 10 '16 at 14:50

1 Answers1

2

using @Vitim.us answer from here

screenshot

you can call it from studio with

select title, occurrences(@this.description, "the") from v

NOTE that this is case sensitive, so with your example you'll get:

 title      | occurrences
 My_data_12 | 1
 My_data_13 | 0 
Community
  • 1
  • 1
Ivan Mainetti
  • 1,982
  • 7
  • 13