0

I am developing a mobile application by using Lucene. I have a folder which includes index files. In the application, I want to use these index files for searching. Lucene Library expects path of this folder to read. I placed this folder in the assets folder. But I can't get this folder's path. I checked Android Storage Documentation. But I could not find any solution to add existing folder to external storage. If I would add them to external storage, I can get the path with getExternalFilesDir(). I am working by using emulator.

Directory dir = FSDirectory.open(Paths.get("path of index folder"));
IndexReader reader = DirectoryReader.open(dir);
searcher = new IndexSearcher(reader);

Above code section works well in a Java SE application since I can give the path of folder directly. But In android I am working by using emulator. How can give path of index folder in android? Where should I place this folder to reach in the application?

candreva
  • 57
  • 6

1 Answers1

0

You put them into the folder into your assets, then copy the assets to the file system on first run. Then you can pass the location you wrote them to to Lucene.

Fair warning: I tried to use Lucene and couldn't a year ago, because it was using IO functions that weren't ported to Android. Now that Java 1.8 exists on Android maybe they have been, but if not you're going to have additional problems to solve.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • thanks for the answer. I wrote the index files to internal storage. I get the path of index folder by using "getFilesDir().toString()". As you said, Since java 1.8 exist, Lucene is working in android now. note: Lucene version 7.0.1 sdk 26 – candreva Dec 05 '17 at 12:09