Get all documents within a folder or site that has a specific Aspect property value? - cmis

I have an aspect that I have associated with multiple documents. For example lests call the aspect OrderAspect.
The below query works when I fetch all nodes that have a location property from OrderAspect set to 'WAREHOUSE-A'
SELECT * FROM oa:OrderAspect WHERE oa:Location ='WAREHOUSE-A'
How can I extend this query to get ONLY documents that have this aspect value as 'WAREHOUSE-A'.
Can I extend this query to search within a folder path or site? I would like to list all the documents within a folder (including subfolder) or a site that has OrderAspect with property location set to 'WAREHOUSE-A'.

Here is how you do a CMIS query that restricts results to a value defined in an aspect:
select D.cmis:name from cmis:document as D join sc:temp as T on D.cmis:objectId = T.cmis:objectId where T.sc:prop1 = 'value1'
Here is how you add an AND clause to require that the result be in a certain path, including sub-folders:
select D.cmis:name from cmis:document as D join sc:temp as T on D.cmis:objectId = T.cmis:objectId where T.sc:prop1 = 'value1' AND CONTAINS(D, 'PATH:\"/app:company_home/st:sites/cm:jtp-test-site-1/cm:documentLibrary//*\"')

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'))

DocumentHelper.GetDocuments().InCategories() API Method not working as intended

I am trying to get documents of given type with assigned category. This is my code:
var inCategoryDocuments = DocumentHelper.GetDocuments("XYZ.MyType").InCategories("CategoryCodeName");
It's result with this query:
SELECT * FROM View_CMS_Tree_Joined AS V WITH (NOLOCK, NOEXPAND) INNER JOIN xyz_MyType AS C WITH (NOLOCK) ON [V].[DocumentForeignKeyValue] = [C].[MyTypeID] AND V.ClassName = N'xyz.MyType' LEFT OUTER JOIN COM_SKU AS S WITH (NOLOCK) ON [V].[NodeSKUID] = [S].[SKUID] WHERE ([DocumentCulture] = N'en-EN' AND 0 = 1)
It looks like this API method (.InCategories()) doing nothing or I am missing something?
Kentico v11.0.26
Is this category assigned to specific site? If so, it wouldn't work, because in your query you didn't specify the site from which you want get documents.
You can simply add
.OnCurrentSite()
to your DataQuery, it will look like this
var inCategoryDocuments = DocumentHelper.GetDocuments("XYZ.MyType").OnCurrentSite().InCategories("CategoryCodeName");
It will retrieve the documents from the current website based on domain.
IMO method .InCategory shouldn't take care about site or it should be parametrized.
You need to include the using statement for it to work because those methods are extensions.
using CMS.DocumentEngine;

python3 wx.TreeCtrl - how to iterate through several levels

I have a treectrl structure which is populated from an external search of an open data set hosted by our municipal government. The data pertains to business licenses and is requested using Pandas and Sodapy. The tree is populated as follows:
for index, row in results_df.iterrows():
tradename = row['tradename']
address = row['address']
licTypes = row['licencetypes']
comm = row['comdistnm']
jobSts = row['jobstatusdesc']
jobCrt = row['jobcreated']
lng = row['longitude']
lng = str(lng)
lat = row['latitude']
lat = str(lat)
# Populate Tree Controls with DataFrame values
trdName = self.thrTree.AppendItem(root, tradename)
self.thrTree.AppendItem(trdName, address)
self.thrTree.AppendItem(trdName, licTypes)
self.thrTree.AppendItem(trdName, comm)
self.thrTree.AppendItem(trdName, jobSts)
self.thrTree.AppendItem(trdName, jobCrt)
self.thrTree.AppendItem(trdName, lng)
self.thrTree.AppendItem(trdName, lat)
This will result in a final structure of root, then node 1 with business name, and when expanded, contains all the information listed above, so I'm assuming root level, then child node 1, then child.child of node 1? Not even sure how the second second indented nodes are called. (I've heard the term leaf for the third level used before) But I digress; what I am interested in is grabbing the Latitude and Longitude of where the business is located, then allowing the user to map the location if they choose. I bind a wx.EVT_TREE_ITEM_ACTIVATED so that when the user double clicks on a business name to get the details, I want to grab the items displayed. This is how I am currently trying to iterate through the child nodes.
item = self.thrTree.GetSelection()
while self.thrTree.GetItemParent(item):
piece = self.thrTree.GetItemText(item)
tmpHldr.insert(0, piece)
item = self.thrTree.GetItemParent(item)
Looking at item, it appears to be collecting all the business names under root, and ignoring the third level items of interest.
What do I need to do to go deeper within the tree to grab the details under the business clicked on, and not just the list of business names under the root item, which is called 'Search Results'?
Thanks!
#YYC_Code,
Did you look here?
This has GetFirstChild()/GetNextChild() pair functions that you can use to iterate. It also has ItemHasChildren() function which you can use to verify if the item has any children and use the pair mentioned above if it does.
EDIT:
[quote]
For this enumeration function you must pass in a ‘cookie’ parameter which is opaque for the application but is necessary for the library to make these functions reentrant (i.e. allow more than one enumeration on one and the same object simultaneously). The cookie passed to GetFirstChild and GetNextChild should be the same variable.
[/quote]
You need to make sure that the cookie parameter is the same during the iteration.
You should also do this:
[quote]
Returns an invalid tree item (i.e. wx.TreeItemId.IsOk returns False) if there are no further children.
[/quote]

extract posts cover images(first media) in orchard database

I want to have a query that extract all informations about blog posts in Orchard-cms Database. and i found this reference so i created some query like this:
SELECT * FROM dbo.default_Title_TitlePartRecord
inner join dbo.default_Orchard_Framework_ContentItemRecord on
dbo.default_Title_TitlePartRecord.ContentItemRecord_id=dbo.default_Orchard_Framework_ContentItemRecord.Id
inner join dbo.default_Orchard_Framework_ContentTypeRecord on
dbo.default_Orchard_Framework_ContentItemRecord.ContentType_id= dbo.default_Orchard_Framework_ContentTypeRecord.Id
inner join dbo.default_Common_BodyPartRecord on
dbo.default_Common_BodyPartRecord.ContentItemRecord_id=dbo.default_Orchard_Framework_ContentItemRecord.Id
INNER JOIN dbo.default_Orchard_Framework_ContentItemVersionRecord AS civr on
civr.ContentItemRecord_id = dbo.default_Orchard_Framework_ContentItemRecord.Id
but still i couldnt find any way to access posts first media(post image or cover image) Address!
do you know how can i get the posts image address in orchard database?
i found picture names in a table named Orchard_MediaLibrary_MediaPartRecord but there isnt any foreign key which connected to this table(maybe i didnt find it)
can any body help me ...is there any diagram for orchard database??!!
i found it... there is no foreign key field to reference image of the post. but there is a field named DATA in version row of the content item which contains an xml string.
one of the xml Elements is <image/> and contains id of image in text value.
SELECT distinct dbo.default_Orchard_Framework_ContentItemRecord.Id as postId ,
L2.Title as PostTitle ,
civr.Data --this is xml field !!!!!!!!!
FROM dbo.default_Orchard_Framework_ContentItemRecord
inner join dbo.default_Common_BodyPartRecord on
dbo.default_Common_BodyPartRecord.ContentItemRecord_id=dbo.default_Orchard_Framework_ContentItemRecord.Id
INNER JOIN dbo.default_Orchard_Framework_ContentItemVersionRecord AS civr on
civr.ContentItemRecord_id = dbo.default_Orchard_Framework_ContentItemRecord.Id
inner join dbo.default_Orchard_Framework_ContentTypeRecord on
dbo.default_Orchard_Framework_ContentItemRecord.ContentType_Id=dbo.default_Orchard_Framework_ContentTypeRecord.Id
CROSS APPLY(select top(1) Title from dbo.default_Title_TitlePartRecord where ContentItemRecord_id =dbo.default_Orchard_Framework_ContentItemRecord.Id)L2
where civr.Published=1 and dbo.default_Orchard_Framework_ContentItemRecord.ContentType_Id=9 and civr.Latest=1 order by postId desc

How can I determine root objects in an arangodb tree graph?

I have a document collection containing tree nodes and an edge collection containing "is child of" like this:
Folders=[
{_key:"1",name:"Root1"},
{_key:"2",name:"Root2"},
{_key:"3",name:"Root1.Node1"},
{_key:"4",name:"Root1.Node2"}]
FolderRelations=[
{_from:"Folders/3",_to:"Folders/1"},
{_from:"Folders/4",_to:"Folders/1"}
]
Now I would like to determine which Folder items are root objects in that tree (all objects that have no outbound relation).
Maybe, I am a bit stuck in thinking SQL, I would like to carry out something like:
SELECT *
FROM Folders
WHERE NOT EXIST (SELECT * FROM FolderRelations WHERE FolderRelations.FromKey=Folders.Key)
For using the traversal and path functionality, I have no vertex to start with.
here is an AQL example that should solve your problem:
for f in Folders
filter LENGTH( EDGES(FolderRelations, v._id, "outbound")) == 0
return f
you will get a list of all vertices that have no folder above in the hierarchy.
but be aware:
saving {key:1} will not have the desired effect, you have to set:
{_key: "1"}
_key is used for internal key attribute, and it has to be a string.

Resources