-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Pyserini bindings to Lucene 9 (#1961)
+ Expose Lucene 8 backwards compatibility bindings in SimpleSearcher and SimpleImpactSearcher: Basically, if we detect Lucene 8 indexes, we disable consistent tie-breaking, which depends on docvalues; see #1952 + General cleanup (fixed code formatting in SimpleImpactSearcher) + Remove main in SimpleSearcher + Change to Python method names (snake_case)
- Loading branch information
Showing
77 changed files
with
812 additions
and
718 deletions.
There are no files selected for viewing
589 changes: 288 additions & 301 deletions
589
src/main/java/io/anserini/search/SimpleImpactSearcher.java
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/java/io/anserini/search/SimpleImpactSearcherPrebuiltLucene8Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Anserini: A Lucene toolkit for reproducible information retrieval research | ||
* | ||
* Licensed 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 io.anserini.search; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class SimpleImpactSearcherPrebuiltLucene8Test { | ||
|
||
@Test | ||
public void testSearch1() throws Exception { | ||
SimpleImpactSearcher searcher = | ||
new SimpleImpactSearcher("src/test/resources/prebuilt_indexes/lucene8-index.sample_docs_json_collection_tokenized"); | ||
assertEquals(2, searcher.get_total_num_docs()); | ||
|
||
SimpleImpactSearcher.Result[] hits; | ||
|
||
Map<String, Float> query = new HashMap<>(); | ||
query.put("##ing", 1.0f); | ||
|
||
hits = searcher.search(query, 10); | ||
assertEquals(1, hits.length); | ||
assertEquals("2000001", hits[0].docid); | ||
assertEquals(2, (int) hits[0].score); | ||
|
||
query = new HashMap<>(); | ||
query.put("test", 1.0f); | ||
hits = searcher.search(query, 10); | ||
assertEquals(1, hits.length); | ||
assertEquals("2000000", hits[0].docid); | ||
assertEquals(1, (int) hits[0].score); | ||
|
||
searcher.close(); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/io/anserini/search/SimpleImpactSearcherPrebuiltLucene9Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Anserini: A Lucene toolkit for reproducible information retrieval research | ||
* | ||
* Licensed 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 io.anserini.search; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class SimpleImpactSearcherPrebuiltLucene9Test { | ||
|
||
@Test | ||
public void testSearch1() throws Exception { | ||
SimpleImpactSearcher searcher = | ||
new SimpleImpactSearcher("src/test/resources/prebuilt_indexes/lucene9-index.sample_docs_json_collection_tokenized"); | ||
assertEquals(2, searcher.get_total_num_docs()); | ||
|
||
SimpleImpactSearcher.Result[] hits; | ||
|
||
Map<String, Float> query = new HashMap<>(); | ||
query.put("##ing", 1.0f); | ||
|
||
hits = searcher.search(query, 10); | ||
assertEquals(1, hits.length); | ||
assertEquals("2000001", hits[0].docid); | ||
assertEquals(2, (int) hits[0].score); | ||
|
||
query = new HashMap<>(); | ||
query.put("test", 1.0f); | ||
hits = searcher.search(query, 10); | ||
assertEquals(1, hits.length); | ||
assertEquals("2000000", hits[0].docid); | ||
assertEquals(1, (int) hits[0].score); | ||
|
||
searcher.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/test/java/io/anserini/search/SimpleSearcherPrebuiltLucene8Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Anserini: A Lucene toolkit for reproducible information retrieval research | ||
* | ||
* Licensed 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 io.anserini.search; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class SimpleSearcherPrebuiltLucene8Test { | ||
|
||
@Test | ||
public void testSearch1() throws Exception { | ||
SimpleSearcher searcher = | ||
new SimpleSearcher("src/test/resources/prebuilt_indexes/lucene8-index.sample_docs_trec_colletion2"); | ||
assertEquals(3, searcher.get_total_num_docs()); | ||
|
||
SimpleSearcher.Result[] hits; | ||
|
||
hits = searcher.search("text", 10); | ||
assertEquals(3, hits.length); | ||
assertEquals("DOC222", hits[0].docid); | ||
assertEquals(0.1015f, hits[0].score, 10e-4); | ||
assertEquals("TREC_DOC_1", hits[1].docid); | ||
assertEquals(0.0738f, hits[1].score, 10e-4); | ||
assertEquals("WSJ_1", hits[2].docid); | ||
assertEquals(0.0687f, hits[2].score, 10e-4); | ||
|
||
hits = searcher.search("simple", 10); | ||
assertEquals(2, hits.length); | ||
assertEquals("TREC_DOC_1", hits[0].docid); | ||
assertEquals(0.2597f, hits[0].score, 10e-4); | ||
assertEquals("DOC222", hits[1].docid); | ||
assertEquals(0.2416f, hits[1].score, 10e-4); | ||
|
||
searcher.close(); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/test/java/io/anserini/search/SimpleSearcherPrebuiltLucene9Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Anserini: A Lucene toolkit for reproducible information retrieval research | ||
* | ||
* Licensed 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 io.anserini.search; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class SimpleSearcherPrebuiltLucene9Test { | ||
|
||
@Test | ||
public void testSearch1() throws Exception { | ||
SimpleSearcher searcher = | ||
new SimpleSearcher("src/test/resources/prebuilt_indexes/lucene9-index.sample_docs_trec_colletion2"); | ||
assertEquals(3, searcher.get_total_num_docs()); | ||
|
||
SimpleSearcher.Result[] hits; | ||
|
||
hits = searcher.search("text", 10); | ||
assertEquals(3, hits.length); | ||
assertEquals("DOC222", hits[0].docid); | ||
assertEquals(0.1015f, hits[0].score, 10e-4); | ||
assertEquals("TREC_DOC_1", hits[1].docid); | ||
assertEquals(0.0738f, hits[1].score, 10e-4); | ||
assertEquals("WSJ_1", hits[2].docid); | ||
assertEquals(0.0687f, hits[2].score, 10e-4); | ||
|
||
hits = searcher.search("simple", 10); | ||
assertEquals(2, hits.length); | ||
assertEquals("TREC_DOC_1", hits[0].docid); | ||
assertEquals(0.2597f, hits[0].score, 10e-4); | ||
assertEquals("DOC222", hits[1].docid); | ||
assertEquals(0.2416f, hits[1].score, 10e-4); | ||
|
||
searcher.close(); | ||
} | ||
|
||
} |
Oops, something went wrong.