42

I am using a MySQL database and have been using database driven search. Any advantages and disadvantages of database engines and Lucene search engine? I would like to have suggestions about when and where to use them?

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
S L
  • 14,262
  • 17
  • 77
  • 116

4 Answers4

36

I suggest you read Full Text Search Engines vs. DBMS. A one-liner would be: If the bulk of your use case is full text search, use Lucene. If the bulk of your use case is joins and other relational operations, use a database. You may use a hybrid solution for a more complicated use case.

ham-sandwich
  • 3,975
  • 10
  • 34
  • 46
Yuval F
  • 20,565
  • 5
  • 44
  • 69
  • i have seen 'search our site' in lots of sites. If I am to search the content of sites, then which would be better? – S L Jan 09 '11 at 12:25
  • 1
    Searching a site is full-text search. Therefore, Lucene is better. Better still, use Solr: http://lucene.apache.org/solr/ – Yuval F Jan 09 '11 at 12:42
  • @YuvalF if the database is not large and the user of that site is not so many, is DBMS based full text query enough? since sometimes if that guy want to use lucene, he must develop it by himself ... – hugemeow Sep 19 '12 at 06:42
  • 1
    @hugemeow - sure. A DBMS's full-text search will be fine for small use cases. If you want to use Lucene, you can use Solr or ElasticSearch - both much easier to start working with than bare Lucene, and providing at least 90% of Lucene's functionality. I have also heard nice things about Sphinx, though have never used it myself. – Yuval F Sep 19 '12 at 06:59
  • I have updated the link. Also see my Quora answer about a related subject, where I have added the NoSql option: http://www.quora.com/ElasticSearch/Does-it-make-sense-to-use-Lucene-based-products-ElasticSearch-Solr-as-a-datastore – Yuval F Nov 17 '13 at 10:03
27

Use Lucene when you want to index textual Documents (of any length) and search for Text within those documents, returning a ranked list of documents that matched the search query. The classic example is search engines, like Google, that uses text indexers like Lucene to index and query the content of web pages.

The advantages of using Lucene over a database like Mysql, for indexing and searching text are:

  • for the developer - tools to analyse, parse and index textual information (e.g. stemming, plurals, synonyms, tokenisation) in multiple languages. Lucene also scales very well for text search.
  • for the user - quality search results. Lucene uses a very good similarity function (to compare the search query against each document), at the heart of which are the Cosine Similarity and Inverse Term/Document frequency. This results in good search results with very little tweaking required upfront.

Lots of useful info on Lucene here.

Joel
  • 29,538
  • 35
  • 110
  • 138
  • is there any more advantageous alternative to Lucene . Opensource or proprietor (Paid or REST API) – Ravinder Payal May 15 '16 at 17:06
  • 1
    @RavinderPayal Most open source search engines are built on top of Lucene - e.g. Solr and Elasticsearch. If you don't have a need to store billions of documents and want something that's fast and simple, take a look at something like Typesense: https://github.com/typesense/typesense – jeffreyveon Apr 06 '18 at 05:45
  • @jeffreyveon type-sense seems reasonable, will dig more in depth – Ravinder Payal Apr 13 '18 at 07:03
3

We used Sql Server at work to make some queries which used Fulltext search. In case of big amounts of data Sql makes an inner join between result set returned by FullText search and the rest of the query which might be slow if database is running on the low powered machine (2GB ram for 20 GB of data). Switching the same query to Lucene improved speed considerably.

Eugeniu Torica
  • 7,484
  • 12
  • 47
  • 62
2

Lucene search has a advantage of indexing. This post can help you understand lucene.

Community
  • 1
  • 1
Harry Joy
  • 58,650
  • 30
  • 162
  • 207
  • i think we can also add index on database table. but i don't have a clue about what is it? – S L Jan 09 '11 at 10:30