parent
5bb75f9da3
commit
c18c609af1
|
@ -66,6 +66,11 @@ public class QueryParserSettings {
|
|||
float tieBreaker = 0.0f;
|
||||
boolean useDisMax = true;
|
||||
|
||||
public boolean isCacheable() {
|
||||
// a hack for now :) to determine if a query string is cacheable
|
||||
return !queryString.contains("now");
|
||||
}
|
||||
|
||||
public String queryString() {
|
||||
return queryString;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@ import org.elasticsearch.common.component.CloseableComponent;
|
|||
import org.elasticsearch.index.IndexComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* The main benefit of the query parser cache is to not parse the same query string on different shards.
|
||||
* Less about long running query strings.
|
||||
*/
|
||||
public interface QueryParserCache extends IndexComponent, CloseableComponent {
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.cache.query.parser.resident;
|
|||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
import org.apache.lucene.queryparser.classic.QueryParserSettings;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
|
@ -69,7 +68,9 @@ public class ResidentQueryParserCache extends AbstractIndexComponent implements
|
|||
|
||||
@Override
|
||||
public void put(QueryParserSettings queryString, Query query) {
|
||||
cache.put(queryString, query);
|
||||
if (queryString.isCacheable()) {
|
||||
cache.put(queryString, query);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Licensed to ElasticSearch and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. ElasticSearch licenses this
|
||||
* file to you 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 org.elasticsearch.index.cache.query.parser.support;
|
||||
|
||||
import org.apache.lucene.queryparser.classic.QueryParserSettings;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.AbstractIndexComponent;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.cache.query.parser.QueryParserCache;
|
||||
import org.elasticsearch.index.settings.IndexSettings;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AbstractJvmQueryParserCache extends AbstractIndexComponent implements QueryParserCache {
|
||||
|
||||
final ConcurrentMap<QueryParserSettings, Query> cache;
|
||||
|
||||
protected AbstractJvmQueryParserCache(Index index, @IndexSettings Settings indexSettings, ConcurrentMap<QueryParserSettings, Query> cache) {
|
||||
super(index, indexSettings);
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws ElasticSearchException {
|
||||
clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query get(QueryParserSettings queryString) {
|
||||
return cache.get(queryString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(QueryParserSettings queryString, Query query) {
|
||||
cache.put(queryString, query);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue