1 / 35

CS520 Web Programming Full Text Search with Lucene

Learn about full text search (FTS) using Lucene, an information retrieval system that deals with the storage, organization, and access of large amounts of textual data. Explore tokenization, stop words removal, stemming, and ranking to improve search accuracy and relevancy.

panthony
Download Presentation

CS520 Web Programming Full Text Search with Lucene

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS520 Web ProgrammingFull Text Search with Lucene Chengyu Sun California State University, Los Angeles

  2. Search Text • Web search • Desktop search • Applications • Search posts in a bulletin board • Search product descriptions at an online retailer • …

  3. Database Query • Find the posts regarding “SSHD login errors”. select * from posts where content like‘%SSHD login errors%’; Here are the steps to take to fix the SSHD login errors: … Please help! I got SSHD login errors!

  4. Problems with Database Queries • And how about performance?? Please help! I got an error when I tried to login through SSHD! There a problem recently discovered regarding SSHD and login. The error message is usually … The solution for sshd/loginerrors: …

  5. Full Text Search (FTS) • More formally known as Information Retrieval (IR) • Deals with the representation, storage, organization, and access of LARGE quantity of textual data.

  6. Characteristics of FTS • Vs. database • “Fuzzy” query processing • Relevancy ranking

  7. Accuracy of FTS # of relevant documents retrieved Precision = # of documents retrieved # of relevant documents retrieved Recall = # of relevant documents

  8. Journey of a Document document Stripping non-textual data tokenizing Removing stop words Stemming index Indexing

  9. Original Text-only Document <html> <body> <p>The solution for sshd/login errors: …</p> </body> <html> The solution for sshd/login errors: …

  10. Tokenizing [the] [solution] [for] [sshd] [login] [errors] …

  11. Chinese Text Example Text: 今天天气不错。 Unigram: [今] [天] [天] [气] [不] [错] Bigram: [今天] [天天] [天气] [气不] [不错] Grammar-based: [今天] [天气] [不错]

  12. Stop Words • Words that do not help in search and retrieval • Function words: a, an, and, the, of, for … • Domain specific: “to be or not to be” • After stop words removal: [the] [solution] [for] [sshd] [login] [errors] …

  13. Stemming • Reduce a word to its stem or root form. • Examples: connection, connections connected, connecting connective connect [solution] [sshd] [login] [errors] … [solve] [sshd] [login] [error] …

  14. Inverted Index # of occurrences # of words position 22 5 234 cat documents dog buckets keywords

  15. Query Processing Query tokenizing Removing stop words Stemming Searching results Ranking

  16. Ranking • How well the document matches the query • E.g. weighted vector distance • How “important” the document is • E.g. based on ratings, citations, and links

  17. FTS Implementations • Databases • MySQL: MyISAM tables only • PostgreSQL: tsearch2 module; OpenFTS • Oracle, DB2, MS SQL Server, ... • Standard-alone IR libraries • Lucene, Egothor, Xapian, MG4J, … • Database vs. Standard-alone Library??

  18. Lucene Overview • http://lucene.apache.org/ • Originally developed by Doug Cutting • THE full text search solution for Java applications • Handles text only – needs external converters to convert other document types to text

  19. Example 1: Index Text Files • Directory • Document and Field • Analyzer • IndexWriter

  20. Directory • A place where the index files will be stored • FSDirectory – file system directory • RAMDirectory – virtual directory in memory

  21. Document • A document consists of a number of user-defined fields Title: FTS with Lucene Fields Author: Chengyu Sun Content: lots of words … lots of words …

  22. Types of Fields • Indexed – whether the field is indexed • Tokenized • Untokenized • Stored – whether the original text is stored together with the index

  23. Common Usage of Field Types

  24. Analyzer • Pre-processing the document or query text – tokenization, stop words removal, stemming … • Lucene built-in analyzers • WhitespaceAnalyzer, SimpleAnalyzer, StopAnalyzer • StandardAnalyzer • Grammer-based • Recognize special tokens such as email addresses • Handle CJK text

  25. IndexWriter • addDocument( Document ) • close() • optimize()

  26. Example 2: Search • Query and QueryParser • IndexSearcher • Hits • Document (again)

  27. Query and QueryParser Query ::= ( Clause )* Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )

  28. Sample Queries full text search +full +text search +full +text –search +title:“text search” +(title:full title:text) -author:“john doe"

  29. IndexSearcher • search( Query ) • close()

  30. Hits • A ranked list of documents used to hold search results • Methods • Document doc( int n ) • int id( int n ) • int length() • float score( int n ) – normalized score

  31. Factors in Lucene Score • # of times a term appears in a document • # of documents that contain the term • # of query terms found • length of a field • boost factor - field and/or document • query normalizing factor – does not affect ranking See the API documentation for the Similarity class.

  32. Document (again) • Methods to retrieve data stored in the document • String get( String name ) • Field getField( String name )

  33. Handle Rich Text Documents • HTML • NekoHTML, JTidy, TagSoup • PDF • PDFBox • MS Word • TextMining, POI • More at Lucence FAQ - http://wiki.apache.org/jakarta-lucene/LuceneFAQ

  34. Example: FTS in Evelyn • Indexer and Searcher interface • FileHandler interface • File handler implementations • DefaultFileHandler • TextFileHandler • HtmlFileHandler • PdfFileHandler • Spring beans configuration

  35. Further Readings • Lucene in Action by Otis Gospodnetic and Erik Hatcher • Hibernate Search Reference Guide - http://www.hibernate.org/hib_docs/search/reference/en/html/

More Related