Domanda

I am using Lucene.NET with Sitecore for searching. I have created a custom Lucene index. Normally it is a one-to-one mapping between Sitecore fields and Lucene index fields. I would like to be able to take 2 fields and combine them in the Lucene index. Below is an example of my custom index definition. You will see a field called Activity and a field called Board. Then below it is an example of what I am trying to do - combine Activity and Board in to one field in the index. I just am not sure if this is possible and if so, what the syntax is for defining a combined field like this. Any ideas?

        <index id="reportsIndex" singleInstance="true" type="IOM.library.CustomIndexer, IOM">
            <param desc="name">$(id)</param>
            <template hint="list:AddTemplate">
                <template>{79EBE484-BAD6-4173-B80A-29AC7D734565}</template>
            </template>
            <fields hint="raw:AddField">
                <field target="Title">Title</field>
                <field target="SortTitle" storage="keyword">Title</field>
                <field target="ShortDescription">ShortDescription</field>
                <field target="FullDescription">FullDescription</field>
                <field target="Topic">Topic</field>
                <field target="Type">Type</field>
                <field target="ReleaseDate">ReleaseDate</field>
                <field target="Series">Series</field>
                <field target="Activity">Activity</field>
                <field target="Board">Board</field>
                <field target="MyCombinedField">??Activity, Board??</field>
            </fields>
        </index>

UPDATE: I tried to do what people have suggested and map 2 different Sitecore fields to the same Lucene field. However that doesn't seem to work. I tried the following:

<index id="reportsIndex" singleInstance="true" type="IOM.library.CustomIndexer, IOM">
  <param desc="name">$(id)</param>
  <template hint="list:AddTemplate">
    <template>{79EBE484-BAD6-4173-B80A-29AC7D734565}</template>
  </template>
  <fields hint="raw:AddField">
    <field target="Title">Title</field>
    <field target="Activity">Activity</field>
    <field target="Board">Board</field>
    <field target="MyCombinedField">Activity</field>
    <field target="MyCombinedField">Board</field>
  </fields>
</index>

When I look in IndexViewer this is what I see. If the content item has content for the Activity field then that will get populated in the "MyCombinedField" (since it is first). If the Activity field has no content then Lucene will populate the "MyCombinedField" with the Board content. But it never puts both field's content in to the MyCombinedField field. Am I doing something wrong?

È stato utile?

Soluzione

You must be using the old data indexes. Are you running pre Sitecore 6.5? You might consider rewriting your code to use Sitecore.Search.

Anyway you can index multiple Sitecore Fields in the same Lucene field by something similar to this:

<index id="system" singleInstance="true" type="Sitecore.Data.Indexing.Index, Sitecore.Kernel">
        <param desc="name">$(id)</param>
        <fields hint="raw:AddField">
          <field target="name">@name</field>
          <field target="name">__created</field>
          <field target="name">@tid</field>

In this case both the name of the item, the created date field and the template id is indexed in the same field.

So in short: Just create multiple field elements with the same target attribute

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top