How to add text to the _content field in a Solr index for a Sitecore implementation? - indexing

This is for a Sitecore 7.5 - Solr 4.7 implementation. I would like to be able to modify the text that is stored in the _content field in Solr. I believe that somehow that Sitecore aggregates all of the content fields for an item in the _content field in the index. (I think that is correct) At index time I would like to be able to write my own code that could potentially modify the text that is stored in the _content field in Solr. Is this possible? Any ideas how I would go about this?

_content is a computed field, which means the value is resolved at the point that the item is crawled. You'll see the computed field is defined in your config:
<field fieldName="_content" returnType="string" type="Sitecore.ContentSearch.ComputedFields.MediaItemContentExtractor,Sitecore.ContentSearch">
<mediaIndexing ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/mediaIndexing"/>
</field>
I recommend decompiling the class specified in the type attribute to see what it does. Then you can create your own computed field class (or inherit from that one), and replace the type attribute.
Computed fields are really quite simple to work with. They implement IComputedIndexField which requires a ComputeFieldValue method. The method accepts an argument of type IIndexable (in most cases the concrete class is an Item) and is called every time an item is crawled.
So in the ComputeFieldValue method you could cast the Iindexable to an Item, then return a concatenated string of all the field values you want to include from that item.
See here for more on computed fields:
http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2013/03/sitecore-7-computed-index-fields.aspx

From what I understand, you can add another (separate) _content field with your own IComputedIndexField implementation. The resulting values from all added fields with the same name are aggragated.
See also: https://kamsar.net/index.php/2014/05/indexing-subcontent/ and https://andrewwburns.com/2015/09/03/appending-to-the-_content-field-in-sitecore-search-7-2-and-7-5/

Related

Make a custom field as a range - like "Price" is as default in Bigcommerce

Hi I am new in Bigcommerce can I make any custom field or field as a Range and filter data base on that range.
Depending on what functionality you're needing from this custom field, you may be able to use it for the 'price range'. The value type is string, so this does not accept an array of multiple values, you can see this in our API reference documentation. If you're just needing to use custom fields to render the text on a template or so, this could work, but if you're needing more functionality from it, it'd be best to use something else.

Extract Collection index from ModelExpression

Is there a way to extract the current index of the collection within a TagHelper?
I want to implement a TagHelper to create a hidden input for "Index" property in a collection where specific indices are missing.
corresp article: this.
He simply extracted the index using regex (there). Is it the only way?

Illegal characters in OrientDB graph for property-type string

I use the graph version of OrientDB. Now I created a schema-less class, where I want to index a variable. This variable needs to become a property first. But when I try to create this property - of type string (or binary, or whatever) - it responds:
com.orientechnologies.orient.core.exception.OSchemaException: The database contains some schema-less data in the property 'clazz.clazz_name' that is not compatible with the type STRING. Fix those records and change the schema again [ONetworkProtocolHttpDb]
So I need to fix something, but what? What characters are illegal for a variable to become a property so that it can be indexed? (BTW, lists are also not an option)
There was indeed a problem I created.
I created a super-class where the property had to be created. One of the sub-classes inserted a List instead of a String. So when querying all vertices of sub-type
final Iterable<Vertex> iterable = this.graph.getVerticesOfClass("clazz");
I printed all types of clazz_name by vertex.getProperty("clazz_name").getClass().getName() where I saw OLinkedList. Reinserting those vertices fixed my problem.

RavenDb GenerateDocumentKey

I need to generate Id for child object of my document. What is the current syntax for generating document key?
session.Advanced.Conventions.GenerateDocumentKey(document) is not there anymore. I've found _documentSession.Advanced.DocumentStore.Conventions.GenerateDocumentKey method but its' signature is weird: I am okay with default key generation algorithm I just want to pass an object and receive an Id.
The default implementation of GenerateDocumentKey is to get the "dynamic tag name" for the class, and append a slash. For example, class Foo would turn into Foos/ which then goes through the HiLoKeyGenerator so that ids can be assigned on the client-side without having to consult the server each time.
If you really want this behavior, you could try to use the HiLoKeyGenerator on your own, but have you considered something simpler? I don't know what your model is, but if the child thing is fully owned by the containing document (which it should be, to be in the same document) have you have several much easier options:
Just use the index within the collection
Keep a int NextChildThingId property on the document and increment that every time you add a ChildThing
Just use a Guid, although those are no fun to read, type, look at, compare, or speak to someone over the phone.

override linq properties

I am using Linq to Sql that generated a data contract for a table. I have a date field in that table which is a non-nullable field. I need to override the auto generated property of the date field to return a specific value, something like
Get
if_dt<>date.minvalue
return _dt
else
return string.empty
End Get
Is it possible to override an autogenerated property in the designer.vb file using a partial class? I dont want to create a new property as it is currently being accessed in n number of places and I dont want to change it in every place.
No, you'll need to modify the .designer file or inherit from it and change the behavior of that property (but I guess the auto-generated property won't be virtual so you'll need to edit it anyway)