Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lucece Indexing


Published on

Published in: Technology

Lucece Indexing

  1. 1. LUCENE Indexing.....
  2. 2. What is a Search Index <ul><li>Search Index is a variant of Database </li></ul><ul><li>Similarities with traditional RDBMS </li></ul><ul><ul><li>Needs to have fast lookup for keys </li></ul></ul><ul><ul><li>Bulk of data resides on secondary storage </li></ul></ul><ul><ul><li>Minimize secondary storage access </li></ul></ul><ul><li>Differences(additions) compared to RDBMS </li></ul><ul><ul><li>No definitive score, returns only top k ranked hits </li></ul></ul><ul><ul><li>Relaxed transactional requirements </li></ul></ul><ul><ul><li>Two-level processing required ( details later..) </li></ul></ul>
  3. 3. Requirements of a Search Index <ul><li>Minimize disk access at the expense of CPU </li></ul><ul><li>Indexing </li></ul><ul><ul><li>Support for Dynamic Indexing </li></ul></ul><ul><ul><ul><li>Relatively fast indexing without compromising search time. </li></ul></ul></ul><ul><ul><ul><li>Simultaneous search/indexing </li></ul></ul></ul><ul><ul><li>Index Compression </li></ul></ul><ul><ul><ul><li>Speeds up overall process by resulting in less I/O </li></ul></ul></ul><ul><li>Searching </li></ul><ul><ul><li>Needs an inverted index for efficient search </li></ul></ul><ul><ul><li>Merge search results for different query terms </li></ul></ul>
  4. 4. Indexing Strategies <ul><li>Primarily requires a sorted list of terms postings </li></ul><ul><li>Possible Data Structures </li></ul><ul><ul><li>B-Tree based – O(log b N) </li></ul></ul><ul><ul><ul><li>Requires random access, hence frequent disk seeks </li></ul></ul></ul><ul><ul><li>Merge based – O(log k N) </li></ul></ul><ul><ul><ul><li>Sorts in-memory, then merge the sorted runs/segments </li></ul></ul></ul><ul><ul><ul><ul><li>Creates new segments for newly added documents </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Merge existing segments </li></ul></ul></ul></ul><ul><ul><li>Trie Based – O(term-length) </li></ul></ul><ul><ul><ul><li>Requires random access, frequent disk seeks </li></ul></ul></ul>
  5. 5. Lucene Indexing Fundamentals <ul><li>An index contains a collection of documents </li></ul><ul><li>A document is a collection of fields </li></ul><ul><li>A field is a named collection of terms </li></ul><ul><li>A term is a paired string <field,term-string> </li></ul><ul><li>Inverted Index for efficient term-based search </li></ul>
  6. 6. Some Indexing Terms <ul><li>Fields ( Independent search space) </li></ul><ul><ul><li>Unlike CPL, fields are defined at run-time </li></ul></ul><ul><ul><li>Field Types : stored,indexed,tokenized </li></ul></ul><ul><ul><ul><li>A field can be both stored and indexed </li></ul></ul></ul><ul><ul><ul><li>An indexed field can be tokenized </li></ul></ul></ul><ul><li>Segments (sub indexes) </li></ul><ul><ul><li>Independent searchable index </li></ul></ul><ul><ul><li>Lucene index evolves with segments getting added/merged </li></ul></ul><ul><ul><li>Search results from segments are merged </li></ul></ul>
  7. 7. Merge Algorithm <ul><ul><li>Maintain a stack of Segment Indexes </li></ul></ul><ul><ul><li>Create a segment/index for every doc added </li></ul></ul><ul><ul><li>Push new indexes into a stack </li></ul></ul><ul><ul><li>For (size=1;size < INF; size *= b) { </li></ul></ul><ul><ul><ul><li>If (exists b indexes of size docs on top of stack) { </li></ul></ul></ul><ul><ul><ul><ul><li>Pop them off the stack </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Merge them into a single index </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Push the merged index onto the stack </li></ul></ul></ul></ul><ul><ul><ul><li>} Else { </li></ul></ul></ul><ul><ul><ul><ul><li>break </li></ul></ul></ul></ul><ul><ul><ul><li>} } </li></ul></ul></ul>
  8. 8. Lucene Indexing Algorithm <ul><li>K-way merge – process at disk transfer rate </li></ul><ul><li>Average b*logN indexes </li></ul><ul><ul><li>n=1M,b=2 gives 20 indexes </li></ul></ul><ul><ul><li>Fast to update and not too slow to search </li></ul></ul><ul><li>Optimization </li></ul><ul><ul><li>Small sized segments kept in RAM, saves I/O calls </li></ul></ul>
  9. 9. Search Algorithm <ul><li>Uses Inverted Index </li></ul><ul><ul><li>Data Structure : term->doc-entries postings </li></ul></ul><ul><ul><li>Use skip lists to speed up search </li></ul></ul><ul><li>Merge postings from different query terms </li></ul><ul><ul><li>Efficient relevancy score calculation </li></ul></ul><ul><ul><li>Use Vector Space Model for similarity calculation </li></ul></ul><ul><ul><li>Parallel merge algorithm </li></ul></ul>
  10. 10. A Lucene Segment <SegName, SegSize> SegCount Version Name Counter SegCount Format
  11. 11. Per Index Files <ul><ul><li>Segments File (“segments” file) </li></ul></ul><ul><ul><ul><li>Segments --> Format, Version, NameCounter, SegCount, <SegName, SegSize>^SegCount </li></ul></ul></ul><ul><ul><li>Lock Files </li></ul></ul><ul><ul><ul><li>Several files are used to indicate that another process is using an index. These are stored in </li></ul></ul></ul><ul><ul><li>Deletable Files </li></ul></ul><ul><ul><ul><li>Only used on Win32, where a file may not be deleted while it is still open </li></ul></ul></ul><ul><ul><li>Compound files (“.fcs” file, just a container) </li></ul></ul><ul><ul><ul><li>Compound (.cfs) --> FileCount, <DataOffset, FileName>^FileCount, FileData^FileCount </li></ul></ul></ul>
  12. 12. Per Segment Files <ul><li>Each segment has the following : </li></ul><ul><ul><li>Field names (e.g. Title, content etc.) </li></ul></ul><ul><ul><li>Stored Field Values ( e.g. Urls ) </li></ul></ul><ul><ul><li>Term dictionary </li></ul></ul><ul><ul><ul><li>A dictionary containing all of the terms used in all of the indexed fields of all of the documents. It also contains the number of documents which contain the term, and pointers to the term's frequency and proximity data. </li></ul></ul></ul><ul><ul><li>Term Frequency data. </li></ul></ul><ul><ul><ul><li>For each term in the dictionary, the numbers of all the documents that contain that term, and the frequency of the term in that document. </li></ul></ul></ul>
  13. 13. FileFormat (contd..) <ul><ul><li>Term Proximity data </li></ul></ul><ul><ul><ul><li>For each term in the dictionary, the positions that the term occurs in each document. </li></ul></ul></ul><ul><ul><li>Term Vectors </li></ul></ul><ul><ul><ul><li>For each field in each document, the term vector (sometimes called document vector) is stored. A term vector consists of term text and term frequency. </li></ul></ul></ul><ul><ul><li>Normalization factors </li></ul></ul><ul><ul><ul><li>For each field in each document, a value is stored that is multiplied into the score for hits on that field. </li></ul></ul></ul><ul><ul><li>Deleted Documents </li></ul></ul>
  14. 14. Per Segment Files(prefix=segname) <ul><ul><li>Fields </li></ul></ul><ul><ul><ul><ul><li>Field Info ( .fnm file) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Stored Fields (.fdx and .fdt files) </li></ul></ul></ul></ul><ul><ul><li>Term Dictionary </li></ul></ul><ul><ul><ul><li>Term Infos (.tis file) </li></ul></ul></ul><ul><ul><ul><ul><li>TermInfoFile (.tis)--> TIVersion, TermCount, IndexInterval, SkipInterval, TermInfos </li></ul></ul></ul></ul><ul><ul><ul><li>Term Info Index (.tii file) </li></ul></ul></ul><ul><ul><ul><ul><li>This contains every IIth entry from the .tis file, along with its location in the &quot;tis&quot; file. This is designed to be read entirely into memory and used to provide random access to the &quot;tis&quot; file. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>TermInfoIndex (.tii)--> TIVersion, IndexTermCount, IndexInterval, SkipInterval, TermIndices </li></ul></ul></ul></ul>
  15. 15. Per Segment Files (contd..) <ul><ul><li>Frequencies (.frq or the doc postings file) </li></ul></ul><ul><ul><ul><li>Contains lists of documents which contain each term, along with the frequency of the term in that document. </li></ul></ul></ul><ul><ul><ul><li>Referred in .tis file as FreqData (with delta encoding) </li></ul></ul></ul><ul><ul><li>Positions (.prx file) </li></ul></ul><ul><ul><ul><li>Contains list of term positions within the documents </li></ul></ul></ul><ul><ul><ul><li>Used for Span Query, Phrase Query searches </li></ul></ul></ul><ul><ul><li>Normalization (.f[0-9]* files) </li></ul></ul><ul><ul><ul><li>A Norm file (.fn) for each indexed field with a byte/doc </li></ul></ul></ul>
  16. 16. Segment layout T i+1 T j+k T j T i .tii file (in memory) .tis file (in disk) Random seeks Contiguous reads T q IndexDelta .frq/posting file (in disk) T q+1 Term DocFreq FreqDelta ProxDelta SkipDelta TF 1 TF d Posting-list(term-freqs) SD 1 SD d/sk SD 2 DocId FreqSk TF sk ProxSk .prx file Used to merge postings
  17. 17. Index Compression <ul><li>Variable byte encoding </li></ul><ul><ul><li>Need very fast decoding (byte-align) </li></ul></ul><ul><ul><li>Given a binary representation </li></ul></ul><ul><ul><ul><li>Form groups of 7-bits each (i.e. Block of 128) </li></ul></ul></ul><ul><ul><ul><li>If 1 st bit is 1 append the next 2-8 bits, do it recursively </li></ul></ul></ul><ul><li>Front Encoding of terms </li></ul><ul><ul><ul><li>Sorted terms commonly have long common prefix </li></ul></ul></ul><ul><ul><ul><ul><li>8,automata,8,automate,9,automatic,10,automation </li></ul></ul></ul></ul><ul><ul><ul><ul><li>0,automata,7,e,7,ic,7,ion (huge saving....) </li></ul></ul></ul></ul><ul><ul><ul><li>Works only if they are sorted lexicographically </li></ul></ul></ul>
  18. 18. Search Algorithm <ul><li>Posting Lists (from .frq file) </li></ul><ul><ul><li>For every term Ti, we have a posting list </li></ul></ul><ul><ul><ul><li>Ti -> (Doc-id,Freq(d,t)) * </li></ul></ul></ul><ul><ul><ul><li>Ti's are sorted lexically, so are posting list on doc-id </li></ul></ul></ul><ul><ul><li>Postings are delta encoded(for Index Compression) </li></ul></ul><ul><li>Based on Vector Space Model </li></ul><ul><ul><li>Conjunctive Search Algorithm (AND queries) </li></ul></ul><ul><ul><li>Disjunctive Search Algorithm (OR queries) </li></ul></ul>
  19. 19. Vector Space Model <ul><li>Terms constitute the space (or the axes) </li></ul><ul><li>Document/query are represented as a vector </li></ul><ul><li>Use cosine as a similarity measure (for docs) </li></ul><ul><li>Query is a short doc </li></ul><ul><li>TF-IDF weighting scheme </li></ul><ul><ul><li>Tf * log(n/nt) </li></ul></ul>
  20. 20. Search Algorithm (contd.) <ul><li>Conjunctive Search Algorithm </li></ul><ul><ul><li>The AND merge </li></ul></ul><ul><ul><ul><li>Walk through 2 postings simultaneously, O(m+n) </li></ul></ul></ul><ul><ul><ul><li>Crucial – postings sorted by doc-id </li></ul></ul></ul><ul><ul><li>Use skip pointers to speed up merge </li></ul></ul><ul><li>Disjunctive search Algorithm </li></ul><ul><ul><ul><li>All postings should be merged </li></ul></ul></ul><ul><ul><ul><li>Minimize per postings processing </li></ul></ul></ul>
  21. 21. Others.. <ul><li>Positional Queries </li></ul><ul><ul><li>Use positional information for doc/term tuple </li></ul></ul><ul><li>Range Queries </li></ul><ul><ul><li>Date Range queries </li></ul></ul><ul><li>Stemming </li></ul><ul><ul><li>Porter Stemmer Algorithm </li></ul></ul><ul><li>Configurable Similarity algorithms </li></ul>
  22. 22. Open ended questions <ul><li>Incremental Update to docs </li></ul><ul><ul><li>Relevant to our focused crawl (for av files) </li></ul></ul><ul><ul><li>Hard problem to solve </li></ul></ul><ul><li>Deficiencies in VSM </li></ul><ul><ul><li>Need exact query terms </li></ul></ul><ul><ul><li>Use auto-classification/clustering </li></ul></ul><ul><li>Q/A...... </li></ul>