public override Scorer Scorer(IndexReader reader, bool scoreDocsInOrder, bool topScorer, IState state) { Debug.Assert(reader is ReadOnlySegmentReader); // we assume that only segments go here var clauseCache = _parent._index.DocumentDatabase.ServerStore.QueryClauseCache; if (CacheByReader.TryGetValue(reader, out IndexReaderCachedQueries cachedQueries) == false) { cachedQueries = CacheByReader.GetValue(reader, _ => new IndexReaderCachedQueries(_parent._index) { Cache = clauseCache, }); } // The reader is immutable, so we can safely cache the values for this segment Debug.Assert(cachedQueries != null, nameof(cachedQueries) + " != null"); var queryCacheKey = new QueryCacheKey { Owner = cachedQueries.UniqueId, Query = _parent._query, }; DateTime now = DateTime.UtcNow; FastBitArray results; if (clauseCache.TryGetValue(queryCacheKey, out ulong[] buffer) == false)
// <summary> // cache entry constructor // </summary> internal QueryCacheEntry(QueryCacheKey queryCacheKey, object target) { _queryCacheKey = queryCacheKey; _target = target; }
/// <summary> /// cache entry constructor /// </summary> /// <param name="queryCacheKey"> </param> /// <param name="target"> </param> internal QueryCacheEntry(QueryCacheKey queryCacheKey, object target) { _queryCacheKey = queryCacheKey; _target = target; }
public IQueryTranslator[] GetQuery(string queryString, bool shallow, IDictionary<string, IFilter> enabledFilters) { QueryCacheKey cacheKey = new QueryCacheKey(queryString, shallow, enabledFilters); // have to be careful to ensure that if the JVM does out-of-order execution // then another thread can't get an uncompiled QueryTranslator from the cache // we also have to be very careful to ensure that other threads can perform // compiled queries while another query is being compiled IQueryTranslator[] queries = (IQueryTranslator[]) Get(cacheKey); if (queries == null) { // a query that names an interface or unmapped class in the from clause // is actually executed as multiple queries string[] concreteQueryStrings = QuerySplitter.ConcreteQueries(queryString, this); queries = CreateQueryTranslators(queryString, concreteQueryStrings, cacheKey, enabledFilters); } foreach (IQueryTranslator q in queries) { q.Compile(settings.QuerySubstitutions, shallow); } // see comment above. note that QueryTranslator.compile() is synchronized return queries; }
private IQueryTranslator[] CreateQueryTranslators(string hql, string[] concreteQueryStrings, QueryCacheKey cacheKey, IDictionary<string, IFilter> enabledFilters) { int length = concreteQueryStrings.Length; IQueryTranslator[] queries = new IQueryTranslator[length]; for (int i = 0; i < length; i++) { queries[i] = settings.QueryTranslatorFactory.CreateQueryTranslator(hql, concreteQueryStrings[i], enabledFilters, this); } Put(cacheKey, queries); return queries; }
public bool Equals(QueryCacheKey obj) { return _hashCode == obj._hashCode && Query.Equals(obj.Query) && Scalar == obj.Scalar && CollectionHelper.SetEquals(FilterNames, obj.FilterNames); }
private QueryTranslator[] CreateQueryTranslators(string[] concreteQueryStrings, QueryCacheKey cacheKey) { int length = concreteQueryStrings.Length; QueryTranslator[] queries = new QueryTranslator[length]; for (int i = 0; i < length; i++) { queries[i] = new QueryTranslator(concreteQueryStrings[i]); } Put(cacheKey, queries); return(queries); }
public bool Equals(QueryCacheKey obj) { return(this.Query.Equals(obj.Query) && this.Scalar == obj.Scalar); }
protected bool Equals(QueryCacheKey other) { return(Query == other.Query && Owner == other.Owner); }
private static string DoBuildQueryString(EntityMetadata entityMetadata, InternalQueryRequest queryParameter, QueryCacheKey.QueryMode queryMode, IWhereBuilder compositeWhereBuilder, QueryCacheKey cacheKey) { var buffer = new StringBuilder(InitialStringBuilderCapacity); var projectionBuilder = new StringBuilder(InitialStringBuilderCapacity); projectionBuilder.Append(QuerySelectBuilder.BuildSelectAttributesClause(entityMetadata, queryMode, queryParameter.SearchDTO)); projectionBuilder.Append(QueryFromBuilder.Build(entityMetadata, queryParameter.SearchDTO)); buffer.Append(projectionBuilder); buffer.Append(compositeWhereBuilder.BuildWhereClause(entityMetadata.Name, queryMode, queryParameter.SearchDTO)); var hasUnionWhereClauses = queryParameter.SearchDTO != null && queryParameter.SearchDTO.UnionWhereClauses != null; var isUnion = entityMetadata.HasUnion() || queryMode == QueryCacheKey.QueryMode.Union || hasUnionWhereClauses; if (queryMode != QueryCacheKey.QueryMode.Count && queryMode != QueryCacheKey.QueryMode.Detail && !isUnion) { buffer.Append(QuerySearchSortBuilder.BuildSearchSort(entityMetadata, queryParameter.SearchDTO)); } if (hasUnionWhereClauses) { foreach (var unionWC in queryParameter.SearchDTO.UnionWhereClauses) { buffer.Append(" union all ").Append(projectionBuilder).Append(" where (").Append(unionWC).Append(")"); } buffer.Append(" order by 1 desc"); } var queryString = buffer.ToString(); return(queryString); }
private QueryTranslator[ ] CreateQueryTranslators( string[ ] concreteQueryStrings, QueryCacheKey cacheKey ) { int length = concreteQueryStrings.Length; QueryTranslator[ ] queries = new QueryTranslator[length]; for( int i = 0; i < length; i++ ) { queries[ i ] = new QueryTranslator( concreteQueryStrings[ i ] ); } Put( cacheKey, queries ); return queries; }
public bool Equals( QueryCacheKey obj ) { return this.Query.Equals( obj.Query ) && this.Scalar == obj.Scalar; }