How to add new zebra index

== How to Add new MARC fields to Zebra indexes ==
I searched a lot for direct way to add new field to be searchable with zebra with no luck, so I thought it will be good idea to make one. 
Let's do it together step by step. 
===Step 1===
* You probably want to use Zebra with dom indexing. If you are not, read the following link: http://wiki.koha-community.org/wiki/Switching_to_dom_indexing
* Note: dom indexing has been the standard for quite some while. If you have a modern version of Koha, this will already be set up correctly.
===Step 2===
* In the file /etc/koha/zebradb/marc_defs/marc21/biblios/biblio-koha-indexdefs.xml add the following lines:
 <index_data_field tag="596" subfields="a">
 <target_index>Note596a:w</target_index>
 </index_data_field>
====Note====
* 596$a is the tag and subfield you want to make index for
* Note596a is the index name
* :w the type of index. The following types of indexes are pulled from https://software.indexdata.com/zebra/doc/querymodel-zebra.html#querymodel-pqf-apt-mapping
** :w Word
** :p Phrase
** :u URX/URL
** :n Numeric
** :0 Null bitmap
** :y Year
** :d Date
** :s Sort
===Step 3===
* In the file /etc/koha/zebradb/biblios/etc/bib1.att add the following line:
 att 65 Note596a
====Note====
The attribute number (65 in this example) can be selected from the Bib-1 attribute set (see http://www.loc.gov/z3950/agency/defns/bib1.html#use ) or a new attribute number can be made up.
Note596a is the index name.
===Step 4===
* In the file /etc/koha/zebradb/ccl.properties add the following line:
 Note596a 1=65
====Note====
Note596a is the index name.
1=65 is the CCL mapping.
===Step 5===
* Run the following command, you might need to adjust the paths to match those in your installation
 xsltproc /etc/koha/zebradb/xsl/koha-indexdefs-to-zebra.xsl /etc/koha/zebradb/marc_defs/marc21/biblios/biblio-koha-indexdefs.xml > /etc/koha/zebradb/marc_defs/marc21/biblios/biblio-zebra-indexdefs.xsl
xsltproc is a command line XSLT processor. This will overwrite biblio-zebra-indexdefs.xsl with your modified biblio-koha-indexdefs.xml using koha-indexdefs-to-zebra.xsl.
===Step 6===
* Run the following command 
 sudo koha-rebuild-zebra -b -f -v <yourInstance>
===Step 7===
* To add the new index in indexes select list in staff search go to 
 
 /usr/share/koha/intranet/htdocs/intranet-tmpl/prog/en/includes/
* Edit search_indexes.inc and add
 <option value="Note596a">Find the first manuscript</option>
before </select>
===Step 8===
* To add the new index in indexes select list in OPAC search go to 
 /usr/share/koha/opac/htdocs/opac-tmpl/prog/en/modules
or, in more recent versions, e.g. 20.n:
 /usr/share/koha/opac/htdocs/opac-tmpl/bootstrap/<lng>/modules, e.g.
 /usr/share/koha/opac/htdocs/opac-tmpl/bootstrap/en/modules
* Edit opac-advsearch.tt and add
 <option value="Note596a">Search the first manuscript</option> before </select>
===Step 9===
* To add the new index to Refine your search menu go to
 /usr/share/koha/lib/C4/
* Edit koha.pm go to sub getFacets add the following 
 
 {
 idx => 'Note596a',
 label => 'first of mono',
 tags => [ qw/ 596a / ],
 sep => ', ',
 },
Note
You'll also need to change the corresponding template file to make the new facet visible in OPAC and/or the staff interface.
===Step 10===
* In order for the index to be searchable when using CQL and maybe in general, you also need to add it to the list of indexes in Search.pm.
sub getIndexes{
 my @indexes = (
 # biblio indexes
 'ab',
 'Abstract',
 'acqdate',
 'allrecords',
 ...
 'Note596',
==See also==
* record.abs for MARC 21 bibliographic zebra indexes
* Understanding Zebra indexing
==Credits==
Special thanks for the Institute of Arabic manuscripts to support these steps
And also for Dr. Ahmed Abdalradi
I Hope to be useful for all 
Ashraf Brzy
IT manager 
Heliopolis University
--Ashraf.brzy 15:29, 15 February 2013 (EST)
It has been very helpful for us! Thank you dear Sir!
--Olli-Antti Kivilahti, www.vaarakirjastot.fi
Category:Zebra
Category:Tips_&_Tricks