I'm trying to determine if there's a way to create a custom Predicate to handle searches for text that contains accented characters.
The problem I am trying to solve is that I have the string "Montréal" stored in the JCR, and want it to show up if my query contains a search for "Montreal" or even "Montre".
I am trying to use the XPATH function fn:replace to do something like this:
replace('Montréal', '[éè]+', 'e')
Here's an example xpath query (run using the query tool in the CRX/DE):
/jcr:root/content/dam/mysite/en//*
[
(#jcr:primaryType = 'dam:AssetContent' and jcr:like(fn:replace(fn:lower-case(data/master/#city), '[éè]+', 'e'),'%montre%'))
]
However, when I attempt to use it, I get the error:
expected: jcr:like | jcr:contains | jcr:score | xs:dateTime | fn:lower-case | fn:upper-case | fn:name | rep:similar | rep:spellcheck | rep:suggest
Is there some way to enable the replace function?
I had faced a similar issue.
I will explain what I did to overcome that.
The requirement : There is a search bar, and in that user were using accented chars.
The problem : same. jcr:like & fn:replace didn't work.
What I did was, sent the search param as it is intp the backend (Java) through servlet, as I was building queries through a service there.
Then I just encoded them in base64, and added the same in the query, as AEM keeps non-english chars in base64 encoded values.
Then just decoded the results in the FE ( but you can do that in Java as well.)
Related
I am trying to filter rows with: name eq 'nameFromQueryData'
One name is breaking the filter: Paul O'Meefe
Its due to the filter needing to escape the ' inside the name. Its reading it as: name eq 'Paul O' (end string) Meffe' (start string) = error
Since this is dynamic data, I cant just use the escape character O/'.
So how would one go about escaping it?
Try using fetchxml instead - it's a lot more adaptable and forgiving instead of an odata query in Power Automate
enter image description here
In LogQL line_format template expression, is there a way to access the original log entry (assume the entry is not in JSON or any parseable format and all labels are log labels and not extracted labels).
example:
... | line_format "{{.log_label1}}, {{.log_label2}}: {{<some way to show the entire original log entry>}}"
One way it to prepend it with a regular expression capturing the entire message
... |regexp '(?P<message>.*)' |line_format "{{.some_other_var}} {{.message}}"
Note that the ' around the regex should really by ` otherwise it might not work
It looks like instead of regexp you can use json parser:
... | json | line_format "{{.stream}}: {{.log}}"
I have a few Xpaths as below:
//*[#id="904735f0-bb82-11ea-a473-6d0f51688222"]/div/p
//*[#id="729c0860-a71d-11ea-b994-53a3e91a35c2"]/div/div/div[1]/div/p
//*[#id="2555ab30-bb84-11ea-9e8b-277e7f6208b2"]/div/div/div[1]/div/p
//*[#id="7e100250-a71d-11ea-b994-53a3e91a35c2"]/div/div/div[1]/div/p
//*[#id="811727d0-a71d-11ea-b994-53a3e91a35c2"]/div/div/div[1]/div/p
All of the above are used to extract text from a single web page since text is located at different view--ports, but I wish to find a single xpath to extract text for all of them. Is it possible to use 'and' and multiple ID's to extract all of it through one xpath?
Any other suggestions would be appreciate.
You can use the or operator for the last four.
And the merge-nodes operator | to add the first one.
So to select all 5 expression in one, use the following expression:
//*[#id="904735f0-bb82-11ea-a473-6d0f51688222"]/div/p | //*[#id="729c0860-a71d-11ea-b994-53a3e91a35c2" or #id="2555ab30-bb84-11ea-9e8b-277e7f6208b2" or #id="7e100250-a71d-11ea-b994-53a3e91a35c2" or #id="811727d0-a71d-11ea-b994-53a3e91a35c2"]/div/div/div[1]/div/p
A shorter and more generic solution could be :
(//div/div/div[1]/div/p|//div/p)[parent::*[string-length(#id)=36 and substring(#id,24,1)="-"]]
First part with () is used to specify the end of the path. Since #id attributes have the same length, we use it inside the predicate. We also verify the presence of a - at a specific position with substring.
I want to have URLs like
http://www.example.com/(*.)
but CodeIgniter does not allow me to do that. When I try to access some URLs I get 404 error (and the requested page exists).
I know I can set allowed characters in URL, but I thought about encoding it. However, if I do something like this:
http://www.example.com/<?php echo rawurlencode(string) ?>
or even:
http://www.example.com/<?php echo rawurlencode(rawurlencode(string)) ?>
I still got the 404. Why is that? '%'s are allowed characters, so why it won't work? And what can I do to fix it?
You can allow certain signs through config/config.php and the permitted_uri_chars key.
However, though I'm not fully certain, I do believe these are restricted by default to increase security. As relevant explanation suggests:
/*
|--------------------------------------------------------------------------
| Allowed URL Characters
|--------------------------------------------------------------------------
|
| This lets you specify with a regular expression which characters are permitted
| within your URLs. When someone tries to submit a URL with disallowed
| characters they will get a warning message.
|
| As a security measure you are STRONGLY encouraged to restrict URLs to
| as few characters as possible. By default only these are allowed: a-z 0-9~%.:_-
|
| Leave blank to allow all characters -- but only if you are insane.
|
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
*/
For instance, what's so neat about the current settings is that you allow few enough uris to parse IDs without risking to have them compromised by '', "" or similiar. Of course there's automatic and manual $this->db->escape(), but this just adds more failsafes.
WHen trying to pass urlencoded strings to the URI it will generate an error if the encoded string has a /, codeigniter will try to parse this as a segment, thus rendering a 404, what you need to use is query strings.
$string = rawurlencode(string)
http://www.example.com/class/method/?string=$string
then on your method
use get
function method()
{
$this->input->get('string');
}
In case you want to have slashes / in the URL, use double raw encoding. For example:
$string = rawurlencode(rawurlencode('/sth/sth'));
I am trying a Solr query which is like this
+field1:* AND (field2:1 OR field2:10) NOT(field3:value1 OR field3:value2)
But field3 part of the query is not making any impact. It still brings record which has value1 or value2 in field3
Why is this?
Try this
+field1:* +(field2:1 OR field2:10) -(field3:value1 OR field3:value2)
I think a AND / OR is missing between the two last blocks. It would then become something like :
+field1:* AND (field2:1 OR field2:10) AND NOT(field3:value1 OR field3:value2)
You need to urlencode certain characters in the Solr query to meet UTF8 standards and the + (plus) symbol is one of them, as well as space, brackets etc.
Things to encode are:
Space => +
+ => %2B
( => %28
) => %29
and so forth, you can see an example of an encoded URL on the SOLR website:
https://wiki.apache.org/solr/SolrQuerySyntax
Try:
str_replace(array('+','(',')',' '), array('%2B','%28','%29','+'), '+field1:* (field2:1 field2:10) -(field3:value1 field3:value2)');
This should give you:
%2Bfield1:*+%2B%28field2:1+field2:10%29+-%28field3:value1+field3:value2%29
IF your default query parser operation is set to OR, then any space between fields will be interpreted as an OR operator.
The above result is far from clean & readable, but it is a correctly formatted UTF8 string which Solr requires you to pass to it. You'll notice the difference as soon as you run it.
Why str_replace instead of urlencode? Well you can use urlencode because it will correctly format the string as UTF8 but it might format some string components that don't need to be encoded.