Exclude child path from fulltext search parent path using Querybuilder OR get search hit excerpt from XPATH/JCR SQL2 query - lucene

I want to exclude child nodes path from search path using querybuilder
for example - parent folder is /content/mysite/en
and subfolders are
/content/mysite/en/testfolder1
/content/mysite/en/testfolder2
I want query builder to write a query to exclude these paths
I already looked at this question -
AEM Query builder exclude a folder in search
but grouping paths and p.not=true doesn't seem to be working as expected
I know it's a bit tricky to write such a query using query builder ; so I am using JCR/SQL2 query -
using
SELECT * FROM [cq:Page]
WHERE ISDESCENDANTNODE(page,'/content/mysite/en')
AND CONTAINS(*, 'fulltext')
AND NOT ISDESCENDANTNODE(page, '/content/mysite/en/testfolder1')
AND NOT ISDESCENDANTNODE(page, '/content/mysite/en/testfolder2')
but the issue now is that We also want the search excerpt which is created automatically by querybuilder api's SearchResult's hit object -
hit.getExcerpt()
so is there a way I can get the excerpt using JCR/SQL2 query ?
OR is there a way I can build the exclude subfolder query using querybuilder; so that I can get excerpts from results? Both solutions will solve my case.
If anyone has experience in excluding subfolder query using querybuilder; or building search excerpt using JCR/SQL2 query; or any other idea/suggestion for this case; help will be much appreciated

Try path.exact=true Below is a example
without path.exact=true
type=cq:Page
path=/content/wkndmuzik/us/en
output:
With path.exact=true
type=cq:Page
path=/content/wkndmuzik/us/en
path.exact=true
Output:
path.exact=true : If true exact path is matched, if false all descendants are included.
For other predicates on querybuider api visit the blog of Hashim Khan

Related

AEM JCR SQL2 query to find all pages contains specific component

I wish to build a sql2 jcr query to find all pages under /content that contains this component, e.g /apps/platform/aem-core/components/content/form/form
I read https://wiki.magnolia-cms.com/display/WIKI/JCR+Query+Cheat+Sheet and tried something like below
My current attempt is something like SELECT * from [cq:Page] AS t WHERE t.contains('/apps/platform/aem-core/components/content/form/form')
But it won't work. Please suggest me a example to find all pages contains this component. Thanks
As #awd has mentioned in the comments, QueryBuilder provides better capabilities.
SQL2 however is not that bad, especially for someone with an inclination towards RDBMS !
The below query should fetch all the page paths using the component resourceType.
SELECT * FROM [cq:PageContent] AS s WHERE
ISDESCENDANTNODE(s,'/content') AND CONTAINS(s.[sling:resourceType],
'foundation/components/text')
You've got to use square brackets for properties with namespaces in them, for e.g: cq:template, sling:resourceType, etc
SELECT page.* FROM [cq:Page] AS page INNER JOIN [nt:base] AS component ON ISDESCENDANTNODE(component,page) WHERE ISDESCENDANTNODE(page, '/content') AND component.[sling:resourceType] = '/apps/platform/aem-core/components/content/form/form'
select * from nt:base where jcr:path like '/content/%' and [sling:resourceType] ='/apps/platform/aem-core/components/content/form/form'

How to get specific content type document count from alfresco share UI using Lucene query

How to get specific content type document count in alfresco share UI using Lucene query?
I have tried to query in alfresco share UI Alfresco Lucene query. but it's only giving first 100 results.
Is there any best way to get only document count by specific content type or document count under specific alfresco site??
Please suggest if there is any other best and useful way.
Thanks in Advance.
The class PatchDAO has a method that returns the number of node with a given type:
/**
* Gets the total number of nodes which match the given Type QName.
*
* #param typeQName the qname to search for
* #return count of nodes that match the typeQName
*/
public long getCountNodesWithTypId(QName typeQName);
where typeQName is, of course, the QName of the type.
This method should return the total count and should be the most efficient.
UPDATE:
If you need the count on a specific site this method is not actually usable.
ResultSet result = searchService.query(, SearchService.LANGUAGE_LUCENE, "+PATH:\"/app:company_home/cm:" + + "/*\"" + " +TYPE:\"" + + "\"" );
You can change the parameters as per your need.
Thanks,
Kintu
Hitting the database directly is a very bad idea, so don't even start getting into that bad habit.
Using the Alfresco foundational Java API would require that the Java class be deployed to the server, which is a pain.
The easiest way to do this is to use OpenCMIS. You can run OpenCMIS code remotely, and you can use its paging result set to page through the query results, see Apache CMIS: Paging query result

Solr subquery merging issue

I have an issue to search with SOLR in following scenario,
I'd like to get all products within my favorite tag, categories and user. I want all products which created by my favorite user without any filter but products from favorite tag or categories must be filtered with in a selected location. I have tried as follows,
http://www.example.com:8983/solr/collection1/select?rows=10&start=0&wt=json&indent=true&sort=event_start_date asc&q=status:1 AND event_start_date:[2015-04-23T21:38:00Z TO *] AND ( tags:5539d77455061a650f96c67e OR category1_id:53d16fb28066a12606bbb5f2 OR category2_id:53d16fb28066a12606bbb5f2&fq={!geofilt d=40.2335}&pt=9.9312328,76.26730409999999&sfield=latlng) OR ( user_id:5465da1dc54d3c2a15000000 )
But its not working. Any body help me to find what's wrong with my query?
First of all you have a fq (filterquery clause) inside your query clause (check parenthesis) which is wrong.
fq={!geofilt d=40.2335}&pt=9.9312328,76.26730409999999&sfield=latlng
You can try things like puting the geofilt filter query OUTSIDE your main query with tests so it will be skipped if...
http://www.example.com:8983/solr/collection1/select?rows=10&start=0&wt=json&indent=true&sort=event_start_date asc&q=status:1 AND
event_start_date:[2015-04-23T21:38:00Z TO *] AND
(tags:5539d77455061a650f96c67e OR
category1_id:53d16fb28066a12606bbb5f2 OR
category2_id:53d16fb28066a12606bbb5f2) OR
(user_id:5465da1dc54d3c2a15000000)
&fq=user_id:5465da1dc54d3c2a15000000 OR
{!geofilt pt=9.9312328,76.26730409999999 sfield=latlng d=40.2335}
If user_id is 5465da1dc54d3c2a15000000 then the filterquery is already true so location part is skipped.

Alfresco boost results from site

I'm trying to boost results from a particular Alfresco site compared to others.
I've written the following query but it's not working properly :
(((TAG:term or cm:name:term OR cm:title:term )^8 OR (cm:description:term )^6) AND PATH:'/app:company_home/st:sites/cm:Pub/cm:documentLibrary//*')^8
OR
(((TAG:term or cm:name:term OR cm:title:term )^4 OR (cm:description:term )^2) AND -PATH:'/app:company_home/st:sites/cm:Pub/cm:documentLibrary//*')
The result is overall correct but the results from Pub aren't the first ones in the list.
Is there a way to achieve that ?
^8 on the first part query part was just not enough. Putting a huge value like 100 makes it work perfectly !

Endeca UrlENEQuery java API search

I'm currently trying to create an Endeca query using the Java API for a URLENEQuery. The current query is:
collection()/record[CONTACT_ID = "xxxxx" and SALES_OFFICE = "yyyy"]
I need it to be:
collection()/record[(CONTACT_ID = "xxxxx" or CONTACT_ID = "zzzzz") and
SALES_OFFICE = "yyyy"]
Currently this is being done with an ERecSearchList with CONTACT_ID and the string I'm trying to match in an ERecSearch object, but I'm having difficulty figuring out how to get the UrlENEQuery to generate the or in the correct fashion as I have above. Does anyone know how I can do this?
One of us is confused on multiple levels:
Let me try to explain why I am confused:
If Contact_ID and Sales_Office are different dimensions, where Contact_ID is a multi-or dimension, then you don't need to use EQL (the xpath like language) to do anything. Just select the appropriate dimension values and your navigation state will reflect the query you are trying to build with XPATH. IE CONTACT_IDs "ORed together" with SALES_OFFICE "ANDed".
If you do have to use EQL, then the only way to modify it (provided that you have to modify it from the returned results) is via string manipulation.
ERecSearchList gives you ability to use "Search Within" functionality which functions completely different from the EQL filtering, though you can achieve similar results by using tricks like searching only specified field (which would be separate from the generic search interface") I am still not sure what's the connection between ERecSearchList and the EQL expression above?
Having expressed my confusion, I think what you need to do is to use String manipulation to dynamically build the EQL expression and add it to the Query.
A code example of what you are doing would be extremely helpful as well.