Mercurial Hosting > junotu
changeset 70:fc040f668d55
Database: Added 'databaseResaveAll()' function
Not called from anywhere yet, but it's useful for introducing new fields to databases that don't have them. For example, in this case -- 'search' field.
author | Fox |
---|---|
date | Sat, 24 Dec 2022 12:16:19 +0100 |
parents | 6019854233a7 |
children | dfedca84c36b |
files | src/junotu/Database.java |
diffstat | 1 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/Database.java Sat Dec 24 01:53:55 2022 +0100 +++ b/src/junotu/Database.java Sat Dec 24 12:16:19 2022 +0100 @@ -103,6 +103,31 @@ throw new RuntimeException(e); } } + + public void databaseResaveAll() + { + System.out.print("Database: resaving all cards without modifying edit timestamp..\n"); + try { + TopDocs topDocuments = luceneSearcher.search( + new MatchAllDocsQuery(), + 1000000 + ); + + Card card; + for( int i = 0; i < topDocuments.scoreDocs.length; i++ ) { + Document document = luceneSearcher.doc( topDocuments.scoreDocs[i].doc ); + card = cardFromDocument( document ); + Query query = NumericRangeQuery.newLongRange( Card.TAG_IDENTIFIER, card.identifierGet(), card.identifierGet(), true, true ); + luceneWriter.deleteDocuments( query ); + luceneWriter.addDocument( cardToDocument( card ) ); + } + + searcherRefresh(); + + } catch( IOException e ) { + throw new RuntimeException(e); + } + } private void searcherRefresh() {