Sitecore Xpath comparing two fields - asp.net

I would like to have a query that looks at the name of its parent and then will navigate to the folder with the same sitename underneath the content folder and show the items underneath it in the multilist.
Basically the structure in the content tree looks as followed:
sitecore
content
Sitename1
(items that needs to be showed in the multilist)
Sitename2
(items that needs to be showed in the multilist)
medialibrary
Sitename1
PDF1 (with multiList with search)
Sitename2
PDF2 (with multiList with search)
Trouble starts when I would like to start comparing the "name" of the relative parent to the "name" of the child of the absolute path. In Xpath it would probably go something like it is described within: Compare attribute values using Xpath
In this case I had the following query up until now:
/sitecore/content/*[ancestor-or-self::*[##templateid='{Template Id of Sitename}']=##name and ##templateid='{Template Id of Sitename}']
This query returns Sitename1 and Sitename2.
Funny thing is that if I replace "ancestor-or-se.." or "##name" part bij "Sitename1", like so:
/sitecore/content/*['Sitename1'=##name and ##templateid='{Template Id of Sitename}']
..and..
/sitecore/content/*[./ancestor-or-self::*[##templateid='{Template Id of Sitename}']='DSW' and ##templateid='{Template Id of Sitename}']
I get the wanted result: Sitename1.
Btw I'm using the build-in xpath builder for now, before it paste the query into the "multilist with search."
Any help would be appreciated.
Edit:
I think I found out that when I start the relative query (the "./ancestor::..." part) it actually is relative to the item where I ended up with the absolute query. So I should have the following query:
./ancestor-or-self::*[##templateid='{Template Id of Sitename}' and ##name=ancestor::*[##templateid='{Template Id of root item aka "sitecore"}']//*[##templateid={Template Id of Sitename}]]
Here I get the error "Object must be of type String," which is probably because of the following part of the previous query:
##name=ancestor::*[##templateid='{Template Id of root item aka "sitecore"}']//*[##templateid={Template Id of Sitename}]
The right part of this doesn't solve to a string. So the question remains, how to extract pure the string out of a sitecore item using sitecore xpath in order to be able to make a comparison.

I figured out that Sitecore doesn't support subqueries at least for fast queries, I think same applies to normal ones (see also: "Subqueries are not supported" in here ). Which now lead me to using simple code where I perform two queries. A very simple way to do it is to inherit from IDatasource (in the sitecore.buckets.dll), you will need to write "code:{fullpath to class}, assemblyname.dll" (See also: here)

Related

How to use cursors for navigating to previous pages using GQL and the new gcloud-java API?

I'm using the new gcloud-java API (https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-datastore/src/main/java/com/google/cloud/datastore) for working with the Cloud Datastore. My specific question is on using GQL for pagination with cursors. I was able to page through the results one page at a time in the forward direction using cursors, but not having any luck with paging backwards.
Example Scenario:
Let's say I've 20 entities in a Kind with IDs 1 through 20. I have a page size of 5. Once I'm on the 3rd page (IDs 11 through 15), if I need to go one page back; i.e. retrieve IDs 6 through 10, what would be the correct GQL/sample code? Again, I prefer not to use offset with a number, but would like to use Cursors.
From what I can tell (actually tested), it looks like one needs to keep track of Start/End cursors for each page as they navigate in the forward direction, then use the saved cursors when there is a need to go back. I just want to make sure if this is the correct/only way or there is a simpler way to accomplish this.
Thanks in advance for your help.
If you add to your original query a sort by key (appended to the end of your "order by" clause), you should be able to reverse each property's sort order and use the latest cursor from your original query to get results in reverse.
Suppose you've iterated through some of the values from your forward query's QueryResults. You can call QueryResults's cursorAfter() method, which will return a cursor pointing right after the last result you saw from your original query. Now you can issue a new query (with the opposite sort order on each property, including the key property) using that cursor as the start cursor. You'll probably want to skip the first result, since it will be the last result you saw from the original query.

How can I add a conditional field

I would like to have one field appear conditionally based on the value of another. How should I go about achieving this in dexterity?
E.g. One field is a boolean: Is the resource for sale?
If this is set as "yes" I'd like the next field to show up, being an integer- the price of the resource.
If I had to guess, I'd start hacking a javascript solution but I'm assuming there is a technique for doing it in an organised manner, but I can't find anything.
I should also mention that I am doing this to simplify the process of searching through this content later (using eea.facetednav) in which I don't know how to have a boolean search interface return results based on if the integer is > 0.

Hiding a specific object of a catalog results

There is a way to hide a specific object of my catalog results?
I have a configuration file that I don't want to show.
I'm filtering by id, but it seems so ugly.
from Products.CMFCore.utils import getToolByName
def search(context):
catalog = getToolByName(context, 'portal_catalog')
items = catalog()
for item in items:
if item.id != "config_file":
'do something'
If you are already hiding the object from the navigation tree, you can filter on the same property by testing for exclude_from_nav:
items = catalog()
for item in items:
if item.exclude_from_nav:
continue
# do something with all objects *not* excluded from navigation.
It is harder to filter out things that don't match a criteria. Using a test on the brain object like the above is a perfectly fine way to remove a small subset from your result set.
If you need handle a larger percentage of 'exceptions' you'll need to rethink your architecture, perhaps.
With Products.AdvancedQuery you can create advanced queries and filtering on catalog results. See also this how to.
In the general case, setting a content item's expiration date to some past date hides it from search results (so long as the user does not have the Access inactive portal content permission).
It's an easy way to hide pieces of content that should be visible to all, but that you don't want cluttering up search results e.g. a Document that serves as the homepage.
I always use 1st Jan 2001 as the date so I can easily recognise when I've used this little 'hack'.

Using / in query strings

I am trying to use query strings in ASP.NET. I have a requirement of the following format
http://localhost/website/1/?callback=?
Here 1 denotes the ID of the profile. This means some info from id=1 will be fetched through the string
If this would have been website/2/?callback=? , then the id would be 2. My questions is to how do I use this /id/ as a query string so it can be used to fetch the profile ID. This was my first preference to use /id/ format otherwise I could look into fetching using two ?'s
If the id =1, I want to fetch ID=1 particulars from DB on this page. http://localhost/website/1/?callback=?
In your case the ID is in the PATH, not the query string. You can access the path via Request.Path in an ASPX page. From there you would need to do some string parsing to get at the portion of the path where you expect the ID to be.
In your case I would probably use something like int.Parse(Request.Path.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries)[1]), but please note that I've made that line pretty dense for brevity's sake. For starters, you should use int.TryParse() instead of int.Parse(). This code assumes that the ID will always be in the same place in the url. For example, it will work for "/website/2/" and "/user/2/", but not for "/website/somethingelse/2/".
UriTemplate might be a good choice for that sort of parsing. Not to mention, probably a bit more clear and explicit about what's happening.
Check out: http://msdn.microsoft.com/en-us/library/system.uritemplate(v=VS.90).aspx

Comma Separated check in asp.net

How to search every word separated by comma in textbox
Please refer above post
Its Working perfectly...But i have small issues.. when i enter in text box like c,c++,4-5 yrs it have to check in database like either c,c++ skills and 4-5 yrs experiecne and then the reult has to be shown... Burt as per ur query it just show results whether any one of keyword satisfy database ...I want to compare year also how? –
If you want that behavior, you have to program that behavior. One design is to have multiple input boxes: one where you check if any of the words exist, another where you check that all of the words exist. (Perhaps even another for an exact phrase match.) Another design possibility would be for you to develop a syntax to indicate optional and required words all within a single input box. The point is it is up to you.
After you've decided on a design, then you could write code that builds your query based on or matches on the optional words and and matches on the required. Something like this pseudocode
Select * From Table Where
(Field Like OptionalWord1 Or Field Like OptionalWord2 Or Field Like OptionalWord3)
And Field Like RequiredWord1
And Field Like RequiredWord2
(etc.)

Resources