jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject [3/6] jena git commit: very simple caching of Lucene query results in a hash map
Date Mon, 11 Jan 2016 07:28:03 GMT
very simple caching of Lucene query results in a hash map


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/9149a1df
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/9149a1df
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/9149a1df

Branch: refs/heads/master
Commit: 9149a1df8011ca1aea37f832bb4e19ef22f87f67
Parents: a943062
Author: Osma Suominen <osma@apache.org>
Authored: Tue Dec 22 18:45:50 2015 +0200
Committer: Osma Suominen <osma@apache.org>
Committed: Mon Jan 11 09:27:13 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/jena/query/text/TextQueryPF.java  | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/9149a1df/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
index 13e8848..ff21248 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
@@ -19,7 +19,10 @@
 package org.apache.jena.query.text ;
 
 import java.util.Iterator ;
+import java.util.LinkedHashMap ;
+import java.util.LinkedList ;
 import java.util.List ;
+import java.util.Map ;
 import java.util.function.Function ;
 import java.util.stream.Collectors ;
 
@@ -62,11 +65,14 @@ public class TextQueryPF extends PropertyFunctionBase {
 
     private String langArg = null;
 
+    private Map<String,List<TextHit>> queryCache = null;
+
     @Override
     public void build(PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext
execCxt) {
         super.build(argSubject, predicate, argObject, execCxt) ;
         DatasetGraph dsg = execCxt.getDataset() ;
         textIndex = chooseTextIndex(dsg) ;
+        queryCache = new LinkedHashMap();
 
         if (argSubject.isList()) {
             int size = argSubject.getArgListSize();
@@ -268,7 +274,13 @@ public class TextQueryPF extends PropertyFunctionBase {
         Explain.explain(execCxt.getContext(), "Text query: "+queryString) ;
         if ( log.isDebugEnabled())
             log.debug("Text query: {} ({})", queryString,limit) ;
-        return textIndex.query(property, queryString, limit) ;
+        String cacheKey = limit + " " + property + " " + queryString ;
+        List<TextHit> results = queryCache.get(cacheKey) ;
+        if (results == null) { /* cache miss */
+            results = textIndex.query(property, queryString, limit) ;
+            queryCache.put(cacheKey, results) ;
+        }
+        return results;
     }
     
     /** Deconstruct the node or list object argument and make a StrMatch 


Mime
View raw message