does sitecore query support current() function? - xpath

I get an error if I try to use the xpath 'current()' function in a sitecore query inside a nested expression, something like this:
/sitecore/content/Home/Topics/*[contains(current()/#MainTopics, ##id)]
What I am trying to do is, use this query as a source for my DropLink field to only list 'Topic' items that are already selected in another 'MainTopics' field in the same item.
But this gives me an error, something like ")" expected at position 50
So looks like current() function cannot be used inside the nested expression, or entirely. If not, is there any way to reference the current node and not the context node from within a nested expression?
Any ideas?

does sitecore query support current() function?
current() is a function defined only in XSLT.
By definition current() produces the node that is matched by the current xsl:template or the node that is selected in an xsl:for-each
As SiteCore doesn't seem to have an XSLT implementation, the answer must be negative.

I don't think there's any simple way to do this in Sitecore query.
But to place a data source on a template field that references items chosen in another field (if I've understood right) then one possible solution is to build a custom field. In the code for the custom field you would do some string handling to extend or override Sitecore query, allowing you to add a query type that specified a particular field ID. Essentially you'd have to write your own very basic query language that you could use within your C# code.
You can derive your feild from ValueLookupEx and override the GetItems(Item current) method with your custom query handling. As you can see, it quite handliy comes with the current item provided!
We had a similar requirement which we solved this way.

Related

How to add multiple fields for sorting top hits in ElasticSearch Java API?

I know that ES supports sorting top hits by more than one fields, like sort: ["_score", "datetime"] suggested by this post: https://discuss.elastic.co/t/top-hits-query-with-same-score/107018
But how to do it using Java API?
The AggregationBuilders.topHits().sort() only receives one field as parameter.
Should I use
and SortBuilder as parameter?
If so, SortBuilder asks for a QueryShardContext parameter, which I don't know how to create. I have never used it before. None of the other requests uses this QueryShardContext.
Is there any simple way to do it, like, just pass in an array of fields into sort()?
Thanks in advance!
There are overloaded TopHitsAggregationBuilder.sort() methods, namely one that takes String name, i.e. the name of a field, so you can do it like this:
TopHitsAggregationBuilder thabuilder = AggregationBuilders.topHits("top");
thabuilder.sort("datetime", SortOrder.DESC);
thabuilder.sort("field2", SortOrder.ASC);
...
All the sort calls will add a new sort component to the top-hits aggregation.

Laravel validation; human names for array fields

In Laravel form validation you can do this: file_description.* to validate each item of an array according to a set of rules. The problem is, the system automatically returns "file_description.1 is required" as an error message if the field is required and not filled in.
More on that here: https://ericlbarnes.com/2015/04/04/laravel-array-validation/
Now, I'm not a complex man, I just want the field to say "File Description 1 is required". I am aware you can set messages but a) my input arrays are dynamically generated by jquery (click to add more type scenario) so I'd have to use a loop like in the above example b) I feel like there must be a better way.
Is there a way to either extend the core validation system to simply return a humanized name for the array field as Laravel does with regular fields, or is there an option I missed in the docs that allows for this? I'd rather not get involved with doing some regex type search to fix this.

Searching in component of specific content-type

I'm not sure how to proceed in this case:
I have a model response. This model has a reference to a repeated component message with a field text.
When i use the search in the top left of the response list i want to recieve results of all items where the searchtext ist included in the text field of the component inside the response.
Is this even possible? As far as i see the strapi.entityService.search only can search existing model-content and not component-content?
Due to the relation type that is used for component, it's not possible to filter on this kind of field for the moment.
And there is no workaround for that. Sadly.

OData $filter substringof applied to a list of strings

I have an ASP.NET Web API Controller that exposes an IQueryable(Of String) - which is a list of descriptions. These fields can be in the order of tens of thousands, thus I use $top and $skip to only get a chunk of it - that works fine.
Now I am trying to filter these results, through the OData substringof('mydesc',Property) filter. As you can see, it requires for me to pass in a Property name on which to filter. However, since I'm returning a list of strings, I don't actually have any properties to filter on.
This causes the server to return errors like
No property or field 'tostring' exists in type 'String' - when called with $filter=substringof('asd',tostring).
If I change the call to $filter=substringof('asd',''), no errors are thrown, but no results either.
My question is, can I somehow format the $filter operator to find substrings within my list of strings, without looking for a property/field, or am I going to have to declare a class with a single property, just to enable filtering?
Things have changed since the last time I answered this. OData V3 has support for querying collection of primitives using '$it'. Asp.net Web API supports this syntax as well. For example, in your controller you can return IQueryable<string> and send a request like
$filter=substring('mydesc', $it) or
$filter=length($it) ge 5
etc. You can also expose collections of other primitives like IQueryable etc.
unfortunately declaring a class with a single property seems to be the only solution that I can think of. OData $filter doesn't have any support for something like the this parameter in C#
another less obvious approach is to expose a computed concatenated value representing the list, substringof could then be used to query the list as a single property value

Is it possible to do a "not equals" query in Dojo Grid?

I have a Dojo Grid that I'm filtering with a query that's set in a javascript function.
function filter() {
var grid = dojo.byId("gridNode");
grid.setQuery({fieldName:"Some Text"});
}
What I'd really like to do, though, is filter it so that it shows all entries where the fieldName value is not empty. Does anyone know if there's a way to do this with the Dojo Grid Query, or any other solution that will work with Dojo Grid?
If you are using dojo 1.4 and an dojo.data.ItemFileReadStore you can use a regular expression so the following should work:
grid.setQuery({fieldName:"[^]+"});
According to the following documentation page, not all of the data stores may implement regular expression usage in the query but you can try it out:
http:(slash)(slash)docs.dojocampus.org/dojo/data/ItemFileReadStore
(replace slash slash with //, as a new user, spam prevention prevents me from posting more than one hyperlink)
You might also want to look into using the filter property of the Grid to accomplish what you want, if you want to filter based on some input. Look at this example:
http://docs.dojocampus.org/dojox/grid/DataGrid#filtering-data
It would basically just be something like:
grid.filter({fieldName:"[^]+"});

Resources