You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by gs...@apache.org on 2007/09/08 18:57:30 UTC
svn commit: r573881 - in /lucene/java/trunk: CHANGES.txt
src/java/org/apache/lucene/search/payloads/BoostingTermQuery.java
src/test/org/apache/lucene/search/payloads/TestBoostingTermQuery.java
Author: gsingers
Date: Sat Sep 8 09:57:28 2007
New Revision: 573881
URL: http://svn.apache.org/viewvc?rev=573881&view=rev
Log:
LUCENE-991: Fixed explain() method reporting issues when no payloads present.
Modified:
lucene/java/trunk/CHANGES.txt
lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingTermQuery.java
lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingTermQuery.java
Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=573881&r1=573880&r2=573881&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Sat Sep 8 09:57:28 2007
@@ -81,6 +81,8 @@
long, instead of cryptic ArrayIndexOutOfBoundsException. (Karl
Wettin via Mike McCandless)
+13 LUCENE-991: The explain() method of BoostingTermQuery had errors when no payloads were present on a document. (Peter Keegan via Grant Ingersoll)
+
New features
1. LUCENE-906: Elision filter for French.
Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingTermQuery.java?rev=573881&r1=573880&r2=573881&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingTermQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingTermQuery.java Sat Sep 8 09:57:28 2007
@@ -165,7 +165,7 @@
}
*/
- float avgPayloadScore = payloadScore / payloadsSeen;
+ float avgPayloadScore = (payloadsSeen > 0 ? (payloadScore / payloadsSeen) : 1);
payloadBoost.setValue(avgPayloadScore);
//GSI: I suppose we could toString the payload, but I don't think that would be a good idea
payloadBoost.setDescription("scorePayload(...)");
Modified: lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingTermQuery.java?rev=573881&r1=573880&r2=573881&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingTermQuery.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingTermQuery.java Sat Sep 8 09:57:28 2007
@@ -46,7 +46,6 @@
private class PayloadAnalyzer extends Analyzer {
-
public TokenStream tokenStream(String fieldName, Reader reader) {
TokenStream result = new LowerCaseTokenizer(reader);
result = new PayloadFilter(result, fieldName);
@@ -66,18 +65,12 @@
public Token next() throws IOException {
Token result = input.next();
if (result != null) {
- if (fieldName.equals("field"))
- {
+ if (fieldName.equals("field")) {
result.setPayload(new Payload(payloadField));
- }
- else if (fieldName.equals("multiField"))
- {
- if (numSeen % 2 == 0)
- {
+ } else if (fieldName.equals("multiField")) {
+ if (numSeen % 2 == 0) {
result.setPayload(new Payload(payloadMultiField1));
- }
- else
- {
+ } else {
result.setPayload(new Payload(payloadMultiField2));
}
numSeen++;
@@ -97,11 +90,14 @@
//writer.infoStream = System.out;
for (int i = 0; i < 1000; i++) {
Document doc = new Document();
+ Field noPayloadField = new Field("noPayLoad", English.intToEnglish(i), Field.Store.YES, Field.Index.TOKENIZED);
+ noPayloadField.setBoost(0);
+ doc.add(noPayloadField);
doc.add(new Field("field", English.intToEnglish(i), Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("multiField", English.intToEnglish(i) + " " + English.intToEnglish(i), Field.Store.YES, Field.Index.TOKENIZED));
writer.addDocument(doc);
}
- //writer.optimize();
+ writer.optimize();
writer.close();
searcher = new IndexSearcher(directory);
@@ -109,9 +105,6 @@
}
-
-
-
protected void tearDown() {
}
@@ -148,7 +141,6 @@
assertTrue("hits is null and it shouldn't be", hits != null);
assertTrue("hits Size: " + hits.totalHits + " is not: " + 100, hits.totalHits == 100);
-
//they should all have the exact same score, because they all contain seventy once, and we set
//all the other similarity factors to be 1
@@ -159,13 +151,10 @@
int numTens = 0;
for (int i = 0; i < hits.scoreDocs.length; i++) {
ScoreDoc doc = hits.scoreDocs[i];
- if (doc.doc % 10 == 0)
- {
+ if (doc.doc % 10 == 0) {
numTens++;
assertTrue(doc.score + " does not equal: " + 3, doc.score == 3);
- }
- else
- {
+ } else {
assertTrue(doc.score + " does not equal: " + 2, doc.score == 2);
}
}
@@ -177,8 +166,7 @@
//should be two matches per document
int count = 0;
//100 hits times 2 matches per hit, we should have 200 in count
- while (spans.next())
- {
+ while (spans.next()) {
count++;
}
assertTrue(count + " does not equal: " + 200, count == 200);
@@ -192,9 +180,23 @@
}
+ public void testNoPayload() throws Exception {
+ BoostingTermQuery q1 = new BoostingTermQuery(new Term("noPayLoad", "zero"));
+ BoostingTermQuery q2 = new BoostingTermQuery(new Term("noPayLoad", "foo"));
+ BooleanClause c1 = new BooleanClause(q1, BooleanClause.Occur.MUST);
+ BooleanClause c2 = new BooleanClause(q2, BooleanClause.Occur.MUST_NOT);
+ BooleanQuery query = new BooleanQuery();
+ query.add(c1);
+ query.add(c2);
+ TopDocs hits = searcher.search(query, null, 100);
+ assertTrue("hits is null and it shouldn't be", hits != null);
+ //assertTrue("hits Size: " + hits.totalHits + " is not: " + 1, hits.totalHits == 1);
+ int[] results = new int[1];
+ results[0] = 0;//hits.scoreDocs[0].doc;
+ CheckHits.checkHitCollector(query, "noPayLoad", searcher, results);
+ }
- class BoostingSimilarity extends DefaultSimilarity
- {
+ class BoostingSimilarity extends DefaultSimilarity {
// TODO: Remove warning after API has been finalized
public float scorePayload(byte[] payload, int offset, int length) {
@@ -226,7 +228,7 @@
}
public float tf(float freq) {
- return 1;
+ return freq == 0 ? 0 : 1;
}
}
}