diff options
author | Jon Bratseth <jonbratseth@yahoo.com> | 2017-08-28 12:22:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-28 12:22:42 +0200 |
commit | 7d4b8d465f2b0d1e9005a612cf8373908a33ffb6 (patch) | |
tree | 6fde71ce73cc604774e288d2317e121d1d2a6818 /container-search/src | |
parent | 2b7452bda4e045b1c145c82dde0d6cdda778051d (diff) | |
parent | 62153b6e19e30cf3d7b6c48a8ffd4dc63b8d45aa (diff) |
Merge pull request #3224 from vespa-engine/balder/add-tests-and-tracing-of-cache-and-sessionid
Add info about enabled caches and their keys.
Diffstat (limited to 'container-search/src')
3 files changed, 58 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java index 3369eb64094..1a7e693caa7 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java @@ -396,6 +396,16 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { s.append(" location=") .append(query.getRanking().getLocation().toString()); } + + if (query.getGroupingSessionCache()) { + s.append(" groupingSessionCache=true"); + } + if (query.getRanking().getQueryCache()) { + s.append(" ranking.queryCache=true"); + } + if (query.getGroupingSessionCache() || query.getRanking().getQueryCache()) { + s.append(" sessionId=" + query.getSessionId(true)); + } List<Grouping> grouping = GroupingExecutor.getGroupingList(query); s.append(" grouping=").append(grouping.size()).append(" : "); diff --git a/container-search/src/main/java/com/yahoo/search/query/SessionId.java b/container-search/src/main/java/com/yahoo/search/query/SessionId.java index c6e34e7e430..b065bd9a0a9 100644 --- a/container-search/src/main/java/com/yahoo/search/query/SessionId.java +++ b/container-search/src/main/java/com/yahoo/search/query/SessionId.java @@ -22,4 +22,19 @@ public class SessionId { } public Utf8String asUtf8String() { return id; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SessionId sessionId = (SessionId) o; + + return id.equals(sessionId.id); + } + + @Override + public int hashCode() { + return id.hashCode(); + } } diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java index ce9e3357c77..3ffc5dbcf78 100644 --- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java @@ -23,6 +23,7 @@ import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.query.QueryTree; +import com.yahoo.search.query.SessionId; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.result.Hit; @@ -44,6 +45,7 @@ import java.util.stream.Collectors; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -637,6 +639,37 @@ public class QueryTestCase { } @Test + public void testThatSessionIdIsUniquePerQuery() { + Query q = new Query(); + assertNull(q.getSessionId(false)); + assertNull(q.getSessionId(false)); + SessionId s1 = q.getSessionId(true); + assertNotNull(s1); + SessionId s2 = q.getSessionId(true); + assertNotSame(s1, s2); + assertEquals(s1, s2); + assertEquals(s1.toString(), s2.toString()); + + Query q2 = new Query(); + assertNotEquals(q.getSessionId(false), q2.getSessionId(true)); + assertNotEquals(q.getSessionId(false).toString(), q2.getSessionId(true).toString()); + + // This is not required, but just to document current implementation. + Query clonedQ = q.clone(); + assertNotNull(clonedQ.getSessionId(false)); + assertEquals(q.getSessionId(false), q.getSessionId(false)); + } + + @Test + public void testThatSessionIdIsUniquePerRankProfilePerQuery() { + Query q = new Query(); + SessionId s1 = q.getSessionId(true); + q.getRanking().setProfile("my-profile"); + SessionId s2 = q.getSessionId(false); + assertNotEquals(s1, s2); + } + + @Test public void testPositiveTerms() { Query q = new Query(httpEncode("/?query=-a \"b c\" d e")); Item i = q.getModel().getQueryTree().getRoot(); |