Package org.neo4j.graphdb.index

Examples of org.neo4j.graphdb.index.IndexHits


     * If the graph is not currently in a transaction, then the operation runs efficiently.
     * If the graph is in a transaction, then, for every element, a try/catch is used to determine if its in the current transaction.
     */
    public long count(final String key, final Object value) {
        if (!this.graph.checkElementsInTransaction()) {
            final IndexHits hits = this.rawIndex.get(key, value);
            final long count = hits.size();
            hits.close();
            return count;
        } else {
            final CloseableIterable<T> hits = this.get(key, value);
            long count = 0;
            for (final T t : hits) {
                count++;
            }
            hits.close();
            return count;
        }
    }
View Full Code Here


     * If the graph is in a transaction, then, for every element, a try/catch is used to determine if its in the current transaction.
     */
    public long count(final String key, final Object value) {
        this.graph.autoStartTransaction(false);
        if (!this.graph.checkElementsInTransaction()) {
            final IndexHits hits = this.rawIndex.get(key, value);
            final long count = hits.size();
            hits.close();
            return count;
        } else {
            final CloseableIterable<T> hits = this.get(key, value);
            long count = 0;
            for (final T t : hits) {
                count++;
            }
            hits.close();
            return count;
        }
    }
View Full Code Here

       
      }

      long start = System.currentTimeMillis();

      IndexHits hits = index.query(actualQuery);
      for (Object hit : hits) {
        count++;
      }
     
      // this is not accurate
      // count = hits.size();

      long end = System.currentTimeMillis();

      logger.log(Level.FINE, "Counted {0} entities in {1} ms.", new Object[] { count, (end-start) } );

      hits.close();
    }
   
    return count;
  }
View Full Code Here

        allExactMatch &= attr.isExactMatch();
      }

      QueryContext queryContext = new QueryContext(query);
      IndexHits hits            = null;

      if (sortKey != null) {

        Integer sortType = sortKey.getSortType();
        if (sortType != null) {

          queryContext.sort(new Sort(new SortField(sortKey.dbName(), sortType, sortDescending)));

        } else {

          queryContext.sort(new Sort(new SortField(sortKey.dbName(), Locale.getDefault(), sortDescending)));
        }

      }

      if (distanceSearch != null) {

        if (coords != null) {

          Map<String, Object> params = new HashMap<>();

          params.put(LayerNodeIndex.POINT_PARAMETER, coords.toArray());
          params.put(LayerNodeIndex.DISTANCE_IN_KM_PARAMETER, dist);

          LayerNodeIndex spatialIndex = this.getSpatialIndex();
          if (spatialIndex != null) {

            synchronized (spatialIndex) {

              hits = spatialIndex.query(LayerNodeIndex.WITHIN_DISTANCE_QUERY, params);
            }
          }
        }

        // instantiate spatial search results without paging,
        // as the results must be filtered by type anyway
        intermediateResult = new NodeFactory(securityContext).instantiate(hits);

      } else if (allExactMatch) {

        index = getKeywordIndex();

        synchronized (index) {

          try {
            hits = index.query(queryContext);

          } catch (NumberFormatException nfe) {

            logger.log(Level.SEVERE, "Could not sort results", nfe);

            // retry without sorting
            queryContext.sort(null);
            hits = index.query(queryContext);

          }
        }

        // all luecene query, do not filter results
        filterResults = hasEmptySearchFields;
        intermediateResult = factory.instantiate(hits);

      } else {

        // Default: Mixed or fulltext-only search: Use fulltext index
        index = getFulltextIndex();

        synchronized (index) {

          try {
            hits = index.query(queryContext);

          } catch (NumberFormatException nfe) {

            logger.log(Level.SEVERE, "Could not sort results", nfe);

            // retry without sorting
            queryContext.sort(null);
            hits = index.query(queryContext);

          }
        }

        // all luecene query, do not filter results
        filterResults = hasEmptySearchFields;
        intermediateResult = factory.instantiate(hits);
      }

      if (hits != null) {
        hits.close();
      }
    }

    if (filterResults) {
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.index.IndexHits

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.