将Lucene与Android集成时出错

u0njafvf  于 10个月前  发布在  Lucene
关注(0)|答案(1)|浏览(86)
03-28 15:52:36.586 25855-25855/? D/dalvikvm: Late-enabling CheckJNI
03-28 15:52:37.021 25855-25855/com.example.myapplication2.app E/TAG: START/data/data/com.example.myapplication2.app/lib-----INDEX 2 :/storage/emulated/0/Notes/sFileName
03-28 15:52:37.421 25855-25855/com.example.myapplication2.app I/dalvikvm: Could not find method java.io.File.toPath, referenced from method org.apache.lucene.store.NIOFSDirectory.createSlicer
03-28 15:52:37.422 25855-25855/com.example.myapplication2.app W/dalvikvm: VFY: unable to resolve virtual method 8318: Ljava/io/File;.toPath ()Ljava/nio/file/Path;
03-28 15:52:37.422 25855-25855/com.example.myapplication2.app D/dalvikvm: VFY: replacing opcode 0x6e at 0x000c
03-28 15:52:37.422 25855-25855/com.example.myapplication2.app I/dalvikvm: Could not find method java.io.File.toPath, referenced from method org.apache.lucene.store.NIOFSDirectory.openInput
03-28 15:52:37.422 25855-25855/com.example.myapplication2.app W/dalvikvm: VFY: unable to resolve virtual method 8318: Ljava/io/File;.toPath ()Ljava/nio/file/Path;
03-28 15:52:37.422 25855-25855/com.example.myapplication2.app D/dalvikvm: VFY: replacing opcode 0x6e at 0x000c
03-28 15:52:37.422 25855-25855/com.example.myapplication2.app I/dalvikvm: DexOpt: unable to optimize static field ref 0x0d85 at 0x14 in Lorg/apache/lucene/store/NIOFSDirectory;.createSlicer
03-28 15:52:37.422 25855-25855/com.example.myapplication2.app I/dalvikvm: DexOpt: unable to optimize static field ref 0x0d85 at 0x14 in Lorg/apache/lucene/store/NIOFSDirectory;.openInput
03-28 15:52:37.424 25855-25855/com.example.myapplication2.app I/System.out: in --------- indexd path NIOFSDirectory@/storage/emulated/0/Notes/sFileName lockFactory=NativeFSLockFactory@/storage/emulated/0/Notes/sFileName
03-28 15:52:37.587 25855-25855/com.example.myapplication2.app I/dalvikvm: Could not find method java.io.File.toPath, referenced from method org.apache.lucene.util.IOUtils.fsync
03-28 15:52:37.587 25855-25855/com.example.myapplication2.app W/dalvikvm: VFY: unable to resolve virtual method 8318: Ljava/io/File;.toPath ()Ljava/nio/file/Path;
03-28 15:52:37.587 25855-25855/com.example.myapplication2.app D/dalvikvm: VFY: replacing opcode 0x6e at 0x0001
03-28 15:52:37.588 25855-25855/com.example.myapplication2.app I/dalvikvm: DexOpt: unable to optimize static field ref 0x0d85 at 0x0b in Lorg/apache/lucene/util/IOUtils;.fsync
03-28 15:52:37.588 25855-25855/com.example.myapplication2.app I/dalvikvm: DexOpt: unable to optimize static field ref 0x0d86 at 0x24 in Lorg/apache/lucene/util/IOUtils;.fsync
03-28 15:52:37.631 25855-25855/com.example.myapplication2.app W/dalvikvm: VFY: unable to resolve exception class 1120 (Ljava/nio/file/NoSuchFileException;)
03-28 15:52:37.631 25855-25855/com.example.myapplication2.app W/dalvikvm: VFY: unable to find exception handler at addr 0xe
03-28 15:52:37.631 25855-25855/com.example.myapplication2.app W/dalvikvm: VFY:  rejected Lorg/apache/lucene/index/IndexWriter;.slowFileExists (Lorg/apache/lucene/store/Directory;Ljava/lang/String;)Z
03-28 15:52:37.631 25855-25855/com.example.myapplication2.app W/dalvikvm: VFY:  rejecting opcode 0x0d at 0x000e
03-28 15:52:37.631 25855-25855/com.example.myapplication2.app W/dalvikvm: VFY:  rejected Lorg/apache/lucene/index/IndexWriter;.slowFileExists (Lorg/apache/lucene/store/Directory;Ljava/lang/String;)Z
03-28 15:52:37.631 25855-25855/com.example.myapplication2.app W/dalvikvm: Verifier rejected class Lorg/apache/lucene/index/IndexWriter;
03-28 15:52:37.631 25855-25855/com.example.myapplication2.app D/AndroidRuntime: Shutting down VM
03-28 15:52:37.632 25855-25855/com.example.myapplication2.app W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4162fd40)
03-28 15:52:37.633 25855-25855/com.example.myapplication2.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapplication2.app, PID: 25855
    java.lang.VerifyError: org/apache/lucene/index/IndexWriter
    at com.example.myapplication2.app.Lucene2.openIndex(Lucene2.java:124)
    at com.example.myapplication2.app.Lucene2.createIndex(Lucene2.java:87)
    at com.example.myapplication2.app.MainActivity.onCreate(MainActivity.java:42)
    at android.app.Activity.performCreate(Activity.java:5248)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
    at android.app.ActivityThread.access$800(ActivityThread.java:139)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5086)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)
03-28 15:57:37.984 25855-25855/com.example.myapplication2.app I/Process: Sending signal. PID: 25855 SIG: 9

字符串
代码可以与java实现一起使用,但不能与android一起使用。是否有任何方法可以使用Gradle依赖项来避免此类错误。

wbgh16ku

wbgh16ku1#

要在Android中使用Lucene,您可以:

package com.texopher.gophoxes;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.UUID;

import org.apache.lucene.store.BaseDirectory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.LockFactory;

public class BucketDirectory extends BaseDirectory {

    protected Bucket bucket;
    
    public BucketDirectory(Bucket bucket, LockFactory lockFactory) {
        super(lockFactory);
        this.bucket = bucket;
    }

    @Override
    public void close() throws IOException {
    }

    @Override
    public IndexOutput createOutput(String name, IOContext context) throws IOException {
        return new BucketIndexOutput(bucket, name);
    }

    @Override
    public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException {
        return new BucketIndexOutput(bucket, prefix + UUID.randomUUID().toString().replaceAll("-", "") + suffix);
    }

    @Override
    public void deleteFile(String name) throws IOException {
        try {
            bucket.deleteFile(name);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public long fileLength(String name) throws IOException {
        try {
            return bucket.fileLength(name);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public String[] listAll() throws IOException {
        String[] tag = new String[0];
        try {
            List<String> tmp = bucket.listFiles();
            tag = new String[tmp.size()];
            for (int i = 0; i < tmp.size(); i++) {
                tag[i] = tmp.get(i);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tag;
    }

    @Override
    public IndexInput openInput(String name, IOContext context) throws IOException {
        try {
            return new BucketIndexInput(bucket, name);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void rename(String source, String dest) throws IOException {
        try {
            bucket.rename(source, dest);;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void sync(Collection<String> arg0) throws IOException {
    }

    @Override
    public void syncMetaData() throws IOException {
    }

}

字符串

  • 使用以下代码进行搜索:
Query qr = new TermQuery(new Term("code", this.md5(link)));
Bucket bk = new Bucket(this.gopherServer, this.hole, this.magic);
Directory indexDirectory = new BucketDirectory(bk, new SingleInstanceLockFactory());
IndexReader reader = DirectoryReader.open(indexDirectory);
IndexSearcher searcher = new IndexSearcher(reader);
TopDocs docs = searcher.search(qr, 1);
ScoreDoc[] hits = docs.scoreDocs;

相关问题