LIKE operator in XQL - sql

I am doing some XML parsing in webMethods which only supports XQL, not XPath/XQuery.
I'm trying to find the LIKE operator to do a wildcard search on an attribute value
/MAP[#MODE='INPUT']/MAPSET[#FIELD LIKE '/documentTypeName*']/DATA/Values/value
In XQuery, I was using the matches() function. Have been surprised at my lack of finding an answer through searching. My best bet was http://www.ibiblio.org/xql/xql-proposal.html which says it should be keyword contains but this doesn't seem correct.

Pretty much a necro, but i believe you are looking for 'icontains'.
http://www.ibiblio.org/xql/xql-proposal.html#Comparisons
Section 1.4.3 Comparisons. This should be a case insensitive version of 'contains'
(field icontains "/documentTypeName*")

Related

Find string that is not between specific html tag

I'm being required to use regular expressions to parse HTML. I do realize regular expressions are bad for HTML matching.
I would like to find a specific string and evaluate whether or not its between two strings.
In this example ® must be immediately between <sup> and </sup>
Example:
<sup>®</sup>
I believe this would involve using negative lookaheads and lookbehinds. My first thought would be:
(?<!<sup>)®(?!<\/sup>)
Unfortunately this fails as I don't believe you can do a lookahead and lookbehind in this combination.
Just using the negative-lookahead does work and is probably good enough for my purposes...
®(?!<\/sup>)
...but I'd like to know if it's possible to combine a lookahead and lookbehind in this way. Or is there another technique I should be using?
Thanks in advance
Your initial regex (i.e. (?<!<sup>)®(?!<\/sup>)) is correct, as demonstrated in the example usage at https://www.debuggex.com/r/WyY9y0Zq2Krz_3Xm
However, it works in Python and PCRE, but not in Javascript (you can check by choosing each of them in the dropdown). Javascript does not have negative lookbehind support.

ATK4 Quicksearch case-sensitive?

I'm using ATK4.2.4, I've got a grid with a QuickSearch but it appears to be case-sensitive. However, looking at the example here: http://agiletoolkit.org/codepad/gui/grid it does not behave case-sensitive.
I've tried feeding my grid from a model and directly through setSource, no difference.
Any clues on which direction to look for the cause and/or how to fix it?
QuickSearch is case sensitive (class QuickSearch method PostInit).
But in case you use MySQL for your model, then MySQL itself ignores string case for LIKE statements if correctly configured.
See here: How can I search (case-insensitive) in a column using LIKE wildcard?

VB.Net String comparison and Wildcard values

Is it possible to do String comparison where one of the strings I am comparing against has wild cards and is generally just for formatting purposes. For example
Dim correctFormat as String = "##-##-###-##"
Dim stringToCheck = someClass.SomeFunctionThatReturnsAStringToCheck
If FormatOf(CorrectFormat) = FormatOF(StringToCheck) then
Else
End if
I am aware of the made up FormatOf syntax, but I'm just using it to show what I am asking.
No need for regular expressions.
You can simply use the Like operator, which supports ?, * and # as wildcards and also character lists ([...], [!...])
So you simply change your code to:
If stringToCheck Like correctFormat Then
and it will work as expected.
The way is to use regular expressions - that's what they are for.
This is the regular expression that matches the format you have posted:
^\d{2}-\d{2}-\d{3}-\d{2}$
As the previous post mentioned, you should use regular expressions for that purpose - they are way better for that task.
Sadly, learning them can be confusing, especially finding bugs can be really annoying.
I really like http://www.regular-expressions.info/ and http://regexpal.com/ for building and testing regexes before.
In VB.net use something like reg.ismatch

JSON filter (like SQL SELECT)

I have a json file/stream, i like to be able to make select SQL style
so here is the file
the file contain all the data i have, I'll like to be able to show, let said :
all the : odeu_nom and odeu_desc that is : categorie=Feuilles
if you can do that with PHP and json (eval) fine... tell me how...
on the other part in sql i will do : SELECT * from $json where categorie=Feuilles
p.s. i have found : jsonpath that is a xpath for json... maybe another option ?
p.s. #2... with some research, i have found anoter option, the json is the same as a array, maybe I can filter the array and just return the one i need ?... how do i do that ?
It makes more sense to try and stick with XPath-style selectors (like jsonpath), rather than using SQL, even if you are more familiar with SQL.
The advantage of the "path" is that it is more readily expressive of the hierarchical structure implicit to XML/JSON, as opposed to SQL which requires using various joins to help it "get out of its rectangular/tabular prison".
Although I never used jsonpath, by reading its summary page, I believe that the following should produce all the odeu_nom for objects which catagorie is 'Feuilles' (given the json input referred in the question).
$.Liste_des_odeurs[?(#.categorie = 'Feuilles'].odeu_nom
which correspond to the following XPath
/Liste_des_odeurs[categorie='Feuilles']/odeu_nom
Et voila...
BTW, 'Jazz is not dead, it just smells funny' (F Zappa)

How to make Lucene match all words in query?

I am using Lucene to allow a user to search for words in a large number of documents. Lucene seems to default to returning all documents containing any of the words entered.
Is it possible to change this behaviour? I know that '+' can be use to force a term to be included but I would like to make that the default action.
Ideally I would like functionality similar to Google's: '-' to exclude words and "abc xyz" to group words.
Just to clarify
I also thought of inserting '+' into all spaces in the query. I just wanted to avoid detecting grouped terms (brackets, quotes etc) and potentially breaking the query. Is there another approach?
This looks similar to the Lucene Sentence Search question. If you're interested, this is how I answered that question:
String defaultField = ...;
Analyzer analyzer = ...;
QueryParser queryParser = new QueryParser(defaultField, analyzer);
queryParser.setDefaultOperator(QueryParser.Operator.AND);
Query query = queryParser.parse("Searching is fun");
Like Adam said, there's no need to do anything to the query string. QueryParser's setDefaultOperator does exactly what you're asking for.
Why not just preparse the user search input and adjust it to fit your criteria using the Lucene query syntax before passing it on to Lucene. Alternatively, you could just create some help documentation on how to use the standard syntax to create a specific query and let the user decide how the query should be performed.
Lucene has a extensive query language as described here that describes everything you want except for + being the default but that's something you can simple handle by replacing spaces with +. So the only thing you need to do is define the format you want people to enter their search queries in (I would strongly advise to adhere to the default Lucene syntax) and then you can write the transformations from your own syntax to the Lucene syntax.
The behavior is hard-coded in method addClause(List, int, int, Query) of class org.apache.lucene.queryParser.QueryParser, so the only way to change the behavior (other than the workarounds above) is to change that method. The end of the method looks like this:
if (required && !prohibited)
clauses.addElement(new BooleanClause(q, BooleanClause.Occur.MUST));
else if (!required && !prohibited)
clauses.addElement(new BooleanClause(q, BooleanClause.Occur.SHOULD));
else if (!required && prohibited)
clauses.addElement(new BooleanClause(q, BooleanClause.Occur.MUST_NOT));
else
throw new RuntimeException("Clause cannot be both required and prohibited");
Changing "SHOULD" to "MUST" should make clauses (e.g. words) required by default.