public void execute(String query) throws ParseException { reset(); query = query.replaceAll("\\s+AND\\s+", " and "); query = query.replaceAll("\\s+OR\\s+", " or "); query = query.replaceAll("\\s+NOT\\s+", " not "); // Check to see if its in the cache Hash hash = MurmurHash.getInstance(); this.hashVal = hash.hash(query.getBytes(), SEED); CacheEntry entry = null; synchronized (cache) { entry = (CacheEntry) cache.get(hashVal); } if (entry != null) { this.negatedTerms = entry.getNegatedTerms(); this.andTerms = entry.getAndTerms(); this.orTerms = entry.getOrTerms(); this.literals = entry.getLiterals(); this.terms = entry.getTerms(); this.rootNode = entry.getRootNode(); this.tree = entry.getTree(); } else { Parser p = new Parser(new StringReader(";")); rootNode = p.parse(new StringReader(query), null); rootNode.childrenAccept(this, null); TreeBuilder builder = new TreeBuilder(rootNode); tree = builder.getRootNode(); entry = new CacheEntry(this.negatedTerms, this.andTerms, this.orTerms, this.literals, this.terms, rootNode, tree); synchronized (cache) { cache.put(hashVal, entry); } } }
private int computeHash(final byte[] encodedKey) { return Math.abs(MurmurHash.getInstance().hash(encodedKey)); }