9

Sorry for the generalized question...I have been hunting for a long time and haven't found anything I can use or easily adapt yet. I'd really appreciate any pointers!

I'm building a reference app that will contain several textbooks in plain-text format. I want the user to be able to perform a search, and get a table back with a list of results. I have a working prototype, but the search logic that I wrote isn't all that smart and it's been hell trying to make it better.

This is obviously a fairly common problem so I'm looking for a tool that I could adapt to the task. So far I've found Lucene (http://vafer.org/blog/20090107014544/) and Locayta (http://www.locayta.com/iOS-search-engine/locayta-search-mobile/)

Lucene appears to have been last updated for iOS 2...I don't even know if I'll be able to rework it myself. Maybe.

Locayta would probably work great, but a commercial license is $1,000 and I may not soon recoup that with this app, as it's a niche market.

Thanks!

Reid
  • 1,109
  • 1
  • 12
  • 27
  • Well, think I have one possible solution: https://github.com/TonnyXu/sqliteFTS I will have to read up a lot on SQLite as I've never used it directly, but this seems to be what I'm looking for. I still appreciate any references that others can provide. Thanks! – Reid Apr 10 '13 at 21:24
  • Added bounty because I'm still looking for some guidance...I've found a few open-source things (LuceneKit, FTS, some SQL extensions) but haven't been able to successfully implement any of them...e.g., I can't even get them into my project. Most are hopelessly outdated and don't appear to be maintained. No tutorials I can follow, either. Some sites say FTS is included in iOS SQLite, others tell you to do a huge song and dance and build your own static library...what the heck? I'm just lost. Appreciate any help. – Reid Apr 14 '13 at 01:46

2 Answers2

5

We stumbled upon the same predicament where I work, and have yet to decide on a solution. Locayta seems promising, but barring that, I've looked into SQLite's FTS3/FTS4 as well.

The only issue seemed the lack of a way to match partial words. It's easy to search for fields that contain whole words (eg. "paper" matches "printer paper", "paper punch", and "sketch paper"), or words that start with something (eg. "bi*" matches "binder", and "bicycle"), but there's no built in way to match a suffix.

If you don't require that functionality, FTS3/FTS4 might work.

I see you mentioned in the follow-up that your SQLite didn't recognize FTS3(), and I had the same issue at first. Apparently it's not bundled into the iOS version by default, instead you have to download the SQLite3 amalgamation, and include it in the project manually. As found at is FTS available in the iOS build of SQLite?

Also note, the SQLITE_ENABLE_FTS3 variable is not enabled by default, you just have to add it to the configuration as detailed at http://www.sqlite.org/fts3.html#section_2

Hope this helps.

Community
  • 1
  • 1
Luca
  • 346
  • 1
  • 4
  • I definitely appreciate the help, thank you. It's been very tough for me to find iOS-specific instructions on SQLite...I can find SQLite statements, but I don't really know what to do with them, in other words. I can't program in straight C and the various wrappers are bewildering. I've accepted that there is simply no easy solution to do this and it's going to extend my dev time by some weeks. Very surprising since I figure this is a pretty common problem and thought there'd be some good open-source stuff. I sure wish Apple would enable Spotlight in iOS!!! – Reid Apr 15 '13 at 23:26
  • I may just go back to using my old "rangeOfString" method...it took a few seconds but it worked. I thought FTS would be reasonably easy to implement but I'm finding it nigh-on-impossible. There are zero tutorials that actually guide you through the process of setting it up. I'm new to this platform so I know Core Data, but never messed with SQLite directly--all the resources I've found seem to assume that you're a SQLite pro already. Oh well. – Reid Apr 15 '13 at 23:29
  • @ReidBelton Yes, I don't know of any way to use FTS through Core Data. It involves direct interaction with SQLite. Once enabled you have to create a virtual table with the fields you want to search against, and run SQLite queries against that. I can see how it would be quite a hassle if you're not familiar with direct database interaction. – Luca Apr 17 '13 at 11:43
  • @ReidBelton - be sure to file an enhancement request for Apple to port SearchKit from Mac to iOS. – Aaron Brager Apr 17 '13 at 18:43
  • I realize now there's no magic solution as I had hoped...but you provided the most detailed and clear info. Thanks! – Reid Apr 20 '13 at 23:51
4

If you can translate plain C code to iOS Objective-C, then Apache Lucy (a loose "C" port of Lucene) might be worth a look.

Mark Leighton Fisher
  • 5,609
  • 2
  • 18
  • 29
  • I did the same. And because it is pure C, you can call it directly from Swift 4+, so there is no need to build any bridge in Objective-C. – ervinbosenbacher Jan 15 '19 at 13:34