Exemple #1
0
  protected LegacyIndexHits query(
      Query query,
      String keyForDirectLookup,
      Object valueForDirectLookup,
      QueryContext additionalParametersOrNull) {
    List<Long> ids = new ArrayList<>();
    Collection<Long> removedIds = Collections.emptySet();
    IndexSearcher additionsSearcher = null;
    if (transaction != null) {
      if (keyForDirectLookup != null) {
        ids.addAll(transaction.getAddedIds(this, keyForDirectLookup, valueForDirectLookup));
      } else {
        additionsSearcher = transaction.getAdditionsAsSearcher(this, additionalParametersOrNull);
      }
      removedIds =
          keyForDirectLookup != null
              ? transaction.getRemovedIds(this, keyForDirectLookup, valueForDirectLookup)
              : transaction.getRemovedIds(this, query);
    }
    LegacyIndexHits idIterator = null;
    IndexReference searcher = null;
    dataSource.getReadLock();
    try {
      searcher = dataSource.getIndexSearcher(identifier);
    } finally {
      dataSource.releaseReadLock();
    }

    if (searcher != null) {
      boolean foundInCache = false;
      LruCache<String, Collection<Long>> cachedIdsMap = null;
      if (keyForDirectLookup != null) {
        cachedIdsMap = dataSource.getFromCache(identifier, keyForDirectLookup);
        foundInCache =
            fillFromCache(cachedIdsMap, ids, valueForDirectLookup.toString(), removedIds);
      }

      if (!foundInCache) {
        DocToIdIterator searchedIds =
            new DocToIdIterator(
                search(searcher, query, additionalParametersOrNull, additionsSearcher, removedIds),
                removedIds,
                searcher);
        if (ids.isEmpty()) {
          idIterator = searchedIds;
        } else {
          Collection<LegacyIndexHits> iterators = new ArrayList<>();
          iterators.add(searchedIds);
          iterators.add(new ConstantScoreIterator(ids, Float.NaN));
          idIterator = new CombinedIndexHits(iterators);
        }
      }
    }

    idIterator = idIterator == null ? new ConstantScoreIterator(ids, 0) : idIterator;
    return idIterator;
  }
 @Override
 protected void fillDocument(Document document, long nodeId, String key, Object value) {
   super.fillDocument(document, nodeId, key, value);
   document.add(
       new Field(
           LuceneFulltextIndexService.DOC_INDEX_SOURCE_KEY,
           value.toString(),
           Field.Store.NO,
           Field.Index.NOT_ANALYZED));
 }