My adventures with Solr continue! I was working recently on a feature that required sorting results by the value of a field of a linked item.
After stumbling around with various LINQ statements that pretended that Solr was a RDBMS instead of an index (No, you cannot OrderBy a field you get in a join), Nick Wesselman pointed me in the direction of Computed Fields. (Thank you Nick, and thank you Twitter.) In short, the computed fields allow you to do the field lookup when you build the index, so your index query can work with a value built into the indexed document. (See this writeup by Martina Welander.) And be careful of the class and assembly name... if you get this wrong, you don't get an error, you just have your field skipped. Took awhile to debug that one.
Mindful of the Seven Deadly Sins of Sitecore 7, I attempted to avoid Sloth by building a custom index to house my additional fields. And that's where the fun started. My feature worked great if I built the index from the Sitecore Desktop, but when I created new items,either my index or the main index would get the update, but not both. What was very strange was that the log showed that both my index and the main index received the update.
Credit Sitecore Support for solving the mystery.(Thanks Evgeniy!) My mistake was following the pattern of putting all the indexes in the same collection. ("itembuckets" in the out of the box Sitecore.ContentSearch.Solr.Indexes.Config) This works for sitecore_master_index, sitecore_web_index, and sitecore_core_index because they are all built on separate databases, so the _uniqueid fields will never collide: "sitecore://master/{110d559f-dea5-42ea-9c1c-8a5df7e70ef9}?lang=en&ver=1" will never bump into "sitecore://web/{110d559f-dea5-42ea-9c1c-8a5df7e70ef9}?lang=en&ver=1". That no longer works if you are putting items into the collection twice.
So, moral of the story: Putting your indexes into the same collection is a bad idea, unless you can be sure that the _uniqueid values will be unique.
Very informative!
ReplyDeleteI was in search of something related solr and i find it here.....thanks for sharing
ReplyDelete