Parse Or Regex Query Gives Geoquery Error - regex

I am using a Parse OR query to find user matches based on regex and emails within an array. The regex can be quite long as I am generating it from names in the user's address book. My code is below:
PFQuery *emailQuery = [WPUser query];
[emailQuery whereKey:#"email" containedIn:emails];
PFQuery *nameQuery = [WPUser query];
[nameQuery whereKey:#"name" matchesRegex:regex modifiers:#"i"];
PFQuery *query = [PFQuery orQueryWithSubqueries:#[emailQuery, nameQuery]];
[query whereKey:#"objectId" notEqualTo:[WPUser currentUser].objectId];
[query whereKeyExists:#"signedUp"];
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
self.registeredContacts = objects;
BLOCK_ON_MAINTHREAD()
}];
The regex format is (^First.*Last$)|(^First.*Last$) etc. for each name in the address book. I use the i modifier to make it case insensitive.
However, I get a weird error with this query and it seems to have only begun recently: [Error]: geo query within or is not supported (Code: 102, Version: 1.14.2). I am not adding any geo constraints to this query as you can see. If my regex somehow causing Parse to add a geoquery? If I comment out the line of matchesRegex:modifiers: then the query returns as normal...however I am obviously losing the functionality I need.
I do not have symbols or anything as I am also validating names with an NSCharacterSet.
NSMutableCharacterSet *validCharacters = [NSMutableCharacterSet letterCharacterSet];
[validCharacters formUnionWithCharacterSet:[NSCharacterSet whitespaceCharacterSet]];
Why is Parse giving me an error that has no relation to my actual query? If it is related to my regex, any ideas on avoiding it?

I have some Chinese names in my address book and for some reason these names were causing the error I added a line in checking my regex to skip these names and the error is gone.
For reference I added a BOOL check:
BOOL isLatin = [regexName canBeConvertedToEncoding:NSISOLatin1StringEncoding];

Related

How can I fix this error in my go project - undefined: bson.RegEx

I get the following error from my editor:
undefined: bson.RegEx
due to this line of code in my go project:
regex := bson.M{"$regex": bson.RegEx{Pattern: id, Options: "i"}}
Why am I getting this error and how can I resolve it?
I've made sure that I'm importing:
"go.mongdb.org/mongo-driver/bson"
I've also checked inside bson/primitive/primitive.go to see that RegEx does exist
Using version 1.1.0 of mongo-driver.
Managed to work around the problem by removing this:
regex := bson.M{"$regex": bson.RegEx{Pattern: id, Options: "i"}}
and add this instead:
regex := `(?i).*` + name + `.*`
filter = bson.M{"name": bson.M{"$regex": regex}}
Why am I getting this error and how can I resolve it?
Using mongo-go-driver v1+, you can utilise bson.primitive. For example:
patternName := `.*` + name + `.*`
filter := bson.M{"name": primitive.Regex{Pattern: patternName, Options:"i"}}
cursor, err := collection.Find(context.TODO(), filter)
This is imported from "go.mongodb.org/mongo-driver/bson/primitive".
In addition, I would also suggest to consider the search pattern. You can optimise a regex search if the regular expression is a “prefix expression”, which means that all potential matches start with the same string. For example, ^name.* will be optimised by matching only against the values from the index that starts with name.
Also worth noting that case insensitive regular expression queries generally cannot use indexes effectively. The $regex implementation is not collation-aware and is unable to utilise case-insensitive indexes. Please see $regex index use for more information.
Depending on the use case, consider MongoDB Text Search. For example, you can create a text index:
db.collection.createIndex({"name":"text"});
Which then you can search using:
filter := bson.M{"$text": bson.M{"$search": name}}
cur, err := collection.Find(context.TODO(), filter)
Also worth mentioning depending on your requirements, there's also MongoDB Atlas Full Text Search feature for advanced search functionality. i.e. text analysers.

Unparsable MOF Query When Trying to Register Event

Update 2
I accepted an answer and asked a different question elsewhere, where I am still trying to get to the bottom of this.
I don't think that one-lining this query is the answer, as I am still not getting the required results (and multi-lining queries is allowed in .mof, as shown in the URLs in comments to the answer ...
Update
I rewrote the query as a one-liner as suggested, but still got the same error! As it was still talking about lines 11-19 I knew there must be another issue. After saving a new file with the change, I reran mofcomp and it appears to have loaded, but the event which I have subscribed to simply does not work.
I really feel that there is not enough documentation on this topic and it is hard to work out how I am meant to debug this - any help on this would be much appreciated, even if this means using a different more appropriate method.
I have the following .mof file, which I would like to use to register an event on my system :
#pragma namespace("\\\\.\\root\\subscription")
instance of __EventFilter as $EventFilter
{
Name = "Event Filter Instance Name";
Query = "Select * from __InstanceCreationEvent within 1 "
"where targetInstance isa \"Cim_DirectoryContainsFile\" "
"and targetInstance.GroupComponent = \"Win32_Directory.Name=\"c:\\\\test\"\"";
QueryLanguage = "WQL";
EventNamespace = "Root\\Cimv2";
};
instance of ActiveScriptEventConsumer as $Consumer
{
Name = "TestConsumer";
ScriptingEngine = "VBScript";
ScriptText =
"Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
"Set objFile = objFSO.OpenTextFile(\"c:\\test\\Log.txt\", 8, True)\n"
"objFile.WriteLine Time & \" \" & \" File Created\"\n"
"objFile.Close\n";
// Specify any other relevant properties.
};
instance of __FilterToConsumerBinding
{
Filter = $EventFilter;
Consumer = $Consumer;
};
But whenever I run the command mfcomp myfile.mof I am getting this error:
Parsing MOF file: myfile.mof
MOF file has been successfully parsed
Storing data in the repository...
An error occurred while processing item 1 defined on lines 11 - 19 in file myfile.mof:
Error Number: 0x80041058, Facility: WMI
Description: Unparsable query.
Compiler returned error 0x80041058
This error appears to be caused by incorrect syntax in the query, but I don't understand where I have gone wrong with this - is anyone able to advise?
There are no string concatenation or line continuation characters being used in building "Query". To keep it simple, you could put the entire query on one line.

R: Countrycode package not supporting regex as the origin

I have a list of countries that i need to convert into standardized format (iso3c). Some have long names, others have 2 or 3 digit codes, and others do not display the whole country name like "Africa" instead of "South Africa". Ive done some research and come up to use countrycode package in R. However, when i tried to use "regex" R doesnt seem to recognize it. Im getting the error below:
> countrycode(data,"regex","iso3c", warn = TRUE)
Error in countrycode(data, "regex", "iso3c", :
Origin code not supported
Any other option I need to do?
Thanks!
You can view the README for the countrycode package here https://github.com/vincentarelbundock/countrycode, or you can pull up the help file in R by entering this into your R console ?countrycode::countrycode.
"regex" is not a valid 'origin' value (2nd argument in the countrycode() function). You must use one of "cowc", "cown", "eurostat", "fao", "fips105", "imf", "ioc", "iso2c", "iso3c", "iso3n", "p4_ccode", "p4_scode", "un", "wb", "wb_api2c", "wb_api3c", "wvs", "country.name", "country.name.de" (using latest version 0.19).
If you use either of the following 'origin' values, regex matching will be performed automatically: "country.name" or "country.name.de"
If you're using a custom dictionary with the new (as of version 0.19) custom_dict argument, you must set the origin_regex argument to TRUE for regex matching to occur.
In your example, this should do what you want:
countrycode(data, origin = "country.name", destination = "iso3c", warn = TRUE)

Pgocaml customizing sql queries

I am trying to write a query that simply drops a table.
let drop_table dbh table_name =
let query = String.concat " " ["drop table"; table_name] in
PGSQL(dbh) query
I am receiving the following error from the query
File "save.ml", line 37, characters 10-11:
Parse error: STRING _ expected after ")" (in [expr])
File "save.ml", line 1:
Error: Preprocessor error
Why am I getting this error? It appears that this function is valid Ocaml syntax.
Thanks guys!
You cannot construct query when using PG'OCaml's syntax extension. You must provide a literal string. This is the tradeoff for getting PG'Ocaml's compile time query validation. If query could be any OCaml expression, PG'OCaml wouldn't know how to validate it at compile time.
Personally, I've stopped using the syntax extension completely. My feeling is it doesn't scale to large projects. Instead I call prepare and execute directly. For example, this function will create a new database connection (assuming the connection parameters are previously defined), run the given query, and close the connection:
let exec query =
let db = PGOCaml.connect ~host ~user ~database ~port ~password ()
PGOCaml.prepare db ~query ();
let ans = PGOCaml.execute db ~params:[] () in
PGOCaml.close db;
ans
Of course, this isn't a robust implementation and shouldn't be used in production code. It doesn't handle errors and isn't asynchronous.

Sitecore Fast Query Gives Parse Exception

Why am I getting this error with the code below ParseException: End of string expected at position 4.
Here's the code: The error is on the 3rd line.
var db = Sitecore.Configuration.Factory.GetDatabase("web");
string query = #"fast:/sitecore/content/foodservice/home/Products/3492-5326/3518-7";
Item item = db.SelectSingleItem(query);
return item;
Can we use a fast query with SelectSingleItem()? I was trying to avoid the get folder contents and loop through each item until I find the target solution. Suggestions?
When using Sitecore Query, you need to escape item names with dashes. From SDN:
Items with dashes in names (“-”) should be included in “#” symbols. Please use such syntax: /sitecore/content/Home/#About-us#. Otherwise you may get the following error: Invalid lookup source "/sitecore/content/TestSiteB/Home/About-us": End of string expected at position 38. Also, an item name should be included in “#” symbols if it contains “and” or “or” word and is used before “//” symbols. For example: "/sitecore/content/Home/#news and events#//".
UPDATE:
I have confirmed that this applies to Fast Query as well.
End of string expected at position 27.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Sitecore.Data.Query.ParseException: End of string expected at position 27.
Source Error:
Line 21: protected void Page_Load(object sender, EventArgs e)
Line 22: {
Line 23: Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/Test-Item");
Line 24:
Line 25: Model = Sitecore.Context.Item;
The same code runs fine with #escapes#:
Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/#Test-Item#");
This is a bug when using Fast Query and SelectSingleItem(). The issue is fixed in the Sitecore CMS 6.3.0 rev.100716 release. See Release Notes. Since we are using 6.2, I had to rewrite my method to use a Sitecore Query instead of the Fast Query.