Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refreshing automatic index #173

Closed
lassewesth opened this issue Nov 12, 2012 · 3 comments
Closed

Refreshing automatic index #173

lassewesth opened this issue Nov 12, 2012 · 3 comments
Labels

Comments

@lassewesth
Copy link
Member

@deelam: 'In cases where the auto-index is stopped or isn't active (i.e., during BatchInsertion), there is no way to "refresh" the auto-index.

To update the automatic index when using BatchInserter, use the name of the automatic index (i.e., "node_auto_index" and "relationship_auto_index") in the place of "actors" in 'indexProvider.nodeIndex( "actors", MapUtil.stringMap( "type", "exact" ) );'.

Possible solution: Implement a refresh method to update the automatic index based on all the data in the database.

The following was provided by Michael Hunger:

Some code like this can "create" the auto-index in a regular graphdb.

If you want to update an auto-index which indexed different properties before that you have to include those properties in the set (they will then be removed from the auto-index).

public static void main(String[] args) {
       EmbeddedGraphDatabase db = null;
       try {
           db = new EmbeddedGraphDatabase(args[0], config()); // config must contain auto-index-config
           GlobalGraphOperations graphOperations = GlobalGraphOperations.at(db);
           updateAutoIndex(db, db.index().getNodeAutoIndexer(), graphOperations.getAllNodes());
           updateAutoIndex(db, db.index().getRelationshipAutoIndexer(), graphOperations.getAllRelationships());
       } finally {
           if (db != null) db.shutdown();
       }
   }

   private static <T extends PropertyContainer> void updateAutoIndex(GraphDatabaseService db, AutoIndexer<T> autoIndexer, final Iterable<T> elements) {
       if (!autoIndexer.isEnabled()) return;
       final Set<String> properties = autoIndexer.getAutoIndexedProperties();
       Transaction tx = db.beginTx();
       int count = 0;
       for (PropertyContainer pc : elements) {
           for (String property : properties) {
               if (!pc.hasProperty(property)) continue;
               pc.setProperty(property,pc.getProperty(property));
               count++;
               if (count % 10000 == 0) {
                   tx.success();
                   tx.finish();
                   tx = db.beginTx();
               }
           }
       }
       tx.success();
       tx.finish();
   }

'

@lassewesth
Copy link
Member Author


values:

@lassewesth
Copy link
Member Author

@jexp: so an AutoIndexer.reindex() would be sensible.

@jakewins
Copy link
Contributor

jakewins commented Nov 3, 2013

This is addressed by the new indexing being released in 2.0, where the database ensures indexes are kept up-to-date with data changes automatically.

@jakewins jakewins closed this as completed Nov 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants