6

I created a user content generated database in Sitecore where I will store my users and their comments.

I plan to have a subscriptions item bucket that will be stored in the web database (published from master, of course) which I want to reference from my user item in the ugc database.

The subscriptions field on my user will be a multilist with search but I am unable to come up with the correct query to reference the subscriptions in the web database for the list to populate. Is there an out of the box solution for referencing the web database in the source of a multilist with search field located in another database?

9

Yes - in the source property of your field item, you can use the parameter DatabaseName to set the name.

So you might have something like:

DataSource=/Sitecore/Content/MySite/Subscriptions&DatabaseName=web

You can also then add any other parameters for including/excluding templates etc...

| improve this answer | |
  • 1
    I got that to work with a multilist field but once I set it to a multilist with search, the list looks back at the ugc database. – Robert Michael Watson Oct 27 '17 at 22:03
6

No. Doesn't appear to be, out of the box

While my initial instinct was, that @Richard Seal's answer was correct, I don't actually see any documentation stating that this will work with search driven fields.

While proving a negative is impossible, I checked the following guides. None of them list &DatabaseName=xxx as a valid parameter for the search driven fields - only for the regular content driven ones.


Mentions DatabaseName only under the section "Fields without Search".


The possibility is mentioned briefly (but not otherwise documented) when discussing the StartSearchLocation argument.

To lookup which index should be searched. This is necessary as you could be using a sharded index approach or you could be search the Core or Web database.


Makes no mention of DatabaseName anywhere at all, in the entire document.


Mentions a lot of fixes and workarounds for this field. Database switching is not mentioned at all.


In the code

The code is not the easiest to follow, as it has been abstracted out a fair bit. But ultimately it comes down to this method located in Sitecore.Buckets.FieldTypes.SearchList:

ExtractStartSearchLocation(NameValueCollection values, Item currentItem)

The method deals with parsing the StartSearchLocation (which would also include database).

It calls up an internal method, MakeFilterQueryable(string locationFilter) that is tasked with resolving the location (checking for query: etc) - and ends up doing this:

locationFilter = obj.ID.ToString();

The key thing to note here is, it returns an ID. Not a DataUri or SitecoreUri that could include database information. Just an ID.

Further on, where it actually renders the results to show in the list results, we also find this code:

    foreach (string path in str3.Split(separator, (StringSplitOptions) num))
    {
      Item obj = Context.ContentDatabase.GetItem(path, language);
      string str4 = obj != null ? this.OutputString(obj) : path + " " + Translate.Text("[Item not found]");
      output.Write("<option value='" + path + "'>" + str4 + "</option>");
    }

Notice how it makes no effort to deal with the database issue. It just grabs the Context.ContentDatabase and gets on with it.

In summary

If there is a way to query across databases on this field OOTB, I can't see a way. I did find references to a db parameter in some parts of the code, but I don't see it actually being used in any of the sample code above.

| improve this answer | |
  • 1
    ah, so I could possibly create my own field that will accept DatabaseName in the query and parse it out in this. Thanks for your help and research! – Robert Michael Watson Oct 28 '17 at 20:24
  • I didn't really find an obviously easy way as I was digging through. Ultimately the field doesn't search a database, it searches an index. And how it arrives at what index to use, appears buried beneath quite many layers of abstraction. One thing though - the field should search correctly on an item IN your custom database. There is a slight chance you could cross database that item through via a Proxy - but it is only a very remote theory at this point, I did not have time to test this. – Mark Cassidy Oct 28 '17 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.