Skip to content

Commit efec13f

Browse files
committed
First results servlet OK
1 parent 27a045f commit efec13f

14 files changed

Lines changed: 814 additions & 199 deletions

File tree

common/src/java/com/github/oeuvres/alix/lucene/DocHilite.java

Lines changed: 543 additions & 0 deletions
Large diffs are not rendered by default.

common/src/java/com/github/oeuvres/alix/lucene/HtmlResults.java

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

test/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
<version>${jmh.version}</version>
6262
<scope>provided</scope>
6363
</dependency>
64+
<dependency>
65+
<groupId>com.github.oeuvres</groupId>
66+
<artifactId>alix-web</artifactId>
67+
<version>1.0.0</version>
68+
</dependency>
6469
</dependencies>
6570

6671
<build>

test/src/main/java/com/github/oeuvres/alix/lucene/SpanDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static void main(final String[] args) throws IOException {
126126
.doclineFieldName("docline")
127127
.docLimit(20)
128128
.spanLimit(5)
129-
.wordsAround(20);
129+
.ctx(20);
130130
SpanWalker walker = new SpanWalker(searcher, query, null, results);
131131
writer.append(String.valueOf(walker.hits())).append(" hits " + (System.currentTimeMillis() - t0) + "ms \n");
132132
int nextDoc = walker.walk(0);

test/src/test/java/com/github/oeuvres/alix/lucene/search/LocutionTest.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/src/test/java/com/github/oeuvres/alix/lucene/search/WordSuggestTest.java

Lines changed: 0 additions & 109 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.github.oeuvres.alix.web.util;
2+
3+
import java.io.IOException;
4+
5+
public class HttpParsTest
6+
{
7+
public static void main(final String[] args) throws IOException
8+
{
9+
System.out.println(HttpPars.encodeQueryComponent("ab\nab"));
10+
}
11+
}

web/src/main/java/com/github/oeuvres/alix/web/AlixServlet.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void destroy()
9797
private void registerOps()
9898
{
9999
// register(new OpSearch());
100-
// register(new OpKwic());
100+
register(new OpConc());
101101
// register(new OpCooc());
102102
// register(new OpFreqs());
103103
register(new OpTerms());
@@ -128,7 +128,7 @@ protected void doGet(
128128
final String indexName = segments[1];
129129
final LuceneIndex index = indices.get(indexName);
130130
if (index == null) {
131-
sendError(resp, 404, "Unknown index: " + indexName);
131+
jsonError(resp, 404, "Unknown index: " + indexName);
132132
return;
133133
}
134134

@@ -144,7 +144,7 @@ protected void doGet(
144144

145145
final Op op = ops.get(opName);
146146
if (op == null) {
147-
sendError(resp, 404, "Unknown operation: " + opName);
147+
jsonError(resp, 404, "Unknown operation: " + opName);
148148
return;
149149
}
150150

@@ -385,7 +385,7 @@ private Path resolveConfigDir(final ServletConfig config) throws ServletExceptio
385385
* each carrying {@code status} and {@code message}.
386386
* </p>
387387
*/
388-
static void sendError(
388+
static void jsonError(
389389
final HttpServletResponse resp,
390390
final int status,
391391
final String message

0 commit comments

Comments
 (0)