Use a Field value in a Query (Seblod Query plugin) - joomla

I'm using the Query plugin that lets me create a Query field on my List & Search.
I have a hidden field with ID 'id_number' which I'm trying to use in my query. When I check the Page Source(Ctrl+U on Chrome), the hidden field has the correct value of id_number which is '22865'.
The part of my Query is-
WHERE [MATCH]p.pid||$cck->getValue('id_number')[/MATCH] AND (ban_reason in ("", "active"))
When I print this query out using the Debugger, the Query is using the literal value and querying the above as-
(p.pid LIKE '%$cck->getValue(\'id\_number\')%') ....and not like (p.pid LIKE '%22865%')
I also tried using $fields['id_number']->value but it still queries it incorrectly.
Should I not use $cck->getValue('id_number') to get the value of the hidden field in the query? Or is there something other than this that I need to use?

Related

Search specific key's value from a json field database entry using eloquent

Hello everyone please I am working on a system and need to add a query that receives a search term stored with the variable $search and fetch all matching values for a specific key in a json field from database.
I have tried the code bellow
$query = Book::whereJsonContains('book_details->author',['like'=>"%{$search}%"])->get();
Book is my model, book_details is the json field name and author is the key. I want to retrieve every book with authors related to the search term
In Laravel, you can perform a query that retrieves all matching values for a specific key in a JSON field by utilizing the whereJsonContains method. A revised version of your code could look like this:
$query = Book::whereJsonContains('book_details->author', $search)->get();
This query will return all Book records where the value of the author key in the book_details JSON field contains the search term stored in the $search variable.
Note that you don't need to wrap the search term in % characters, as the whereJsonContains method performs a case-insensitive search for matching values by default.

How can I use standard SQL on text fields of elastic without using the specials SQL elasticSearch operators?

I would like to create SQL query on some text field (not keyword) for example "name" field and send that query to elastic server.
my problem is that I need to use the standard SQL language (not the MATCH and QUERY operators which are specials for elastic SQL) of text fields.
when I tried to use JDBC driver or when I tried to use high-level-java-client with LIKE operatorI got the following error
"No keyword/multi-field defined exact matches for [name]; define one or use MATCH/QUERY instead"
I also tried to use the translate API of elasticsearch- but even there I couldn't use the "LIKE" operator on text fields only on keyword fields.
does anyone have any solution for me? I want to use the LIKE operator on text fields instead of the full text operators which are unique to elastic sql.
Please check the this documentation. they have clearly mentioned in document that it is not possible.
One significant difference between LIKE/RLIKE and the full-text search
predicates is that the former act on exact fields while the latter
also work on analyzed fields. If the field used with LIKE/RLIKE
doesn’t have an exact not-normalized sub-field (of keyword type)
Elasticsearch SQL will not be able to run the query. If the field is
either exact or has an exact sub-field, it will use it as is, or it
will automatically use the exact sub-field even if it wasn’t
explicitly specified in the statement.
If you still want to used text field then you need to enabled multi-field as mentioned here. or you can try out to enable fielddata on text field but i am not sure that it will work SQL or not.

How to construct subquery in the form of SELECT * FROM (<subquery>) ORDER BY column;?

I am using gorm to interact with a postgres database. I'm trying to ORDER BY a query that uses DISTINCT ON and this question documents how it's not that easy to do that. So I need to end up with a query in the form of
SELECT * FROM (<subquery>) ORDER BY column;
At first glance it looks like I need to use db.QueryExpr() to turn the query I have into an expression and build another query around it. However it doesn't seem gorm has an easy way to directly specify the FROM clause. I tried using db.Model(expr) or db.Table(fmt.Sprint(expr)) but Model seems to be completely ignored and fmt.Sprint(expr) doesn't return exactly what I thought. Expressions contain a few private variables. If I could turn the original query into a completely parsed string then I could use db.Table(query) but I'm not sure if I can generate the query as a string without running it.
If I have a fully built gorm query, how can I wrap it in another query to do the ORDER BY I'm trying to do?
If you want to write raw SQL (including one that has a SQL subquery) that will be executed and the results added to an object using gorm, you can use the .Raw() and .Scan() methods:
query := `
SELECT sub.*
FROM (<subquery>) sub
ORDER BY sub.column;`
db.Raw(query).Scan(&result)
You pass a pointer reference to an object to .Scan() that is structured like the resulting rows, very similarly to how you would use .First(). .Raw() can also have data added to the query using ? in the query and adding the values as comma separated inputs to the function:
query := `
SELECT sub.*
FROM (<subquery>) sub
WHERE
sub.column1 = ?
AND sub.column2 = ?
ORDER BY sub.column;`
db.Raw(query, val1, val2).Scan(&result)
For more information on how to use the SQL builder, .Raw(), and .Scan() take a look at the examples in the documentation: http://gorm.io/advanced.html#sql-builder

Fast query to retrieve those records that has published date

How do I query using Sitecore fast query to retrieve those records that has published date? I tried using the below but it did not return any value.
And how do I retrieve only the last node? Because when I use descendant::*, it will also return the parent out.
fast:/sitecore/content/test//[##parentid='{5656C582-A876-41E6-8441-A3F0BA0D2601}'
and #Publish>'20170101T000000']/descendant::
The Sitecore Field name for the publish field is not Publish. You need to make use of the following syntax for publish field: #__Publish.
You can see the right field name in the Inheritance from the template. You will be able to see the field names as shown below:
So, your query will looks as follows:
fast:/sitecore/content/Home//*[##parentid='{5656C582-A876-41E6-8441-A3F0BA0D2601}' and #__Publish > '20170101T000000']/*

Multiple Field Search using Lucene Parser with Solr Using Sunspot

I'm using Solr with Sunspot (ruby) and due to other constraints i have to use the Lucene parser instead of the DisMax parser. I need to be able to search using username as well as first_name fields at the same time.
If i were using DisMax i can specify qf="username+first_name" but using only the lucene parser I am only able to set df (default field) and it will not allow me to specify more than one field.
How can I search multiple fields using the lucene parser?
Update: Answer: just use the q parameter
adjust_solr_params do |params|
params[:defType] = "lucene"
params[:q] = "username:\"#{params[:q]}\" OR first_name:\"#{params[:q]}\""
end
You can use copy fields instructions in your schema to create a "catch all" field from all the fields you want to search on. You then set df to that field.
To expand on Karussell's comment, the default field is just that, the default. You can explicitly specify however many fields you want, it's only if you don't specify one that the default comes into play.
So a query like username:foo first_name:bar will find documents with a username of "foo" and a first_name of "bar."

Resources