DQL documentum like pattern with field - sql-like

i tried to use field in like pattern but without success
this is my dql i tried:
select object_name from categories a, (select object_name from clients where client_number = '12345') d
where a.r_folder_path like '%'||d.object_name||'%'
actually i try to get all categories in the clients folder where client_number is 12345
i have not cabinet name to use FOLDER and not id to use FOLDER(ID()) i have only client number.
tnx a lot

Try using the concat function
SELECT
object_name
FROM
categories a, (select object_name from clients where client_number = '12345') d
WHERE
a.r_folder_path LIKE CONCAT('%', d.object_name, '%')

Related

How to query fields with multiple values in Azure Cognitive Search

Working on Azure Cognitive Search with backend as MS SQL table, have some scenarios where need help to define a query.
Sample table structure and data :
Scenarios 1 : Need to define a query which will return data based on category.
I have tied query using search.ismatch but its uses prefix search and matches other categories as well with similar kind of values i.e. "Embedded" and "Embedded Vision"
$filter=Region eq 'AA' and search.ismatch('Embedded*','Category')
https://{AZ_RESOURCE_NAME}.search.windows.net/indexes/{INDEX_NAME}/docs?api-version=2020-06-30-Preview&$count=true&$filter=Region eq 'AA' and search.ismatch('Embedded*','Category')
And it will response with below result, where it include "Embedded" and "Embedded Vision" both categories.
But my expectation is to fetch data only if it match "Embedded" category, as highlighted below
Scenario 2: For the above Scenario 1, Need little enhancement to find records with multiple category
For example if I pass multiple categories (i.e. "Embedded" , "Automation") need below highlighted output
you'll need to use a different analyzer which will break the tokens on every ';' just for the category field rather than 'whitespaces'.
You should first ensure your Category data is populated as a Collection(Edm.String) in the index. See Supported Data Types in the official documentation. Each of your semicolon-separated values should be separate values in the collection, in a property called Category (or similar).
You can then filter by string values in the collection. See rules for filtering string collections. Assuming that your index contains a string collection field called Category, you can filter by categories containing Embedded like this:
Category/any(c: c eq 'Embedded')
You can filter by multiple values like this:
Category/any(c: search.in(c, 'Embedded, Automation'))
Start with clean data in your index using proper types for the data you have. This allows you to implement proper facets and you can utilize the syntax made specifically for this. Trying to work around this with wildcards is a hack that should be avoided.
To solve above mention problem used a below SQL function which will convert category to a json string array supported by Collection(Edm.String) data type in Azure Search.
Sql Function
CREATE FUNCTION dbo.GetCategoryAsArray
(
#ID VARCHAR(20)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE #result NVARCHAR(MAX) = ''
SET #result = REPLACE(
STUFF(
(SELECT
','''+ TRIM(Value) + ''''
FROM dbo.TABLEA p
CROSS APPLY STRING_SPLIT (Category, ';')
WHERE p.ID = #ID
FOR XML PATH('')
),1,1,''),'&','&')
RETURN '[' + #result + ']'
END
GO
View to use function and return desired data
CREATE View dbo.TABLEA_VIEW AS
select
id
,dbo. GetCategoryAsArray(id) as CategoryArr
,type
,region
,Category
from dbo.TABLEA
Defined a new Azure Search Index using above SQL View as data source and during Index column mapping defined CategoryArr column as Collection(Edm.String) data type
Query to use to achieve expected output from Azure Search
$filter=Region eq 'AA' and CategoryArr/any(c: search.in(c, 'Embedded, Automation'))

Explicitly specify "FROM" table

I currently have the following query:
query = self.session.query(Student, School).join(
Person.student, aliased=True).join(
Student.school, aliased=True).filter(
Person.id == 1)
Which compiles to this SQL.
SELECT student.id AS student_id, student.school_id AS student_school_id, student.person_id AS student_person_id, school.id AS school_id, school.name AS school_name
FROM student, school, person JOIN student AS student_1 ON person.id = student_1.person_id JOIN school AS school_1 ON school_1.id = student_1.school_id
WHERE person.id = :id_1
I want the query to remain exactly as it is but I want the from statement to be exclusively from the Person model. So something like
SELECT * FROM person JOIN ... WHERE person.id = :id_1
I think the aliased kwarg is messing up the from condition. Removing the aliased kwarg fixes the behavior but I need the aliased kwarg for special use cases. How can I remove the student and school tables from the "FROM" statement.
The aliased argument to .join uses anonymous aliasing, meaning the Student and School you pass to session.query are different 'instances' of the table.
from sqlalchemy.orm import aliased
aliased_student = aliased(Student)
aliased_school = aliased(School)
query = (
session.query(aliased_student, aliased_school)
.select_from(Person)
.join(aliased_student, Person.student)
.join(aliased_school, Student.school)
.filter(Person.id == 1))
Here you can see that you can tell .join which alias to use when joining to a relationship.

Create Collection in Azure Search Service Using View

I'm trying to create index which using import data tool.
The datasource is from azure sql's view.
SELECT
b.Name,
b.ID
(SELECT
'[' + STUFF((
SELECT
',{"name":"' + p.Name + '"}'
FROM Product p WHERE p.Brand = b.ID
FOR XML PATH (''), TYPE)
.value('.', 'nvarchar(max)'), 1, 1, '') + ']') AS TAry,
b.IsDelete,
b.ModifyDatetime
from Brand b
Column with TAry will return JSon format string like:
[{"name":"Test1"},{"name":"Test2"}]
In Indexder properties with field TAry Chose the type Collection(Edm.String)
After create , It's return error , the message below:
"The data field 'TAry' has an invalid value. The expected type was 'Collection(Edm.String)'."
Thank for your reply.
I have try this kind format :[Test1","Test2"] still not work.
To do this, you need to use Azure Search REST API to set up a field mapping with jsonArrayToStringCollection function. Take a look at this article for detailed instructions.

Joomla - order of pages in search results

The company I work for have inherited a Joomla site and I have no experience of Joomla, so I'm hoping that someone could let myself know if the following is possible.
When searching on the Joomla site, the client is expecting certain pages for certain search terms to appear at the top of the search results.
Is it possible to promote certain pages to the top of the search results depending on the search term?
Appreciate any support with this.
UPDATE
Testing locally I have updated the SQL query in /plugins/search/content.php to get close to the results that I am after.
SELECT
a.title AS title,
a.metadesc,
a.metakey,
a.created AS created,
CONCAT(a.introtext, a.fulltext) AS text,
CONCAT_WS( "/", u.title, b.title ) AS section,
CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,
CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(":", b.id, b.alias) ELSE b.id END as catslug, u.id AS sectionid, "2" AS browsernav
FROM jos_content AS a
INNER JOIN jos_categories AS b ON b.id=a.catid
INNER JOIN jos_sections AS u ON u.id = a.sectionid
WHERE
((a.title LIKE '%carbohydrate%' OR a.introtext LIKE '%carbohydrate%' OR a.fulltext LIKE '%carbohydrate%' OR a.metakey LIKE '%carbohydrate%' OR a.metadesc LIKE '%carbohydrate%'))
AND a.state = 1
AND u.published = 1
AND b.published = 1
AND a.access <= 0
AND b.access <= 0
AND u.access <= 0
AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2013-02-18 14:55:51' )
AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2013-02-18 14:55:51' )
GROUP BY a.id
ORDER BY
(NOT(a.title LIKE '%carbohydrate%'))
, (NOT(a.introtext LIKE '%carbohydrate%'))
, (NOT(a.fulltext LIKE '%carbohydrate%'))
, (NOT(a.metakey LIKE '%carbohydrate%'))
, (NOT(a.metadesc LIKE '%carbohydrate%'))
I would now like to have this as a custom plugin instead of over-writing any core plugins. I have followed the tutorial at http://docs.joomla.org/Creating_a_search_plugin but how do I set the site to use the custom plugin instead of the default search plugin?
Assuming you're using Joomla 2.5 (Although this might be the same for previous versions) you'll need to find the menu item within the 'Menu Manager' that displays the search results.
Within this menu item are some options under the 'Basic Options' tab. These include ordering search results by Newest First, Oldest First, Popularity, Alphabetical and by Category.
If the "fixed articles" are always the same, just override the search result template and add the articles in the template override.
Just copy all the files you find in
/components/com_search/views/search/tmpl
into
/templates/your_template/com_search/search
then edit default_results.php and place your fixed results there

linq to entity Contains() and nested queries

i've a trouble with linq, i'll explain on example :
i have a database table called Employee which got FirstName and LastName columns,
and a method to search employees which gets a nameList list as argument, the elements in this list are names formatted like this one "Fred Burn", or this1 "Grim Reaper",
already tryed these approaches with no luck =[
//just all employees
var allData = from emp in Context.Employee select emp;
var test1 = from emp in allData
where(emp.FirstName + " " + emp.LastName).Contains
("" + ((from n in nameList select n).FirstOrDefault()))
select emp;
var test2 = (from emp in allData
where (emp.FirstName + " " + emp.LastName)
== ((from n in nameList select n).FirstOrDefault())
select emp);
var test3 = from emp in allData
where (from n in nameList select n).Contains
(emp.FirstName + " " + emp.LastName)
select emp;
first and second queries give : {"Unable to create a constant value of type 'Closure type'. Only primitive types ('such as Int32, String, and Guid') are supported in this context."} exceptionand third : {"LINQ to Entities does not recognize the method 'Boolean Contains[String](System.Collections.Generic.IEnumerable`1[System.String], System.String)' method, and this method cannot be translated into a store expression."}
would be glad to hear your suggestions :)
Thank You!
p.s.
yea i know it's possible to split names in list and compare them separately, but still curious why wont these queries work.
I assume nameList in this case is an in memory collection and that you are trying to use the LINQ to SQL trick creating a SQL "IN" clause inside of the Entity Framework. Unfortunately, EF doesn't support this syntax (yet). Depending on the number of records you are trying to match, you may be able to run separate queries for each child you are desiring. Alternatively, you could build an entitysql query using concatenation to append the multiple items from the nameList as separate OR clauses in the WHERE operation.

Resources