Sitecore search with custom index - search

I'm attempting to use Sitecore Search with a custom index to filter and search items.
The items are product reviews and are all stored in a single folder with a ProductReview template.
+ Reviews
- Sample Review 1
- Sample Review 2
- Sample Review 3
The users will be able to filter items by category, subcategory and search by product name. So the form will look similar to this:
Category: [ Drop Down ]
Sub Category: [ Drop Down ]
Product name: [ Single line of Text ]
[ Search Button ]
I'm finding the documentation for defining indexes very thin. I'm trying to setup the index with the following properties.
The index web database
It should include only those three fields as they're all I'll need
Only items based on the review template will be indexed
The two category fields don't need to be tokenised
You can filter on the category fields
I'm not sure if I need a custom Analyzer or DatabaseCrawler and I haven't looked into making one at all.
This is what I have so far, however I haven't produced a working index yet:
<index id="reviews" type="Sitecore.Search.Index, Sitecore.Kernel">
<param desc="name">$(id)</param>
<param desc="folder">reviews</param>
<Analyzer ref="search/analyzer" />
<include hint="list:IncludeField">
<!-- Category -->
<fieldId>Category</fieldId>
<!-- Sub Category -->
<fieldId>Sub Category</fieldId>
<!-- Product Name -->
<fieldId>Product Name</fieldId>
</include>
<locations hint="list:AddCrawler">
<web type="Sitecore.Search.Crawlers.DatabaseCrawler, Sitecore.Kernel">
<Database>web</Database>
<!-- {GUID} -->
<Root>{GUID}</Root>
<Tags>web reviews</Tags>
<IndexAllFields>false</IndexAllFields>
<templates hint="list:AddTemplate">
< !-- Product Review -- >
<reviews>Product Review</reviews>
</templates>
</web>
</locations>
</index>
Any pointers would be greatly appreciated.
Edit
The two main things I'm looking for is:
How to index the category field without tokenizing it.
How to filter using that with the Lucine.net API.

Using the SitecoreSearchContrib (aka Advanced Database Crawler) library will make this much easier for you, both in indexing and searching. The library includes example configs that will make it more obvious to you how you should set things up.
Some initial pointers, even if you don't use SitecoreSearchContrib:
You'll want to index master as well, so that this functionality works in Preview mode. The above library will automatically search the correct database, based on the context the code is running in.
Your template inclusion in the index should be a template GUID.
Your field inclusions should be GUIDs as well.

Related

Narrow categories in Default Extended Multi Reference Editor in Backoffice to subcategories of a given category

I'm trying to filter the supercategories that can be referenced by a given product in Hybris Backoffice. For example if we have the following category structure:
CategoryA
SubCategoryA1
SubCategoryA2
CategoryB
SubCategoryB1
SubCategoryB2
Lets say I want my products to be able to reference only subcategories of CategoryB. In the documentation is given an example how to narrow the results and guarantee that all search results would have the same catalog version as the parent-object with a relation to the current editor.
<editorArea:attribute qualifier="supercategories">
<editorArea:editor-parameter>
<editorArea:name>referenceSearchCondition_catalogVersion</editorArea:name>
<editorArea:value>{parentObject.catalogVersion}</editorArea:value>
</editorArea:editor-parameter>
</editorArea:attribute>
What changes should I make in the configuration?
I guess I need to somehow restrict the available categories to be a subtype of a given supercategory.
Any help would be appreciated!
You can use restrictToType to filter by the specific type:
<wz:property qualifier="item">
<wz:editor-parameter>
<wz:name>restrictToType</wz:name>
<wz:value>Product</wz:value>
</wz:editor-parameter>
</wz:property>

BDC model/search connector and multi value field with refinment

BDC model:
My BDC model's entity has a property named Color.
The TypeName is specified as System.String[].
<TypeDescriptor Name="Color" TypeName="System.String[]">
<Properties>
<Property Name="RequiredInForms" Type="System.Boolean">false</Property>
</Properties>
</TypeDescriptor>
Database:
In my database (my BDC content source) I added column values like this one:
;#Blue;#Green;#Yellow;#
Search Schema
I created a new managed property and enabled multiple values (and also refinable - active, queryable, retrievable, safe).
Search Results
Filtering on a specific color via search works.
Example: RsExpAdvWorksProductColor:"blue"
Search Refinement
However I cannot refine on colors.
Adding a refiner on my Managed Property shows up like that:
Color
;#Blue;#Green;#Yellow;#
;#Green;#Yellow;#
;#Red;#Green;#Yellow;#Blue;#Black;#Cyan;#
Obviously the single values are not treated as such - the whole "string" of "special-delimiter" separated values is being shown as a refinment criteria.
Any hints?
Update 2015-03-20: I took a closer look at the built-in multi choice columns. In search results they are being returned as "Value1;#Value2;#" and so on. Basically there is a trailing Red;#Blue;# separator - no leading ;#Red;#Blue;# one. Much to my regret that didn't solve my problem.
Update 2015-03-20: Surprise surprise. It is in fact "working as designed" (like so many things in SharePoint :P). What I am looking for has to be dealt with separately. It behaves exactly the same with built-in multi choice fields so there is nothing wrong with my BDC/Search integration.
Regarding the refiner, have a look at the following links...
http://www.eliostruyf.com/part-6-create-multi-value-search-refiner-control/
https://hyankov.wordpress.com/2014/12/15/sharepoint-2013-refiner-multi-value-contains-instead-of-an-equals/

Getting lists definition a SharePoint site

I can see all the lists in a project site using <sharepoint site URL>/_vti_bin/ListData.svc/, but how can I get to see all the lists AND their columns? Is there a way of achieving this?
You can't do it in one query. You will need to go through one by one to get the list definition. For example, if you have a list called Calendar you can get the items and the fields by going to <sharepoint site URL>/_vti_bin/listdata.svc/Calendar. It will output the list items and for each entry is a tag called content within which is another tag called m:properties. This includes all the fields for the content type and their values.
<content type="application/xml">
<m:properties>
<d:ContentTypeID>0x010200FD20E8386D889748BDD9444F29251083</d:ContentTypeID>
<d:Title>Meeting with Bob</d:Title>
<d:Location>WebEx</d:Location>
<d:StartTime m:type="Edm.DateTime">2014-11-26T10:00:00</d:StartTime>
<d:EndTime m:type="Edm.DateTime">2014-11-26T10:30:00</d:EndTime>
<d:Description><div>Meeting with Bob</div></d:Description>
<d:AllDayEvent m:type="Edm.Boolean">false</d:AllDayEvent>
<d:Recurrence m:type="Edm.Boolean">false</d:Recurrence>
<d:Workspace m:type="Edm.Boolean">false</d:Workspace>
<d:CategoryValue>Meeting</d:CategoryValue>
<d:TeamMemberNameId m:type="Edm.Int32">138</d:TeamMemberNameId>
<d:Id m:type="Edm.Int32">1</d:Id>
<d:ContentType>Event</d:ContentType>
<d:Modified m:type="Edm.DateTime">2014-11-26T09:35:12</d:Modified>
<d:Created m:type="Edm.DateTime">2014-11-26T09:35:12</d:Created>
<d:CreatedById m:type="Edm.Int32">2990</d:CreatedById>
<d:ModifiedById m:type="Edm.Int32">2990</d:ModifiedById>
<d:Owshiddenversion m:type="Edm.Int32">1</d:Owshiddenversion>
<d:Version>1.0</d:Version>
<d:Path>/Lists/Calendar</d:Path>
</m:properties>
</content>

Default Content Type and Content type order using Folders in a Sharepoint List

I have a Custom List Definition (schema.xml) i have set up Site Columns (through A feature) and numerous content types also through a feature, this all works fine. I have a list definition (schema.xml) and i have put the content types at the top in the order i want them to appear (assuming that the top content type will be the default for the list - which is what i want)
NOTE: i HAVE set
EnableContentTypes="true"
here is an excerpt from my schema.xml
<ContentTypes>
<!-- Folder based content type -->
<ContentTypeRef ID="0x0120006ad66a4924644ac98d371a0e069c5d99" />
<!-- Item Based Content Type -->
<ContentTypeRef ID="0x0100a18ddd58b9384567bc776a3c5889ea77" />
<!-- ..... more content types ... -->
</ContentTypes>
The problem i have is that when a list is provisioned the folder based content type is always second in the list, and as a result is never the default in the list, the only way i can make it default is to remove all the other content type declarations which sort of defeats the object of having multiple content types. Is this ordering because of the way the list is provisioned or am i missing something tucked away deep in the SDK, any help gratefully accepted
Using a FeatureReceiver you can set the lists RootFolder.UniqueContentTypeOrder to an ordered list of ContentTypes which will then determine to Button order.
You can also leave out ContentTypes which you don't want to be available even though they are defined in the list. It's common to combine this with an event receiver which sets the button order (UniqueContentTypeOrder) of folders added, to guide people into a certain structure like only folders at the top level and no nested folders (or only x levels deep) or what you like.
Check the property bag. The list you're working on probably has a property called "vti_contenttypeorder", with the content type id's in the order they will show up when you go reordering them through the UI.
...building on #Renan answer - set your default Content Type declaratively.
Create a module, name it Property bags and add it to the web scope feature containing your list instance. The Elements.xml should contain the following:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<PropertyBag Url="<!--URL of your list instance here-->" ParentType="Folder" RootWebOnly="FALSE" AlwaysCreateFolder="TRUE" xmlns="http://schemas.microsoft.com/sharepoint/">
<Property Name="vti_contenttypeorder" Value="<!--Your custom Content Type ID here-->" Type="string" />
</PropertyBag>
</Elements>

How do you set the Filter for a SharePoint event receiver?

I've only recently noticed the Filter element in the definition file for a SharePoint event receiver:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers>
<Receiver>
...
<Filter />
</Receiver>
</Receivers>
</Elements>
The MSDN documentation for the SPEventReceiverDefinition.Filter property says that the value: "represents the filter for the SPListItem object". And includes the following remarks:
"Event handlers are registered at the site or site collection level to implement filtering to respond to list item events. Filtering allows multiple rules to be applied in sequence to limit the size of a list or some other dimension of that list. They are specified in persistent storage as name-value pairs in the form of assignment statements."
My question is: how can I set the value of the Filter? Would you use a CAML <Where> element?
I'm just curious at this stage. I don't have a reason to use this, but saw it and starting wondering. I searched through all event receiver definitions in SharePoint 12 'hive' folders and none had a filter applied.
Any filtering that I have done in event receivers, I have done in code.
I found a couple of liks that seem to indicate that the filter element is either reserved, or not implemented.
http://msdn.microsoft.com/en-us/library/dd340827(PROT.13).aspx
Maybe in MOSS 2010.

Resources