ketki
ketki

Reputation: 91

Lucene in Android

I'm new to android and Lucene. can I use Lucene for search in android list view. I have tried importing the package 2.3.2 and also used the jar files in library. However, there is an error in SearchFiles.java error is :
The type java.rmi.Remote cannot be resolved. It is indirectly referenced from .class files.

There is a possibility that this file doesnt exist for android. Is this the problem?

Upvotes: 9

Views: 12132

Answers (6)

texopher
texopher

Reputation: 1

This repository modify Lucene 7.3.0 for using in Android 8.0: https://github.com/texophen/lucene-android

If it does not work, you can modify org.apache.lucene.util.AttributeFactory and add your type to bellow method:

  static final MethodHandle findAttributeImplCtor(Class<? extends AttributeImpl> clazz) {
    try {
      //org.apache.lucene.LucenePackage.writeLog("AttributeFactory.findAttributeImplCtor() - 1: " + lookup.findConstructor(clazz, NO_ARG_CTOR).toString());
      MethodHandle mh = null;
      if (lookup.findConstructor(clazz, NO_ARG_CTOR).toString().endsWith("PackedTokenAttributeImpl")) {
        mh = lookup.findConstructor(clazz, NO_ARG_CTOR).asType(MethodType.methodType(org.apache.lucene.analysis.tokenattributes.PackedTokenAttributeImpl.class));
      } else {
        mh = lookup.findConstructor(clazz, NO_ARG_CTOR).asType(NO_ARG_RETURNING_ATTRIBUTEIMPL);
      }
      //org.apache.lucene.LucenePackage.writeLog("AttributeFactory.findAttributeImplCtor() - 2: " + mh.toString());
      return mh;
    } catch (NoSuchMethodException | IllegalAccessException e) {
      throw new IllegalArgumentException("Cannot lookup accessible no-arg constructor for: " + clazz.getName(), e);
    }
  }

Upvotes: 0

JaydeepW
JaydeepW

Reputation: 3285

I think this demo app will work for you.

https://github.com/weiweiwang/quickdialer

It has:

  • fast T9 search
  • support 5000 contacts
  • 500 calllogs

Upvotes: 3

Hendy Irawan
Hendy Irawan

Reputation: 21454

You may want to use the native Full Text Search feature called FTS3 in SQLite instead, which is available in Android and it is faster (since it is running natively) and uses less memory than a Java Lucene implementation under Dalvik VM.

Upvotes: 10

Darko Vasilev
Darko Vasilev

Reputation: 51

  1. Delete "extends java.rmi.Remote" from the Class "org.apache.lucene.search.Searchable"
  2. Delete class "org.apache.lucene.search.RemoteSearchable"

Upvotes: 5

Konstantin Pribluda
Konstantin Pribluda

Reputation: 12367

Android is not java - it does not provide all standart java apis ( just look into android reference, java.rmi is not there ). However, it is possible to import almost everrything that is pure java ( if you have enough memory ). You may try to remove unnecessary classes which cause classloading problems from jars - bu it is a lot of work.

Upvotes: 3

Blackbelt
Blackbelt

Reputation: 157487

I've successfully used Lucene 3.3 for really simple search dute and it works. However, I have no idea what the memory usage impact is. In the 3.3 there is no dependency from RMI. If you need 2.3.2 and you have the source code you can free Lucene from the RMI dependency (I've read about a guy who succeeded in doing this).

Upvotes: 5

Related Questions