-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-schema-from-field-definitions.xsl
163 lines (157 loc) · 6.65 KB
/
update-schema-from-field-definitions.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:c="http://www.w3.org/ns/xproc-step"
xmlns:tei="http://www.tei-c.org/ns/1.0">
<!-- transform an existing Solr schema field list and a new "field definition" document into a Solr schema API update request-->
<xsl:param name="id"/>
<xsl:param name="solr-base-uri"/>
<xsl:template match="/">
<c:request method="post" href="{$solr-base-uri}schema">
<c:body content-type="application/json">
<xsl:text>{</xsl:text>
<!-- update "text_general" field type to use a regex-based tokenizer, rather than the "Standard" tokenizer which eats alchemical symbols -->
<xsl:text>
"replace-field-type": {
"name":"text_general",
"class":"solr.TextField",
"positionIncrementGap":"100",
"multiValued":true,
"indexAnalyzer":{
"tokenizer":{
"class":"solr.PatternTokenizerFactory",
"pattern":"[\\s|\\p{Punct}]+"
},
"filters":[
{
"class":"solr.StopFilterFactory",
"words":"stopwords.txt",
"ignoreCase":"true"
},
{
"class":"solr.LowerCaseFilterFactory"
}
]
},
"queryAnalyzer":{
"tokenizer":{
"class":"solr.PatternTokenizerFactory",
"pattern":"[\\s|\\p{Punct}]+"
},
"filters":[
{
"class":"solr.StopFilterFactory",
"words":"stopwords.txt",
"ignoreCase":"true"
},
{
"class":"solr.SynonymGraphFilterFactory",
"expand":"true",
"ignoreCase":"true",
"synonyms":"synonyms.txt"
},
{
"class":"solr.LowerCaseFilterFactory"
}
]
}
}
</xsl:text>
<!-- define a "metadata-summary" text field to hold an HTML formatted summary of the metadata (for display purposes, rather than searching) -->
<xsl:call-template name="define-field">
<xsl:with-param name="name" select=" 'metadata-summary' "/>
<xsl:with-param name="type" select=" 'display' "/><!-- "display" field is stored literally without any normalization -->
</xsl:call-template>
<!-- define the three main text fields "introduction", "normalized", and "diplomatic" -->
<xsl:call-template name="define-field">
<xsl:with-param name="name" select=" 'introduction' "/>
</xsl:call-template>
<xsl:call-template name="define-field">
<xsl:with-param name="name" select=" 'normalized' "/>
</xsl:call-template>
<xsl:call-template name="define-field">
<xsl:with-param name="name" select=" 'diplomatic' "/>
</xsl:call-template>
<xsl:call-template name="define-field">
<xsl:with-param name="name" select=" 'tei-header' "/>
</xsl:call-template>
<!-- define a "text" field that's a copy of "introduction", "normalized", and "diplomatic" -->
<xsl:call-template name="define-field">
<xsl:with-param name="name" select=" 'text' "/>
</xsl:call-template>
<!-- define "all" field that's a copy of everything in text and select teiHeader text nodes -->
<xsl:call-template name="define-field">
<xsl:with-param name="name" select=" 'all' "/>
</xsl:call-template>
<xsl:call-template name="add-copy-field">
<xsl:with-param name="source" select=" 'introduction' "/>
<xsl:with-param name="destination" select=" 'text' "/>
</xsl:call-template>
<xsl:call-template name="add-copy-field">
<xsl:with-param name="source" select=" 'normalized' "/>
<xsl:with-param name="destination" select=" 'text' "/>
</xsl:call-template>
<xsl:call-template name="add-copy-field">
<xsl:with-param name="source" select=" 'diplomatic' "/>
<xsl:with-param name="destination" select=" 'text' "/>
</xsl:call-template>
<xsl:call-template name="add-copy-field">
<xsl:with-param name="source" select=" 'introduction' "/>
<xsl:with-param name="destination" select=" 'all' "/>
</xsl:call-template>
<xsl:call-template name="add-copy-field">
<xsl:with-param name="source" select=" 'normalized' "/>
<xsl:with-param name="destination" select=" 'all' "/>
</xsl:call-template>
<xsl:call-template name="add-copy-field">
<xsl:with-param name="source" select=" 'diplomatic' "/>
<xsl:with-param name="destination" select=" 'all' "/>
</xsl:call-template>
<xsl:call-template name="add-copy-field">
<xsl:with-param name="source" select=" 'tei-header' "/>
<xsl:with-param name="destination" select=" 'all' "/>
</xsl:call-template>
<!-- define Solr fields corresponding to the facets and search fields defined in the "search-fields.xml" file -->
<xsl:for-each select="/*/fields/field">
<xsl:call-template name="define-field">
<xsl:with-param name="name" select="@name"/>
<xsl:with-param name="type" select="@type"/>
</xsl:call-template>
</xsl:for-each>
<xsl:text>}</xsl:text>
</c:body>
</c:request>
</xsl:template>
<xsl:template name="delete-field">
<xsl:param name="name"/>
<xsl:for-each select="/*/response/lst[@name='schema']/arr[@name='copyFields']/lst[str[@name='source'] = $name]">
, "delete-copy-field": { "source": "<xsl:value-of select="$name"/>", "dest": "<xsl:value-of select="str[@name='dest']"/>"}
</xsl:for-each>
<xsl:if test="/*/response/lst[@name='schema']/arr[@name='fields']/lst/str[@name='name'] = $name">
, "delete-field": {"name": "<xsl:value-of select="$name"/>"}
</xsl:if>
</xsl:template>
<xsl:template name="add-copy-field">
<xsl:param name="source"/>
<xsl:param name="destination"/>
<xsl:if test="/*/response/lst[@name='schema']/arr[@name='copyFields']/lst
[str[@name='source'] = $source and str[@name='dest'] = $destination]
">
, "delete-copy-field": { "source": "<xsl:value-of select="$source"/>", "dest": "<xsl:value-of select="$destination"/>"}
</xsl:if>
, "add-copy-field": { "source": "<xsl:value-of select="$source"/>", "dest": "<xsl:value-of select="$destination"/>"}
</xsl:template>
<xsl:template name="define-field">
<xsl:param name="name"/>
<xsl:param name="type"/>
<xsl:text>, </xsl:text>
<xsl:choose>
<xsl:when test="/*/response/lst[@name='schema']/arr[@name='fields']/lst/str[@name='name'] = $name">"replace-field"</xsl:when>
<xsl:otherwise>"add-field"</xsl:otherwise>
</xsl:choose>
<xsl:text>:{"name":"</xsl:text>
<xsl:value-of select="$name"/>
<!-- facets and sort and display fields are indexed as Solr "strings" type (i.e. untokenized), others are tokenized as "text_general" type -->
<xsl:text>","type":"</xsl:text>
<xsl:value-of select="if ($name='id' or $type='sort' or $type='display') then 'string' else if ($type='facet') then 'strings' else 'text_general'"/>
<xsl:text>"}</xsl:text>
</xsl:template>
</xsl:stylesheet>