CQ5 QueryBuilder if Property has a value or has no value - search

I am running a query like to do determine if the page has the given tag(s)
predicates.put("property","jcr:content/cq:tags");
predicates.put("property.and","true");
predicates.put("property.1_value","properties:style");
predicates.put("property.2_value","properties:style/color");
I also want to be able to get all results that have any tag or query on all results that have no tag.
What would I put in the value section to check for these constraints

You need to set the operation parameter of the property predicate. Its semantic is described here: JcrPropertyPredicateEvaluator

Related

How do we write gremlin update/modify query in node.js?

How do we write gremlin update/modify query in node.js ?
I want to update particular field and save the same and do not modify other fields which are not edited.
I have a table called "org" and it has some properties like name, id, label.
How can we modify particular property or all the properties depends on the put body request ? using gremlin query
Any property can be updated as follows (assuming it is a single value and not a set)
g.V('some-id').
property(Cardinality.single,'my-property',new-value).
iterate()
UPDATED: If you need to update the contents of multiple properties you can just chain the property steps together.
g.V('some-id').
property(Cardinality.single,'p1',new-value).
property(Cardinality.single,'p2',new-value).
property(Cardinality.single,'p3',new-value).
property(Cardinality.single,'p4',new-value).iterate()
UPDATED again
If you only want to set a property value if the property already exists you can check for its existence using a 'has' step as shown below.
g.V('some-id').
has('p1').
property(Cardinality.single,'p1',new-value)
If you want to do this for more than one property you can use optional steps as one way to do multiple of these checks.
g.V('some-id').
optional(has('p1').
property(Cardinality.single,'p1',new-value)).
optional(has('p2').
property(Cardinality.single,'p2',new-value)).
Some additional information can be found at [1] and [2]
[1] http://www.kelvinlawrence.net/book/PracticalGremlin.html#addnodes
[2] https://tinkerpop.apache.org/docs/current/reference/#addproperty-step

MarkLogic Text Search: Return Results Based on Matches Inside Attributes

I am using Marklogic's search:search() functions to handle searching within my application, and I have a use case where users need to be able to perform a text search that returns matches from an attribute on my document.
For example, using this document:
<document attr="foo attribute value">Some child content</document>
I want users to be able to perform a text search (not using constraints) for "foo", and to return my document based on the match within the attribute #attr. Is there some way to configure the query options to allow this?
Typing in attr:"foo" is not a workable solution, so using attribute range constraints won't help, and users still need to be able to search for other child content not in the attribute node. I'm thinking perhaps there is a way to add a cts:query OR'd into the search via the options, that allows this attribute to be searched?
Open to any and all other solutions.
Thanks!
Edit:
Some additional information, to help clarify:
I need to be able to find matches within the attribute, and elsewhere within the content. Using the example above, searches for "foo", "child content", or "foo child content" should all return my document as a result. This means that any query options that are AND'd with the search (like <additional-query>, which is intended to help constrain your search and not expand it) won't work. What I'm looking for is (likely) an additional query option that will be OR'd with the original search, so as to allow searching by child node content, attribute content, or a mix of the two.
In other words, I'd like MarkLogic to treat any attribute node content exactly the same as element text nodes, as far as searching is concerned.
Thanks!!
You could accomplish this search with a serialized element-attribute-word cts query in the additional-query options for the search API. The element attribute word query will use the universal index to match individual tokens within attributes.
In MarkLogic 9 You may be able to use the following to perform your search:
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
search:search("",
<options xmlns="http://marklogic.com/appservices/search">
<additional-query>
<cts:element-attribute-word-query xmlns:cts="http://marklogic.com/cts">
<cts:element>document</cts:element>
<cts:attribute>attr</cts:attribute>
<cts:text>foo</cts:text>
</cts:element-attribute-word-query>
</additional-query>
</options>
)
MarkLogic has ways to parse query text and map a value to an attribute word or value query.
First, you can use cts:parse():
http://docs.marklogic.com/guide/search-dev/cts_query#id_71878
http://docs.marklogic.com/cts.parse
Second, you can use search:search() with constraints defined in an XML payload:
http://docs.marklogic.com/guide/search-dev/query-options#id_39116
http://docs.marklogic.com/guide/search-dev/appendixa#id_36346
I'd look into using the <default> option of <term>. For details see http://docs.marklogic.com/guide/search-dev/appendixa#id_31590
Alternatively, consider doing query expansion. The idea behind that is that a end user send a search string. You parse it using search:parse of cts:parse (as suggested by Erik), and instead of submitting that query as-is to MarkLogic, you process the cts:query tree, to look for terms you want to adjust, or expand. Typically used to automatically blend in synonyms, related terms, or translations, but could be used to copy individual terms, and automatically add queries on attributes for those.
HTH!

Filtering GetEntries by another Entry ID's existence within array of links attribute

I have a content type post where the entries have a categories attribute, which is an Array of Links (to a category content type).
I want to fetch all posts that have been tagged with a certain category. That is, Post entries where fields.categories[any link sys.id] = MyCategoryId.
I can only find an example only where the reference field is a singleton, not an array.
Would love any help, thanks!
You could specify your query like this:
/spaces/YOURSPACEID/entries?content_type=CONTENTTYPEID&fields.categories.sys.id=SOMEID
Notice that a content type restriction is necessary as we are filtering on a field property.
Also note that this only works because we're filtering on a system property directly accessible from the actual entry returned. If you wanted to filter on another property of the Category content type, for example title or description that is not currently supported.
Here's also a link to the official documentation including examples and explanations for the search api: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/query-entries

How to check a property in search result pages in AEM or CQ?

I am executing a query using query builder and getting result which are pages. now i want to check number of pages which contains a property "branch" and value is "true" and i can't include this in my query or as a predicate as i want result of all the pages whether it contains a branch property true or false. but for a different task i need the number of pages who contains branch property value true and due to performance i can't hit another query. Is there any alternative for this requirement so that i can get the number of pages in result who contains branch property true. and what will be the best way to achieve this so that performance also not get impacted.
This sounds like running a single query, and bisecting the results on a given property/predicate based on the property. You haven't described why you want only a single query.
Since I am in the habit of leveraging functional programming styles (in Groovy and Java8), I would gather the query results into a Collection of resources, and then groupBy with a predicate testing your property's value.
PredicateGroup predicates = PredicateGroup.create(map)
Query query = queryBuilder.createQuery(predicates, session)
Map results = query.getResult().getResources()
.collect { it as Resource }
.groupBy { it.adaptTo(ValueMap).get("branch", false).equals() }

Alfresco Lucene search syntax

I am writing a webscript, wherein I have a custom content model.
I want to list all the documents, that have a particular property as one of it's attributes.
Firstly I did
search.luceneSearch("PATH:\"/app:company_home//*\" AND #cm:name:myDocument")
This returned me value 1. But this query actually returns me the documents, whose cm:name property is myDocument.
what if I want to search for documents, who has cm:name property as an attribute.
So that later, I can change cm:name with mycontentmodel:myproperty, and find the elements that belong to my content type.
If I understand correctly, you'd like to find all the documents that have property mycontentmodel:myproperty, but you're not interested in the actual value of the property.
If so, find out what type or aspect mycontentmodel:myproperty belongs to.
If it belongs to type mycontentmodel:mytype the query can be:
PATH:"/app:company_home//*" AND TYPE:"mycontentmodel:mytype"
and if it belongs to aspect mycontentmodel:myaspect
PATH:"/app:company_home//*" AND ASPECT:"mycontentmodel:myaspect"

Resources