Java Code Examples for org.apache.lucene.util.RamUsageEstimator#sizeOfObject()

The following examples show how to use org.apache.lucene.util.RamUsageEstimator#sizeOfObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TermsQuery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * @param toField               The field that should contain terms that are specified in the next parameter.
 * @param terms                 The terms that matching documents should have. The terms must be sorted by natural order.
 * @param indexReaderContextId  Refers to the top level index reader used to create the set of terms in the previous parameter.
 */
TermsQuery(String toField, BytesRefHash terms, String fromField, Query fromQuery, Object indexReaderContextId) {
  super(toField);
  this.terms = terms;
  ords = terms.sort();
  this.fromField = fromField;
  this.fromQuery = fromQuery;
  this.indexReaderContextId = indexReaderContextId;

  this.ramBytesUsed = BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(field) +
      RamUsageEstimator.sizeOfObject(fromField) +
      RamUsageEstimator.sizeOfObject(fromQuery, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED) +
      RamUsageEstimator.sizeOfObject(ords) +
      RamUsageEstimator.sizeOfObject(terms);
}
 
Example 2
Source File: GlobalOrdinalsQuery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
GlobalOrdinalsQuery(LongBitSet foundOrds, String joinField, OrdinalMap globalOrds, Query toQuery,
                    Query fromQuery, Object indexReaderContextId) {
  this.foundOrds = foundOrds;
  this.joinField = joinField;
  this.globalOrds = globalOrds;
  this.toQuery = toQuery;
  this.fromQuery = fromQuery;
  this.indexReaderContextId = indexReaderContextId;

  this.ramBytesUsed = BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(this.foundOrds) +
      RamUsageEstimator.sizeOfObject(this.globalOrds) +
      RamUsageEstimator.sizeOfObject(this.joinField) +
      RamUsageEstimator.sizeOfObject(this.fromQuery, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED) +
      RamUsageEstimator.sizeOfObject(this.toQuery, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED);
}
 
Example 3
Source File: GlobalOrdinalsWithScoreQuery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
GlobalOrdinalsWithScoreQuery(GlobalOrdinalsWithScoreCollector collector, ScoreMode scoreMode, String joinField,
                             OrdinalMap globalOrds, Query toQuery, Query fromQuery, int min, int max,
                             Object indexReaderContextId) {
  this.collector = collector;
  this.joinField = joinField;
  this.globalOrds = globalOrds;
  this.toQuery = toQuery;
  this.scoreMode = scoreMode;
  this.fromQuery = fromQuery;
  this.min = min;
  this.max = max;
  this.indexReaderContextId = indexReaderContextId;

  this.ramBytesUsed = BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(this.fromQuery, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED) +
      RamUsageEstimator.sizeOfObject(this.globalOrds) +
      RamUsageEstimator.sizeOfObject(this.joinField) +
      RamUsageEstimator.sizeOfObject(this.toQuery, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED);
}
 
Example 4
Source File: TermsIncludingScoreQuery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
TermsIncludingScoreQuery(ScoreMode scoreMode, String toField, boolean multipleValuesPerDocument, BytesRefHash terms, float[] scores,
                         String fromField, Query fromQuery, Object indexReaderContextId) {
  this.scoreMode = scoreMode;
  this.toField = toField;
  this.multipleValuesPerDocument = multipleValuesPerDocument;
  this.terms = terms;
  this.scores = scores;
  this.ords = terms.sort();

  this.fromField = fromField;
  this.fromQuery = fromQuery;
  this.topReaderContextId = indexReaderContextId;

  this.ramBytesUsed = BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(fromField) +
      RamUsageEstimator.sizeOfObject(fromQuery, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED) +
      RamUsageEstimator.sizeOfObject(ords) +
      RamUsageEstimator.sizeOfObject(scores) +
      RamUsageEstimator.sizeOfObject(terms) +
      RamUsageEstimator.sizeOfObject(toField);
}
 
Example 5
Source File: CoveringQuery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Sole constructor.
 * @param queries Sub queries to match.
 * @param minimumNumberMatch Per-document long value that records how many queries
 *                           should match. Values that are less than 1 are treated
 *                           like <code>1</code>: only documents that have at least one
 *                           matching clause will be considered matches. Documents
 *                           that do not have a value for <code>minimumNumberMatch</code>
 *                           do not match.
 */
public CoveringQuery(Collection<Query> queries, LongValuesSource minimumNumberMatch) {
  if (queries.size() > IndexSearcher.getMaxClauseCount()) {
    throw new IndexSearcher.TooManyClauses();
  }
  if (minimumNumberMatch.needsScores()) {
    throw new IllegalArgumentException("The minimum number of matches may not depend on the score.");
  }
  this.queries = new Multiset<>();
  this.queries.addAll(queries);
  this.minimumNumberMatch = Objects.requireNonNull(minimumNumberMatch);
  this.hashCode = computeHashCode();

  this.ramBytesUsed = BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(this.queries, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED);
}
 
Example 6
Source File: BM25FQuery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private BM25FQuery(BM25Similarity similarity, TreeMap<String, FieldAndWeight> fieldAndWeights, BytesRef[] terms) {
  this.similarity = similarity;
  this.fieldAndWeights = fieldAndWeights;
  this.terms = terms;
  int numFieldTerms = fieldAndWeights.size() * terms.length;
  if (numFieldTerms > IndexSearcher.getMaxClauseCount()) {
    throw new IndexSearcher.TooManyClauses();
  }
  this.fieldTerms = new Term[numFieldTerms];
  Arrays.sort(terms);
  int pos = 0;
  for (String field : fieldAndWeights.keySet()) {
    for (BytesRef term : terms) {
      fieldTerms[pos++] = new Term(field, term);
    }
  }

  this.ramBytesUsed = BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(fieldAndWeights) +
      RamUsageEstimator.sizeOfObject(fieldTerms) +
      RamUsageEstimator.sizeOfObject(terms);
}
 
Example 7
Source File: CaffeineCache.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public Object init(Map args, Object persistence, CacheRegenerator regenerator) {
  super.init(args, regenerator);
  String str = (String) args.get(SIZE_PARAM);
  maxSize = (str == null) ? 1024 : Integer.parseInt(str);
  str = (String) args.get("initialSize");
  initialSize = Math.min((str == null) ? 1024 : Integer.parseInt(str), maxSize);
  str = (String) args.get(MAX_IDLE_TIME_PARAM);
  if (str == null) {
    maxIdleTimeSec = -1;
  } else {
    maxIdleTimeSec = Integer.parseInt(str);
  }
  str = (String) args.get(MAX_RAM_MB_PARAM);
  int maxRamMB = str == null ? -1 : Double.valueOf(str).intValue();
  maxRamBytes = maxRamMB < 0 ? Long.MAX_VALUE : maxRamMB * 1024L * 1024L;
  str = (String) args.get(CLEANUP_THREAD_PARAM);
  cleanupThread = str != null && Boolean.parseBoolean(str);
  if (cleanupThread) {
    executor = ForkJoinPool.commonPool();
  } else {
    executor = Runnable::run;
  }

  description = generateDescription(maxSize, initialSize);

  cache = buildCache(null);
  inserts = new LongAdder();

  initialRamBytes =
      RamUsageEstimator.shallowSizeOfInstance(cache.getClass()) +
      RamUsageEstimator.shallowSizeOfInstance(executor.getClass()) +
      RamUsageEstimator.sizeOfObject(description);

  return persistence;
}
 
Example 8
Source File: QueryResultKey.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public QueryResultKey(Query query, List<Query> filters, Sort sort, int nc_flags, int minExactCount) {
  this.query = query;
  this.sort = sort;
  this.filters = filters;
  this.nc_flags = nc_flags;
  this.minExactCount = minExactCount;

  int h = query.hashCode();

  if (filters != null) {
    for (Query filt : filters)
      // NOTE: simple summation used here so keys with the same filters but in
      // different orders get the same hashCode
      h += filt.hashCode();
  }

  sfields = (this.sort !=null) ? this.sort.getSort() : defaultSort;
  long ramSfields = RamUsageEstimator.NUM_BYTES_ARRAY_HEADER;
  for (SortField sf : sfields) {
    h = h*29 + sf.hashCode();
    ramSfields += BASE_SF_RAM_BYTES_USED + RamUsageEstimator.sizeOfObject(sf.getField());
  }
  h = h*31 + minExactCount;

  hc = h;

  ramBytesUsed =
      BASE_RAM_BYTES_USED +
      ramSfields +
      RamUsageEstimator.sizeOfObject(query, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED) +
      RamUsageEstimator.sizeOfObject(filters, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED);
}
 
Example 9
Source File: TermAutomatonQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public long ramBytesUsed() {
  return BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(builder) +
      RamUsageEstimator.sizeOfObject(det) +
      RamUsageEstimator.sizeOfObject(field) +
      RamUsageEstimator.sizeOfObject(idToTerm) +
      RamUsageEstimator.sizeOfObject(termToID);
}
 
Example 10
Source File: PointInGeo3DShapeQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public long ramBytesUsed() {
  return BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(field) +
      RamUsageEstimator.sizeOfObject(shape) +
      RamUsageEstimator.sizeOfObject(shapeBounds);
}
 
Example 11
Source File: LTRScoringQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public long ramBytesUsed() {
  return BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(efi) +
      RamUsageEstimator.sizeOfObject(ltrScoringModel) +
      RamUsageEstimator.sizeOfObject(originalQuery, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED);
}
 
Example 12
Source File: ConcurrentLRUCache.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public CacheEntry(K key, V value, long createTime, long lastAccessed) {
  this.key = key;
  this.value = value;
  this.createTime = createTime;
  this.lastAccessed = lastAccessed;
  this.ramBytesUsed =
      BASE_RAM_BYTES_USED +
      RamUsageEstimator.sizeOfObject(key, QUERY_DEFAULT_RAM_BYTES_USED) +
      RamUsageEstimator.sizeOfObject(value, QUERY_DEFAULT_RAM_BYTES_USED);
}
 
Example 13
Source File: CompiledAutomaton.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public long ramBytesUsed() {
  return BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(automaton) +
      RamUsageEstimator.sizeOfObject(commonSuffixRef) +
      RamUsageEstimator.sizeOfObject(runAutomaton) +
      RamUsageEstimator.sizeOfObject(term) +
      RamUsageEstimator.sizeOfObject(transition);
}
 
Example 14
Source File: RunAutomaton.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public long ramBytesUsed() {
  return BASE_RAM_BYTES +
      accept.ramBytesUsed() +
      RamUsageEstimator.sizeOfObject(automaton) +
      RamUsageEstimator.sizeOfObject(classmap) +
      RamUsageEstimator.sizeOfObject(points) +
      RamUsageEstimator.sizeOfObject(transitions);
}
 
Example 15
Source File: LTRScoringModel.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public long ramBytesUsed() {
  return BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(allFeatures, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED) +
      RamUsageEstimator.sizeOfObject(features, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED) +
      RamUsageEstimator.sizeOfObject(featureStoreName) +
      RamUsageEstimator.sizeOfObject(name) +
      RamUsageEstimator.sizeOfObject(norms) +
      RamUsageEstimator.sizeOfObject(params);
}
 
Example 16
Source File: LongHashSet.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public long ramBytesUsed() {
  return BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(table);
}
 
Example 17
Source File: Feature.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public long ramBytesUsed() {
  return BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(name) +
      RamUsageEstimator.sizeOfObject(params);
}
 
Example 18
Source File: DocValuesTermsQuery.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public long ramBytesUsed() {
  return BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(field) +
      RamUsageEstimator.sizeOfObject(termData);
}
 
Example 19
Source File: DocValuesNumbersQuery.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public long ramBytesUsed() {
  return BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(field) +
      RamUsageEstimator.sizeOfObject(numbers);
}
 
Example 20
Source File: ContextQuery.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void updateRamBytesUsed() {
  ramBytesUsed = BASE_RAM_BYTES +
      RamUsageEstimator.sizeOfObject(contexts) +
      RamUsageEstimator.sizeOfObject(innerQuery, RamUsageEstimator.QUERY_DEFAULT_RAM_BYTES_USED);
}