Generate a random string using ArangoDB's AQL? - arangodb

Using AQL (preferably in the ArangoDB WebUI), is it possible to generate a random string or letters and numbers similar to this: 4EKH5G3AN6HH?
If not, what is another way to do it without doing it in application code?

https://docs.arangodb.com/3.0/AQL/Functions/String.html#randomtoken
RANDOM_TOKEN(8) // "zGl09z42"
then you can apply https://docs.arangodb.com/3.0/AQL/Functions/String.html#upper
UPPER(RANDOM_TOKEN(8)) // "ZGL09Z42"

Great answer from sevcik.tk
Just in case, you can generate documents full of random data like that:
FOR i IN 1..300000
INSERT {
code: CONCAT("t", i),
name: RANDOM_TOKEN(32),
article1: RANDOM_TOKEN(10),
article2: RANDOM_TOKEN(20)
} IN batchtest
And there is link to useful functions:
https://www.arangodb.com/docs/stable/aql/functions-string.html#random_token

Related

Chaining filters in JMESpath

I want to be able to chain together multiple filters using JMESpath but it appears you cannot filter on the output of a filter.
My working example is as follows:
// document:
{
pips: {
ancestors:[{
id: 'p01234567'
}],
episode: {
more: 'data',
goes: 'here
}
}
}
// working filter: `[pips][?ancestors[?pid=='p01234567'] && episode]`
But I would like to write my filter instead as follows, effectively to filter the output of another filter:
[pips][?ancestors[?pid=='p01234567']][?episode]
Any idea why this doesn't work?
I am building this in NodeJS using the following NPM package: https://www.npmjs.com/package/jmespath
Is there a mistake in the syntax I am using, is there a bug in the library I am using, or am I just trying to do something that is outside what JMESpath allows?
Thank you!
I found the reason why - projections are evaluated in two steps, with the left-hand-side creating a JSON array of initial values and the right-hand-side is the expression.
Solution: "Pipe expressions" which allow you to"operate on the result of a projection".
So instead of the incorrect expression from before: [pips][?ancestors[?pid=='p01234567']][?episode]
This instead should be written as: [pips][?ancestors[?pid=='p01234567']] | [?episode]
And to undo the conversion of the initial document into an array, we can convert this back to an object like this: [pips][?ancestors[?pid=='p01234567']] | [?episode] | [0]
As a side note, I observed that using parentheses () also works, but using pipes are a bit cleaner.

Gradle: How to filter and search through text?

I'm fairly new to gradle. How do I filter text in the following manner?
Pretend that the output/result I want to filter will be the two URLs below.
"http://localhost/artifactory/appNameIwant/moreStuffHereThatsDynamic"
> I want this URL
"http://localhost/artifactory/differentAppName"
> I don't want this URL
I want to put up a "match" variable that would be something like
variable = http://localhost/artifactory/appnameIwant
So essentially, the string will not be a perfect match. I want it to filter and provide back any URLs that start with the variable listed above. It cannot be a perfect match as the characters after the /appnameIwant/ will be changing.
I want to use a for loop to cycle through an array, with an if then statement to return any matches. For instance.
for (i=0; i < results.length; i++){
if (results[i] strings matches (http://localhost/artifactory/appnameIwant) {
return results[i] }
I am just filtering the URL strings themselves, not anything complicated inside the webpages.
Let me know if further explanation would be helpful.
Thanks so much for your time and help!
I figured it out - I just used
if (string.startsWith"texthere")) {println string}
A lot easier than I thought!

Is there a way to prevent partial word matching using Sitecore Search and Lucene?

Is there a way when using Sitecore Search and Lucene to not match partial words? For example when searching for "Bos" I would like to NOT match the word "Boston". Is there a way to require the entire word to match? Here is a code snippet. I am using FieldQuery.
bool _foundHits = false;
_index = SearchManager.GetIndex("product_version_index");
using (IndexSearchContext _searchContext = _index.CreateSearchContext())
{
QueryBase _query = new FieldQuery("title", txtProduct.Text.Trim());
SearchHits _hits = _searchContext.Search(_query, 1000);
...
}
You may want to try something like this to get the query you want to run. It will put the + in (indicating a required term) and quote the term, so it should exactly match what you're looking for, its worked for me. Providing you're passing in BooleanClause.Occur.MUST.
protected BooleanQuery GetBooleanQuery(string fieldName, string term, BooleanClause.Occur occur)
{
QueryParser parser = new QueryParser(fieldName, new StandardAnalyzer());
BooleanQuery query = new BooleanQuery();
query.Add(parser.Parse(term), occur);
return query;
}
Essentially so your query ends up being parsed to +title:"Bos", you could also download Luke and play around with the query syntax in there, its easier if you know what the syntax should be and then work backwards to see what query objects will generate that.
You have to place the query in double quotes for the exact match results. Lucene supports many such opertators and boolean parameters that can be found here: http://lucene.apache.org/core/2_9_4/queryparsersyntax.html
It depends on field type. If you have memo or text field then partial matching is applied. If you want exact matching use string field instead. There you can find some details: https://www.cmsbestpractices.com/bug-how-to-fix-solr-exact-string-matching-with-sitecore/ .

mongodb, finding by coordinate + query

I'm building a web application over Node.js and MongoDB which is based on geolocated points.
The document is something like this:
{ name: ""
keywords: [Array of strings]
location: {lng: double, lat: double }
}
I am wondering how could I use find() to find documents that are near from a coordinate but, in addition, are coincident with any of he keywords in the keywords array.
Imagine that keywords are: ["restaurant", "bar", "coffee"]
I've looked into 2d Index, but the secondary index must be a string. It can't be an array of strings.
The problem is that a document could have more than one keyword (or category) so I can't use a simple string to query them
How would you implement this?
Thanks!
What version of mongo? It looks like this was added in 2.4.0: SERVER-8457

How can I achieve fast and effective String compression in Actionscript 3?

I have an Object which stores pairs for a find and replace that I perform on up to 1500 Strings at a time.
The Object is populated with pairs using a method that will accept a String and then store this as a property with the value being an automatically assigned base 36 number, like this:
function addShort(long:String):void
{
_pairs[long] = _nextShort;
}
_nextShort returns an automatically incremented value being the subject of .toString(36), so running the above a few times might make _pairs look like this:
_pairs:Object = {
"class": "0",
"testing.objects.TestBlock": "1",
"skin.x": "2",
"skin.y": "3",
...........
"someString": "az1"
};
This Object could realistically end up being really large, having over a couple hundred pairs stored.
I then have a method that will take a "long" String (which will include the Strings I've given to addShort() previously) and return a new String where these have been replaced with their respective short value.
The method looks like this:
public function shorten(long:String):String
{
for(var i:String in _pairs)
long = long.split(i).join(_pairs[i]);
return long;
}
Nice an simple, however in my mind I foresee a massive problem in a case where I might want to "shorten" 2000+ Strings and the _pairs Object has at the same time has over 500 pairs.
That ends up being 1,000,000 iterations all up which obviously doesn't seem very efficient at all.
How can I improve this process significantly?
Based on comments from #kapep I realized what I needed is actually a compression library that will do this work for me.
I stumbled across an LZW compression class within a package called Calista which works great.
I did notice that the compression was really slow, which is understandable, but if there are any suggestions for something quicker I'm open to them.
How about Regular Expressions for replacing String patterns? Catch some code.

Resources