Merge remote-tracking branch 'origin/branch_6x' into branch_6x

This commit is contained in:
Noble Paul 2016-04-15 19:11:17 +05:30
commit b2a9a787b4
7 changed files with 203 additions and 88 deletions

View File

@ -84,6 +84,9 @@ Other
* LUCENE-7205: Remove repeated nl.getLength() calls in
(Boolean|DisjunctionMax|FuzzyLikeThis)QueryBuilder. (Christine Poerschke)
* LUCENE-7210: Make TestCore*Parser's analyzer choice override-able
(Christine Poerschke, Daniel Collins)
======================= Lucene 6.0.0 =======================
System Requirements

View File

@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.lucene.queryparser.xml;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.LegacyIntField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
class CoreParserTestIndexData implements Closeable {
final Directory dir;
final IndexReader reader;
final IndexSearcher searcher;
CoreParserTestIndexData(Analyzer analyzer) throws Exception {
BufferedReader d = new BufferedReader(new InputStreamReader(
TestCoreParser.class.getResourceAsStream("reuters21578.txt"), StandardCharsets.US_ASCII));
dir = LuceneTestCase.newDirectory();
IndexWriter writer = new IndexWriter(dir, LuceneTestCase.newIndexWriterConfig(analyzer));
String line = d.readLine();
while (line != null) {
int endOfDate = line.indexOf('\t');
String date = line.substring(0, endOfDate).trim();
String content = line.substring(endOfDate).trim();
Document doc = new Document();
doc.add(LuceneTestCase.newTextField("date", date, Field.Store.YES));
doc.add(LuceneTestCase.newTextField("contents", content, Field.Store.YES));
doc.add(new LegacyIntField("date2", Integer.valueOf(date), Field.Store.NO));
doc.add(new IntPoint("date3", Integer.valueOf(date)));
writer.addDocument(doc);
line = d.readLine();
}
d.close();
writer.close();
reader = DirectoryReader.open(dir);
searcher = LuceneTestCase.newSearcher(reader, false);
}
@Override
public void close() throws IOException {
reader.close();
dir.close();
}
}

View File

@ -21,76 +21,42 @@ import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenFilter;
import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.LegacyIntField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.DisjunctionMaxQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
public class TestCoreParser extends LuceneTestCase {
final private static String defaultField = "contents";
private static Analyzer analyzer;
private static CoreParser coreParser;
private static Directory dir;
private static IndexReader reader;
private static IndexSearcher searcher;
@BeforeClass
public static void beforeClass() throws Exception {
private static CoreParserTestIndexData indexData;
protected Analyzer newAnalyzer() {
// TODO: rewrite test (this needs to set QueryParser.enablePositionIncrements, too, for work with CURRENT):
analyzer = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, MockTokenFilter.ENGLISH_STOPSET);
//initialize the parser
coreParser = new CoreParser(defaultField, analyzer);
BufferedReader d = new BufferedReader(new InputStreamReader(
TestCoreParser.class.getResourceAsStream("reuters21578.txt"), StandardCharsets.US_ASCII));
dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(analyzer));
String line = d.readLine();
while (line != null) {
int endOfDate = line.indexOf('\t');
String date = line.substring(0, endOfDate).trim();
String content = line.substring(endOfDate).trim();
Document doc = new Document();
doc.add(newTextField("date", date, Field.Store.YES));
doc.add(newTextField("contents", content, Field.Store.YES));
doc.add(new LegacyIntField("date2", Integer.valueOf(date), Field.Store.NO));
doc.add(new IntPoint("date3", Integer.valueOf(date)));
writer.addDocument(doc);
line = d.readLine();
}
d.close();
writer.close();
reader = DirectoryReader.open(dir);
searcher = newSearcher(reader, false);
return new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, MockTokenFilter.ENGLISH_STOPSET);
}
protected CoreParser newCoreParser(String defaultField, Analyzer analyzer) {
return new CoreParser(defaultField, analyzer);
}
@AfterClass
public static void afterClass() throws Exception {
reader.close();
dir.close();
reader = null;
searcher = null;
dir = null;
if (indexData != null) {
indexData.close();
indexData = null;
}
coreParser = null;
analyzer = null;
}
@ -133,7 +99,7 @@ public class TestCoreParser extends LuceneTestCase {
public void testCustomFieldUserQueryXML() throws ParserException, IOException {
Query q = parse("UserInputQueryCustomField.xml");
int h = searcher.search(q, 1000).totalHits;
int h = searcher().search(q, 1000).totalHits;
assertEquals("UserInputQueryCustomField should produce 0 result ", 0, h);
}
@ -179,13 +145,38 @@ public class TestCoreParser extends LuceneTestCase {
}
protected Analyzer analyzer() {
if (analyzer == null) {
analyzer = newAnalyzer();
}
return analyzer;
}
protected CoreParser coreParser() {
if (coreParser == null) {
coreParser = newCoreParser(defaultField, analyzer());
}
return coreParser;
}
private CoreParserTestIndexData indexData() {
if (indexData == null) {
try {
indexData = new CoreParserTestIndexData(analyzer());
} catch (Exception e) {
fail("caught Exception "+e);
}
}
return indexData;
}
protected IndexReader reader() {
return indexData().reader;
}
protected IndexSearcher searcher() {
return indexData().searcher;
}
protected Query parse(String xmlFileName) throws ParserException, IOException {
try (InputStream xmlStream = TestCoreParser.class.getResourceAsStream(xmlFileName)) {
assertNotNull("Test XML file " + xmlFileName + " cannot be found", xmlStream);
@ -195,13 +186,14 @@ public class TestCoreParser extends LuceneTestCase {
}
protected Query rewrite(Query q) throws IOException {
return q.rewrite(reader);
return q.rewrite(reader());
}
protected void dumpResults(String qType, Query q, int numDocs) throws IOException {
if (VERBOSE) {
System.out.println("TEST: qType=" + qType + " query=" + q + " numDocs=" + numDocs);
}
final IndexSearcher searcher = searcher();
TopDocs hits = searcher.search(q, numDocs);
assertTrue(qType + " should produce results ", hits.totalHits > 0);
if (VERBOSE) {

View File

@ -16,11 +16,15 @@
*/
package org.apache.lucene.queryparser.xml;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.Query;
public class TestCorePlusExtensionsParser extends TestCorePlusQueriesParser {
private CoreParser corePlusExtensionsParser;
@Override
protected CoreParser newCoreParser(String defaultField, Analyzer analyzer) {
return new CorePlusExtensionsParser(defaultField, analyzer);
}
public void testFuzzyLikeThisQueryXML() throws Exception {
Query q = parse("FuzzyLikeThisQuery.xml");
@ -31,16 +35,4 @@ public class TestCorePlusExtensionsParser extends TestCorePlusQueriesParser {
dumpResults("FuzzyLikeThis", q, 5);
}
//================= Helper methods ===================================
@Override
protected CoreParser coreParser() {
if (corePlusExtensionsParser == null) {
corePlusExtensionsParser = new CorePlusExtensionsParser(
super.defaultField(),
super.analyzer());
}
return corePlusExtensionsParser;
}
}

View File

@ -16,11 +16,15 @@
*/
package org.apache.lucene.queryparser.xml;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.Query;
public class TestCorePlusQueriesParser extends TestCoreParser {
private CoreParser corePlusQueriesParser;
@Override
protected CoreParser newCoreParser(String defaultField, Analyzer analyzer) {
return new CorePlusQueriesParser(defaultField, analyzer);
}
public void testLikeThisQueryXML() throws Exception {
Query q = parse("LikeThisQuery.xml");
@ -32,16 +36,4 @@ public class TestCorePlusQueriesParser extends TestCoreParser {
dumpResults("boosting ", q, 5);
}
//================= Helper methods ===================================
@Override
protected CoreParser coreParser() {
if (corePlusQueriesParser == null) {
corePlusQueriesParser = new CorePlusQueriesParser(
super.defaultField(),
super.analyzer());
}
return corePlusQueriesParser;
}
}

View File

@ -258,15 +258,7 @@ class GeoConcavePolygon extends GeoBasePolygon {
@Override
public boolean isWithin(final double x, final double y, final double z) {
// If present within *any* plane, then it is a member, except where there are holes.
boolean isMember = false;
for (final SidedPlane edge : edges) {
if (edge.isWithin(x, y, z)) {
isMember = true;
break;
}
}
if (isMember == false) {
if (!localIsWithin(x, y, z)) {
return false;
}
if (holes != null) {
@ -279,6 +271,22 @@ class GeoConcavePolygon extends GeoBasePolygon {
return true;
}
protected boolean localIsWithin(final Vector v) {
return localIsWithin(v.x, v.y, v.z);
}
protected boolean localIsWithin(final double x, final double y, final double z) {
// If present within *any* plane, then it is a member, except where there are holes.
boolean isMember = false;
for (final SidedPlane edge : edges) {
if (edge.isWithin(x, y, z)) {
isMember = true;
break;
}
}
return isMember;
}
@Override
public GeoPoint[] getEdgePoints() {
return edgePoints;
@ -341,7 +349,28 @@ class GeoConcavePolygon extends GeoBasePolygon {
@Override
public void getBounds(Bounds bounds) {
super.getBounds(bounds);
// Because of holes, we don't want to use superclass method
if (localIsWithin(planetModel.NORTH_POLE)) {
bounds.noTopLatitudeBound().noLongitudeBound()
.addPoint(planetModel.NORTH_POLE);
}
if (localIsWithin(planetModel.SOUTH_POLE)) {
bounds.noBottomLatitudeBound().noLongitudeBound()
.addPoint(planetModel.SOUTH_POLE);
}
if (localIsWithin(planetModel.MIN_X_POLE)) {
bounds.addPoint(planetModel.MIN_X_POLE);
}
if (localIsWithin(planetModel.MAX_X_POLE)) {
bounds.addPoint(planetModel.MAX_X_POLE);
}
if (localIsWithin(planetModel.MIN_Y_POLE)) {
bounds.addPoint(planetModel.MIN_Y_POLE);
}
if (localIsWithin(planetModel.MAX_Y_POLE)) {
bounds.addPoint(planetModel.MAX_Y_POLE);
}
bounds.isWide();
// Add all the points
@ -353,6 +382,7 @@ class GeoConcavePolygon extends GeoBasePolygon {
for (final SidedPlane edge : edges) {
bounds.addPlane(planetModel, edge, eitherBounds.get(edge));
}
}
@Override

View File

@ -253,9 +253,8 @@ class GeoConvexPolygon extends GeoBasePolygon {
@Override
public boolean isWithin(final double x, final double y, final double z) {
for (final SidedPlane edge : edges) {
if (!edge.isWithin(x, y, z))
return false;
if (!localIsWithin(x, y, z)) {
return false;
}
if (holes != null) {
for (final GeoPolygon polygon : holes) {
@ -266,7 +265,19 @@ class GeoConvexPolygon extends GeoBasePolygon {
}
return true;
}
protected boolean localIsWithin(final Vector v) {
return localIsWithin(v.x, v.y, v.z);
}
protected boolean localIsWithin(final double x, final double y, final double z) {
for (final SidedPlane edge : edges) {
if (!edge.isWithin(x, y, z))
return false;
}
return true;
}
@Override
public GeoPoint[] getEdgePoints() {
return edgePoints;
@ -328,7 +339,27 @@ class GeoConvexPolygon extends GeoBasePolygon {
@Override
public void getBounds(Bounds bounds) {
super.getBounds(bounds);
// Because of holes, we don't want to use superclass method
if (localIsWithin(planetModel.NORTH_POLE)) {
bounds.noTopLatitudeBound().noLongitudeBound()
.addPoint(planetModel.NORTH_POLE);
}
if (localIsWithin(planetModel.SOUTH_POLE)) {
bounds.noBottomLatitudeBound().noLongitudeBound()
.addPoint(planetModel.SOUTH_POLE);
}
if (localIsWithin(planetModel.MIN_X_POLE)) {
bounds.addPoint(planetModel.MIN_X_POLE);
}
if (localIsWithin(planetModel.MAX_X_POLE)) {
bounds.addPoint(planetModel.MAX_X_POLE);
}
if (localIsWithin(planetModel.MIN_Y_POLE)) {
bounds.addPoint(planetModel.MIN_Y_POLE);
}
if (localIsWithin(planetModel.MAX_Y_POLE)) {
bounds.addPoint(planetModel.MAX_Y_POLE);
}
// Add all the points
for (final GeoPoint point : points) {
@ -339,6 +370,7 @@ class GeoConvexPolygon extends GeoBasePolygon {
for (final SidedPlane edge : edges) {
bounds.addPlane(planetModel, edge, eitherBounds.get(edge));
}
}
@Override