From 862bd27d5c1400763e11424a7d44dcbf4cf48c17 Mon Sep 17 00:00:00 2001 From: AileenLin Date: Fri, 11 Aug 2023 19:24:12 -0400 Subject: [PATCH] Fix misalignment in SearchCollection and SimpleImpactSearcher implementations (#2165) - ref #2167 --- .../anserini/search/SimpleImpactSearcher.java | 3 +-- .../search/SimpleImpactSearcherTest.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/anserini/search/SimpleImpactSearcher.java b/src/main/java/io/anserini/search/SimpleImpactSearcher.java index 2b5ca36edd..9944fceedf 100644 --- a/src/main/java/io/anserini/search/SimpleImpactSearcher.java +++ b/src/main/java/io/anserini/search/SimpleImpactSearcher.java @@ -638,9 +638,8 @@ public Result[] search(Map encoded_q, int k) throws IOException public Result[] search(String q, int k) throws IOException, OrtException { // make encoded query from raw query Map encoded_q = encodeWithOnnx(q); - Query query = generator.buildQuery(Constants.CONTENTS, analyzer, q); - String encodedQuery = encodeWithOnnx(encoded_q); + Query query = generator.buildQuery(Constants.CONTENTS, analyzer, encodedQuery); return _search(query, encodedQuery, k); } diff --git a/src/test/java/io/anserini/search/SimpleImpactSearcherTest.java b/src/test/java/io/anserini/search/SimpleImpactSearcherTest.java index 44f9598ce1..442c32f9be 100644 --- a/src/test/java/io/anserini/search/SimpleImpactSearcherTest.java +++ b/src/test/java/io/anserini/search/SimpleImpactSearcherTest.java @@ -370,4 +370,23 @@ public void testSearch5() throws Exception { isearcher_rm3.close(); } + @Test + public void testSearch6() throws Exception { + // test the expanded query result should be diff with testSearch5 + SimpleImpactSearcher searcher = new SimpleImpactSearcher(super.tempDir1.toString()); + searcher.set_onnx_query_encoder("UniCoil"); + + Result[] results; + + String query = "this is a a a a a test"; + results = searcher.search(query, 1); + + assertEquals(1, results.length); + assertEquals("doc3", results[0].docid); + assertEquals(2, results[0].lucene_docid); + assertEquals(130.0, results[0].score, 10e-5); + + searcher.close(); + } + }