Skip to content

Commit 8cf9226

Browse files
Merge pull request #65 from icatproject/v4.0.0
Bump version to 4.0.0-SNAPSHOT, write 4.0.0 release-notes
2 parents 4f41ced + 5c4dab5 commit 8cf9226

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>org.icatproject</groupId>
55
<artifactId>icat.lucene</artifactId>
6-
<version>3.0.1-SNAPSHOT</version>
6+
<version>4.0.0-SNAPSHOT</version>
77
<packaging>war</packaging>
88
<name>ICAT Lucene</name>
99

@@ -114,7 +114,7 @@
114114
<dependency>
115115
<groupId>org.icatproject</groupId>
116116
<artifactId>icat.utils</artifactId>
117-
<version>4.17.0</version>
117+
<version>4.17.1</version>
118118
</dependency>
119119

120120
<dependency>

src/main/java/org/icatproject/lucene/Lucene.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ public void lock(@PathParam("entityName") String entityName, @QueryParam("minId"
11791179
IndexSearcher searcher = shardBucket.searcherManager.acquire();
11801180
try {
11811181
Query query;
1182+
Sort sort = new Sort(new SortedNumericSortField("id", Type.LONG, true));
11821183
if (minId == null && maxId == null) {
11831184
query = new MatchAllDocsQuery();
11841185
} else {
@@ -1190,7 +1191,7 @@ public void lock(@PathParam("entityName") String entityName, @QueryParam("minId"
11901191
}
11911192
query = LongPoint.newRangeQuery("id", minId + 1, maxId);
11921193
}
1193-
TopDocs topDoc = searcher.search(query, 1);
1194+
TopDocs topDoc = searcher.search(query, 1, sort);
11941195
if (topDoc.scoreDocs.length != 0) {
11951196
// If we have any results in the populating range, unlock and throw
11961197
bucket.locked.compareAndSet(true, false);
@@ -1627,7 +1628,7 @@ private void encodeSearchAfterField(JsonGenerator gen, SortField sortField, Scor
16271628
* @param json Key value pairs of fields.
16281629
* @return Lucene Document.
16291630
*/
1630-
private Document parseDocument(JsonObject json) {
1631+
public Document parseDocument(JsonObject json) {
16311632
Document document = new Document();
16321633
for (String key : json.keySet()) {
16331634
Field field = new Field(json, key, key, facetFields);

src/site/xhtml/release-notes.xhtml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66

77
<h1>ICAT Lucene Server Release Notes</h1>
88

9+
<h2>4.0.0</h2>
10+
<p>In addition to the bugfixes, the change to how the location field is parsed will require a re-index to ensure that searches using the new syntax match historic Documents.</p>
11+
<ul>
12+
<li>Bugfix: handle an unexpectedly closed IndexWriter</li>
13+
<li>Bugfix: use RAFDirectory and AsynchronousFileChannel for locks</li>
14+
<li>Bugfix: use IcatSynonymAnalyzer to write Documents</li>
15+
<li>Feature: expand location into location, location.exact, location.fileName</li>
16+
<li>Feature: sort by ICAT id to return highest id when failing to lock index</li>
17+
<li>Feature: allow automatic commits to be disabled by config</li>
18+
</ul>
19+
920
<h2>3.0.0</h2>
1021
<p>Significant changes to the functionality and performance of searches:</p>
1122
<ul>

src/test/java/icat/lucene/TestLucene.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.lucene.index.IndexWriter;
3636
import org.apache.lucene.index.IndexWriterConfig;
3737
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
38+
import org.apache.lucene.index.IndexableField;
3839
import org.apache.lucene.index.Term;
3940
import org.apache.lucene.queryparser.flexible.core.QueryNodeException;
4041
import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser;
@@ -60,7 +61,7 @@
6061
import org.icatproject.lucene.analyzers.IcatAnalyzer;
6162
import org.icatproject.lucene.analyzers.IcatSynonymAnalyzer;
6263
import org.icatproject.lucene.exceptions.LuceneException;
63-
import org.junit.Ignore;
64+
import org.icatproject.utils.IcatUnits;
6465
import org.junit.Test;
6566

6667
import jakarta.json.Json;
@@ -410,6 +411,24 @@ public void testLocationFields() throws IOException, QueryNodeException {
410411
checkHits(datafileSearcher, DocumentMapping.datafileParser, "+\"/dls/i00/data/2000\" +screen* +(AB00 DE00) +txt", 2L);
411412
}
412413

414+
@Test
415+
public void testParseDocument() {
416+
// Ensure that we encode units correctly when SI conversion fails
417+
Lucene lucene = new Lucene();
418+
lucene.icatUnits = new IcatUnits();
419+
JsonObjectBuilder builder = Json.createObjectBuilder();
420+
builder.add("type.units", "N/A");
421+
builder.add("numericValue", 1.);
422+
Document document = lucene.parseDocument(builder.build());
423+
assertEquals(4, document.getFields().size());
424+
assertEquals("N/A", document.getField("type.units").stringValue());
425+
// Unlike strings, numbers are represented by different fields for different purposes
426+
IndexableField[] fields = document.getFields("numericValue");
427+
assertEquals(4607182418800017408L, fields[0].numericValue().longValue()); // For faceting, the double value is encoded as a long
428+
assertEquals(1., fields[1].numericValue().doubleValue(), 0); // For querying, encoded as double
429+
assertEquals(1., fields[2].numericValue().doubleValue(), 0); // Stored value for returning documents, encoded as a double
430+
}
431+
413432
private void checkHits(IndexSearcher searcher, StandardQueryParser parser, String queryString, long expected) throws QueryNodeException, IOException {
414433
queryString = SearchBucket.escapePath(queryString);
415434
Query query = parser.parse(queryString, null);

0 commit comments

Comments
 (0)