Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: hashpath -> hash path

...

The query() operator can be used to search structured persistent variables. The syntax is

Code Block
languagejavascript
themeConfluencelanguagejavascript
<persistent variable>.query(<hashpath><hash path>, {
  'requires' : <join operator>,
  'conditions : [
     { 'search_key' : <path_to_field>,
       'operator' : <mongo $ comparison op>,
       'value' : <value> },
     ...
  ]
  },| <extended result>
  );

<hashpath> <hash path> will be the empty array, [], if the key is at root.

search_key is the path from the <hashpath> <hash path> to the field that you want to compare.  If that path does not exist for an entry, it will not be considered even as a null

...

For example to do a twitter timeline search where the entries have been assigned a unique key to transform the array into a hash:

Code Block
languagejavascript
themeConfluence
languagejavascript
ent:tweets.query([],{
  'requires' :  '$and', 
  'conditions'   : [
    {
      'search_key' : ['retweeted_status', 'favorite_count'],
      'operator' : '$gt',
      'value' : 5
    },
    {
      'search_key' : ['retweeted_status', 'favorite_count'],
      'operator' : '$lt',
      'value' : 200
    }
  ]})

This will return an array of <hashpaths> <hash paths> (array of arrays) that is essentially an array of the keys to the matching values

Code Block
languagejavascript
themeConfluencelanguagejavascript
[
   [     'a32'   ],
   [     'a31'   ],
   [     'a30'   ]
]

...

The following function from Fuse uses query() to return trips by their end date, given a start and end date. 

Code Block
languagejavascript
themeConfluencelanguagejavascript
trips = function(start, end){
  utc_start = common:convertToUTC(start);
  utc_end = common:convertToUTC(end);
      
  ent:trip_summaries.query([], 
      { 
       'requires' : '$and',
       'conditions' : [
          { 
     	   'search_key' : [ 'endWaypoint', 'timestamp'],
       	   'operator' : '$gte',
       	   'value' : utc_start 
	      },
     	  {
       	   'search_key' : [ 'endWaypoint', 'timestamp' ],
       	   'operator' : '$lte',
       	   'value' : utc_end 
	      }
	   ]},
	"return_values"
  )
};

...