diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index a5e9493..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/target
-/gen
-.idea
diff --git a/AIS.iml b/AIS.iml
deleted file mode 100644
index 0e60fb0..0000000
--- a/AIS.iml
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
- true
-
- /res-overlay
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ca/dracode/ais/alarm/AutoStart.java b/src/ca/dracode/ais/alarm/AutoStart.java
index ba25bc5..6a00c83 100644
--- a/src/ca/dracode/ais/alarm/AutoStart.java
+++ b/src/ca/dracode/ais/alarm/AutoStart.java
@@ -26,6 +26,7 @@
import android.preference.PreferenceManager;
import ca.dracode.ais.service.FileListener;
+import ca.dracode.ais.service.IndexService;
public class AutoStart extends BroadcastReceiver {
@@ -41,6 +42,9 @@ public void onReceive(Context context, Intent intent) {
Alarm.SetAlarm(context);
Intent serviceIntent = new Intent(context, FileListener.class);
context.startService(serviceIntent);
+ serviceIntent = new Intent(context, IndexService.class);
+ serviceIntent.putExtra("crawl", true);
+ context.startService(serviceIntent);
}
}
}
diff --git a/src/ca/dracode/ais/indexer/FileIndexer.java b/src/ca/dracode/ais/indexer/FileIndexer.java
index 214a081..bd4b96c 100644
--- a/src/ca/dracode/ais/indexer/FileIndexer.java
+++ b/src/ca/dracode/ais/indexer/FileIndexer.java
@@ -26,6 +26,7 @@
* TODO - Evaluate the usefulness of ForceMerging as it increases total indexing time by about 17%
*/
+import android.content.Context;
import android.os.Environment;
import android.util.Log;
@@ -54,11 +55,18 @@ public class FileIndexer {
private IndexWriter writer;
private FileSearcher searcher;
- public FileIndexer() {
+ public FileIndexer(Context c) {
super();
- this.searcher = new FileSearcher();
+ this.searcher = new FileSearcher(c);
Directory dir;
try {
+ File lock = new File(FileIndexer.getRootStorageDir() + "/write.lock");
+ if(lock.exists()) {
+ lock.delete();
+ Log.e(TAG, "Lucene write lock exists when indexer isn't running, removing\n" +
+ "WARNING, Index may be corrupted");
+ if(lock.exists()) Log.e(TAG, "What?? Lock didn't delete");
+ }
dir = FSDirectory.open(new File(FileIndexer.getRootStorageDir()));
Analyzer analyzer = new SimpleAnalyzer(Version.LUCENE_47);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_47,
@@ -222,7 +230,6 @@ public int buildIndex(String filename, int pages) {
if(pages != -1) {
doc.add(new IntField("pages", pages, Field.Store.YES));
}
- Log.w(TAG, "" + writer);
if(writer.getConfig().getOpenMode() == OpenMode.CREATE) {
writer.addDocument(doc);
} else {
diff --git a/src/ca/dracode/ais/indexer/FileSearcher.java b/src/ca/dracode/ais/indexer/FileSearcher.java
index 2312928..cbc75b9 100644
--- a/src/ca/dracode/ais/indexer/FileSearcher.java
+++ b/src/ca/dracode/ais/indexer/FileSearcher.java
@@ -19,6 +19,8 @@
package ca.dracode.ais.indexer;
+import android.content.Context;
+import android.content.Intent;
import android.util.Log;
import org.apache.lucene.analysis.core.SimpleAnalyzer;
@@ -54,6 +56,7 @@
import java.util.LinkedHashMap;
import java.util.List;
+import ca.dracode.ais.alarm.AutoStart;
import ca.dracode.ais.indexdata.SearchResult;
/**
@@ -85,7 +88,7 @@ public class FileSearcher {
private IndexSearcher indexSearcher;
private int interrupt = -1;
- public FileSearcher() {
+ public FileSearcher(Context c) {
IndexReader indexReader;
IndexSearcher indexSearcher = null;
try {
diff --git a/src/ca/dracode/ais/service/IndexService.java b/src/ca/dracode/ais/service/IndexService.java
index 67df73c..7258035 100644
--- a/src/ca/dracode/ais/service/IndexService.java
+++ b/src/ca/dracode/ais/service/IndexService.java
@@ -167,7 +167,7 @@ public void onCreate() {
return;
}
Log.i(TAG, "Creating Indexer");
- this.indexer = new FileIndexer();
+ this.indexer = new FileIndexer(getApplicationContext());
Log.i(TAG, "Created Indexer");
this.pIndexes = new LinkedList();
this.doneCrawling = true;
@@ -493,4 +493,8 @@ IndexService getService() {
return IndexService.this;
}
}
+
+ public boolean isIndexing(){
+ return tasks != 0;
+ }
}
diff --git a/src/ca/dracode/ais/service/SearchService.java b/src/ca/dracode/ais/service/SearchService.java
index 63cafa4..f6c3a47 100644
--- a/src/ca/dracode/ais/service/SearchService.java
+++ b/src/ca/dracode/ais/service/SearchService.java
@@ -35,6 +35,7 @@
import java.util.List;
import ca.dracode.ais.indexdata.SearchResult;
+import ca.dracode.ais.indexer.FileIndexer;
import ca.dracode.ais.indexer.FileSearcher;
/**
@@ -114,6 +115,25 @@ public void onCreate() {
this.sm = new SearchManager();
this.data = new HashMap();
this.builtIndexes = new HashMap();
+ verifyIndex();
+ }
+
+ private void verifyIndex(){
+ File dir = new File(FileIndexer.getRootStorageDir());
+ if(!dir.exists()) {
+ dir.mkdirs();
+ if(mBoundService != null) mBoundService.crawl();
+ Log.i(TAG, "Index folder doesn't exist, creating...");
+ }
+ if(mBoundService != null && !mBoundService.isIndexing()){
+ File lock = new File(FileIndexer.getRootStorageDir() + "/write.lock");
+ if(lock.exists()) {
+ lock.delete();
+ Log.e(TAG, "Lucene write lock exists when indexer isn't running, removing\n" +
+ "WARNING, Index may be corrupted");
+ if(lock.exists()) Log.e(TAG, "What?? Lock didn't delete");
+ }
+ }
}
private void doBindService() {
@@ -167,6 +187,7 @@ public int buildIndex(int id, String filePath) {
* -1 if there was an error
*/
public int load(final String filePath) {
+ this.verifyIndex();
if(this.data.containsKey(filePath)) {
return 1;
}
@@ -214,7 +235,7 @@ private class SearchManager {
private FileSearcher searcher;
public SearchManager() {
- this.searcher = new FileSearcher();
+ this.searcher = new FileSearcher(getApplicationContext());
}
/**
diff --git a/src/ca/dracode/ais/ui/AISPreferences.java b/src/ca/dracode/ais/ui/AISPreferences.java
index 93549a7..cc0f30a 100644
--- a/src/ca/dracode/ais/ui/AISPreferences.java
+++ b/src/ca/dracode/ais/ui/AISPreferences.java
@@ -54,8 +54,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
@Override
public void onDestroy(){
- super.onDestroy();
if(indexInfo != null)
- indexInfo.close(this);
+ indexInfo.close(this);
+ super.onDestroy();
}
}