@@ -37,7 +37,7 @@ public class HtmlResults extends ResultsListener
3737 /** Stored field providing the one-line title rendered as a document heading. */
3838 private String doclineFieldName = "docline" ;
3939 /** Number of words of context to show on each side of a span match. */
40- private int wordsAround = 10 ;
40+ private int ctx = 10 ;
4141 /** Maximum number of spans to emit per document; {@code -1} = unlimited. */
4242 private int spanLimit = -1 ;
4343 /** Maximum number of documents to emit; {@code -1} = unlimited. */
@@ -57,6 +57,9 @@ public class HtmlResults extends ResultsListener
5757 private int lastDocId = -1 ;
5858 /** Reusable buffer for assembling each concordance line. */
5959 private final Detagger detagger = new Detagger (Set .of ("i" , "em" ));
60+ private String hrefBase = "" ;
61+ private String hrefExt = "" ;
62+ private String hrefSearch = "" ;
6063
6164
6265 /**
@@ -66,7 +69,7 @@ public class HtmlResults extends ResultsListener
6669 * @param storedFields access to stored document fields
6770 * @param contentField name of the stored field holding the document HTML content
6871 */
69- HtmlResults (
72+ public HtmlResults (
7073 final Writer writer ,
7174 final StoredFields storedFields ,
7275 final String contentField
@@ -77,6 +80,29 @@ public class HtmlResults extends ResultsListener
7780 this .contentFieldName = contentField ;
7881 }
7982
83+ public int ctx ()
84+ {
85+ return ctx ;
86+ }
87+
88+ public HtmlResults ctx (final int ctx )
89+ {
90+ this .ctx = ctx ;
91+ return this ;
92+ }
93+
94+ public int docLimit ()
95+ {
96+ return this .docLimit ;
97+ }
98+
99+ /** Sets the maximum number of documents to emit; {@code -1} = unlimited. */
100+ public HtmlResults docLimit (final int docLimit )
101+ {
102+ this .docLimit = docLimit ;
103+ return this ;
104+ }
105+
80106 /** Sets the name of the stored field used as document heading. */
81107 public HtmlResults doclineFieldName (final String doclineFieldName )
82108 {
@@ -88,37 +114,52 @@ public String doclineFieldName()
88114 {
89115 return this .doclineFieldName ;
90116 }
117+
118+ public String hrefBase ()
119+ {
120+ return this .hrefBase ;
121+ }
91122
92- /** Sets the maximum number of spans emitted per document; {@code -1} = unlimited. */
93- public HtmlResults spanLimit (final int spanLimit )
123+ public HtmlResults hrefBase (final String hrefBase )
94124 {
95- this .spanLimit = spanLimit ;
125+ this .hrefBase = hrefBase ;
96126 return this ;
97127 }
98-
99- public int spanLimit ()
128+
129+ public String hrefExt ()
100130 {
101- return this .spanLimit ;
131+ return this .hrefExt ;
102132 }
103133
104- /** Sets the maximum number of documents to emit; {@code -1} = unlimited. */
105- public HtmlResults docLimit (final int docLimit )
134+ public HtmlResults hrefExt (final String hrefExt )
106135 {
107- this .docLimit = docLimit ;
136+ this .hrefExt = hrefExt ;
108137 return this ;
109138 }
110139
111- public int docLimit ()
140+ public String hrefSearch ()
112141 {
113- return this .docLimit ;
142+ return this .hrefSearch ;
114143 }
115-
116- public HtmlResults wordsAround (final int wordsAround )
144+
145+ public HtmlResults hrefSearch (final String hrefSearch )
117146 {
118- this .wordsAround = wordsAround ;
147+ this .hrefSearch = hrefSearch ;
119148 return this ;
120149 }
121150
151+ /** Sets the maximum number of spans emitted per document; {@code -1} = unlimited. */
152+ public HtmlResults spanLimit (final int spanLimit )
153+ {
154+ this .spanLimit = spanLimit ;
155+ return this ;
156+ }
157+
158+ public int spanLimit ()
159+ {
160+ return this .spanLimit ;
161+ }
162+
122163 @ Override
123164 public boolean wantsMoreDocs ()
124165 {
@@ -143,8 +184,15 @@ public void startDoc(int docId) throws IOException
143184 if (doclineFieldName != null ) {
144185 final String docline = doc .get (doclineFieldName );
145186 if (docline != null ) {
146- writer .append ("<h2><a href=\" " ).append (id ).append ("\" >" )
147- .append (docline ).append ("</a></h2>\n " );
187+ writer
188+ .append ("<h2><a href=\" " )
189+ .append (hrefBase )
190+ .append (id )
191+ .append (hrefExt )
192+ .append (hrefSearch )
193+ .append ("\" >" )
194+ .append (docline )
195+ .append ("</a></h2>\n " );
148196 }
149197 }
150198 }
@@ -161,10 +209,16 @@ public boolean span(OffsetsCollector collector) throws IOException
161209
162210 // Opening tag written first: no buffer needed, no prepend.
163211 writer .append ("<li class=\" hit span\" ><a href=\" " )
164- .append (id ).append ("#span" ).append (String .valueOf (spanCount )).append ("\" >" );
212+ .append (hrefBase )
213+ .append (id )
214+ .append (hrefExt )
215+ .append (hrefSearch )
216+ .append ("#span" )
217+ .append (String .valueOf (spanCount ))
218+ .append ("\" >" );
165219
166220 // Left context: locate boundary, then detag forward directly into writer.
167- final int left = Markup .leftBoundary (content , collector .startOffset (0 ) - 1 , wordsAround , -1 );
221+ final int left = Markup .leftBoundary (content , collector .startOffset (0 ) - 1 , ctx , -1 );
168222 detagger .detag (content , left , collector .startOffset (0 ), writer );
169223
170224 // Pivot terms with inter-term text between them.
@@ -179,7 +233,7 @@ public boolean span(OffsetsCollector collector) throws IOException
179233 }
180234
181235 // Right context.
182- final int right = Markup .rightBoundary (content , collector .endOffset (termCount - 1 ), wordsAround , -1 );
236+ final int right = Markup .rightBoundary (content , collector .endOffset (termCount - 1 ), ctx , -1 );
183237 detagger .detag (content , collector .endOffset (termCount - 1 ), right , writer );
184238 writer .append ("</a></li>\n " );
185239 return spanLimit < 0 || spanCount < spanLimit ;
0 commit comments