Information Retrieval

Similar documents
Information Retrieval

SEARCHING AND INDEXING BIG DATA. -By Jagadish Rouniyar

Informa(on Retrieval

Introduc)on to Lucene. Debapriyo Majumdar Information Retrieval Spring 2015 Indian Statistical Institute Kolkata

Informa(on Retrieval. Introduc*on to. Lucene Tutorial

LUCENE - FIRST APPLICATION

EPL660: Information Retrieval and Search Engines Lab 2

COMP Implemen0ng Search using Lucene

Lucene. Jianguo Lu. School of Computer Science. University of Windsor

LUCENE - BOOLEANQUERY

Lucene Java 2.9: Numeric Search, Per-Segment Search, Near-Real-Time Search, and the new TokenStream API

LUCENE - TERMRANGEQUERY

Information Retrieval

Applied Databases. Sebastian Maneth. Lecture 11 TFIDF Scoring, Lucene. University of Edinburgh - February 26th, 2017

LUCENE - QUICK GUIDE LUCENE - OVERVIEW

Covers Apache Lucene 3.0 IN ACTION SECOND EDITION. Michael McCandless Erik Hatcher, Otis Gospodnetic F OREWORD BY D OUG C UTTING MANNING

Project Report. Project Title: Evaluation of Standard Information retrieval system related to specific queries

Please post comments or corrections to the Author Online forum at

Searching and Analyzing Qualitative Data on Personal Computer

LUCENE - DELETE DOCUMENT OPERATION

Web Data Management. Text indexing with LUCENE (Nicolas Travers) Philippe Rigaux CNAM Paris & INRIA Saclay

Apache Lucene - Overview

LUCENE - ADD DOCUMENT OPERATION

!"#$%&'()*+,-./'*.0'12*)$%-./'34'5# '/"-028'

The Lucene Search Engine

AN EFFECTIVE SEARCH TOOL FOR LOCATING RESOURCE IN NETWORK

Project Report on winter

Search Evolution von Lucene zu Solr und ElasticSearch. Florian

Apache Lucene - Scoring

Querying a Lucene Index

LAB 7: Search engine: Apache Nutch + Solr + Lucene

A short introduction to the development and evaluation of Indexing systems

Please post comments or corrections to the Author Online forum at

LucidWorks: Searching with curl October 1, 2012

Lucene Performance Workshop Lucid Imagination, Inc.

Brainspace: Quick Reference

Realtime Search with Lucene. Michael

BEST SEARCH AND RETRIEVAL PERFORMANCE EVALUATION WITH LUCENE INDEXING

Apache Lucene 7 What s coming next?

VK Multimedia Information Systems

Advanced Indexing Techniques with Lucene

Development of Search Engines using Lucene: An Experience

Information Retrieval and Search Engine

Indexing and Searching Document Collections using Lucene

Full-Text Indexing For Heritrix

Soir 1.4 Enterprise Search Server

Open Source Search. Andreas Pesenhofer. max.recall information systems GmbH Künstlergasse 11/1 A-1150 Wien Austria

Building Search Applications

rpaf ktl Pen Apache Solr 3 Enterprise Search Server J community exp<= highlighting, relevancy ranked sorting, and more source publishing""

Chapter 2. Architecture of a Search Engine

Apache Lucene 4. Robert Muir

run your own search engine. today: Cablecar

Search Engines Exercise 5: Querying. Dustin Lange & Saeedeh Momtazi 9 June 2011

230 Million Tweets per day

Collective Intelligence in Action

XML to Lucene to SRW

Yonik Seeley 29 June 2006 Dublin, Ireland

Lucene 4 - Next generation open source search

Apache Lucene - Query Parser Syntax

Journal of Chemical and Pharmaceutical Research, 2014, 6(6): Research Article

EPL660: Information Retrieval and Search Engines Lab 3

RELATIONAL database management systems (RDBMS)

Computer Components. Software{ User Programs. Operating System. Hardware

Project: The idea CS276A Text Information Retrieval, Mining, and Exploitation

Research and implementation of search engine based on Lucene Wan Pu, Wang Lisha

Today. Book-keeping. File I/O. Subscribe to sipb-iap-java-students. Inner classes. Debugging tools

ΕΠΛ660. Ανάκτηση µε το µοντέλο διανυσµατικού χώρου

Multimedia Information Extraction and Retrieval Term Frequency Inverse Document Frequency

Termin 6: Web Suche. Übung Netzbasierte Informationssysteme. Arbeitsgruppe. Prof. Dr. Adrian Paschke

Improving Drupal search experience with Apache Solr and Elasticsearch

60-538: Information Retrieval

Javadoc. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 7

Hibernate Search: A Successful Search, a Happy User Make it Happen!

Efficiency. Efficiency: Indexing. Indexing. Efficiency Techniques. Inverted Index. Inverted Index (COSC 488)

Frequently Asked Questions

Relevancy Workbench Module. 1.0 Documentation

Information Retrieval. Shehzaad Dhuliawala Maulik Vachhani

Red Hat JBoss Data Grid 7.1 Migration Guide

Pace University. Fundamental Concepts of CS121 1

More on indexing CE-324: Modern Information Retrieval Sharif University of Technology

Logistics. CSE Case Studies. Indexing & Retrieval in Google. Review: AltaVista. BigTable. Index Stream Readers (ISRs) Advanced Search

Computer Science 572 Exam Prof. Horowitz Monday, November 27, 2017, 8:00am 9:00am

UAIC: Participation in task

Haralambos Marmanis Dmitry Babenko SAMPLE CHAPTER MANNING

Full-Text Indexing for Heritrix

elasticsearch The Road to a Distributed, (Near) Real Time, Search Engine Shay Banon

Computer Components. Software{ User Programs. Operating System. Hardware

modern database systems lecture 4 : information retrieval

Building the News Search Engine

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Goal of this document: A simple yet effective

Representation/Indexing (fig 1.2) IR models - overview (fig 2.1) IR models - vector space. Weighting TF*IDF. U s e r. T a s k s

Design and Implementation of Full Text Search Engine Based on Lucene Na-na ZHANG 1,a *, Yi-song WANG 1 and Kun ZHU 1

Searching Large XML Databases using Lucene

Information Retrieval

Indexing and Search with

Department of Computer Science and Engineering B.E/B.Tech/M.E/M.Tech : B.E. Regulation: 2013 PG Specialisation : _

Whoosh Documentation. Release Matt Chaput

Introduction to Programming Using Java (98-388)

Hibernate Search Googling your persistence domain model. Emmanuel Bernard Doer JBoss, a division of Red Hat

Transcription:

Introduction to Information Retrieval ΠΛΕ70: Ανάκτηση Πληροφορίας Διδάσκουσα: Ευαγγελία Πιτουρά Διάλεξη 11: Εισαγωγή στο Lucene. 1

Τι είναι; Open source Java library for IR (indexing and searching) Lets you add search to your application, not a complete search system by itself -- software library not an application Written by Doug Cutting Used by LinkedIn, Twitter, Netflix and many more (see http://wiki.apache.org/lucene-java/poweredby) Ports/integrations to other languages C/C++, C#, Ruby, Perl, Python, PHP, Beyond core jar, a number of extension modules contrib modules

Πηγές Lucene: http://lucene.apache.org/core/ Lucene in Action: http://www.manning.com/hatcher3/ Code samples available for download πολύ χρήσιμο JUnit: http://junit.org/ Some examples are JUnit test cases Automatically executes all methods with public void test-xxx() signature

Lucene in a search system Index document Users Analyze document Search UI Build document Acquire content Index Build query Render results Raw Content INDEX Run query SEARCH

Lucene in a search system: index Index document Analyze document Build document Acquire content Index Steps 1. Acquire content 2. Build content 3. Analyze documents 4. Index documents Raw Content INDEX

Lucene in a search system: index Acquire content (not supported by core Lucid) Depending on type Crawler or spiders (web) Specific APIs provided by the application (e.g., Twitter, FourSquare) Complex software if scattered at various location, etc Additional issues Access Control Lists Online/real-time Complex documents (e.g., XML, relational databases, etc) Solr (Tika, chapter 7)

Lucene in a search system: index Build document (not supported by core Lucid) A document is the unit of search Each document consists of separately named fields with values (title, body, etc) What constitutes a document and what are its fields? Lucene provides an API for building fields and documents Other issues (not handled) Extract text from document (if binary) Handle markups (XML, HTML) Add additional fields (semantic analysis) Boost individual files At indexing time (per document and field, section 2.5) At query time (section 5.7)

Lucene in a search system: index Analyze document (supported by core Lucid) Given a document -> extract its tokens Details in Chapter 4 Issues handle compounds case sensitivity inject synonyms spell correction collapse singular and plural stemmer (Porter s)

Lucene in a search system: index Index document (supported by core Lucid) Details in Chapter 2

Lucene in a search system: search STEPS Enter query (UI) Build query Run search query Render results (UI) Index Build query Users Search UI Render results Run query SEARCH

Lucene in a search system: search Search User Interface (UI) No default search UI, but many useful contrib modules General instructions Simple (do not present a lot of options in the first page) a single search box better than 2-step process Result presentation is important highlight matches (highlighter contrib modules, section 8.3&8.4) make sort order clear, etc Be transparent: e.g., explain if you expand search for synonyms, autocorrect errors (spellchecker contrib module, section 8.5, etc)

Lucene in a search system: search Build query (supported by core Lucid) Provides a package QueryParser: process the user text input into a Query object (Chapter 3) Query may contain Boolean operators, phrase queries, wildcard terms

Lucene in a search system: search Search query (supported by core Lucid) See Chapter 6 Three models Pure Boolean model (no sort) Vector space model Probabilistic model Lucene combines Boolean and vector model select which one on a search-by-search basis Customize

Lucene in a search system: search Render results (supported by core Lucid) UI issues

Lucene in action Get code from the book Command line Indexer /lia2e/src/lia/meetlucene/indexer.java Command line Searcher /lia2e3/src/lia/meetlucene/searcher.java

How Lucene models content A Document is the atomic unit of indexing and searching A Document contains Fields Fields have a name and a value Examples: Title, author, date, abstract, body, URL, keywords,.. Different documents can have different fields You have to translate raw content into Fields Search a field using name:term, e.g., title:lucene

Documents and Fields Parametric or zone indexing There is one (parametric) index for each field Also, supports weighted field scoring

Basic Application Document super_name: Spider-Man name: Peter Parker category: superhero powers: agility, spider-sense Query (powers:agility) Hits (Matching Docs) adddocument() search() 1. Get Lucene jar file IndexWriter IndexSearcher 2. Write indexing code to get data and create Document objects Lucene Index 3. Write code to create query objects 4. Write code to use/display results

Core indexing classes IndexWriter Central component that allows you to create a new index, open an existing one, and add, remove, or update documents in an index Directory Abstract class that represents the location of an index Analyzer Extracts tokens from a text stream

Creating an IndexWriter import org.apache.lucene.index.indexwriter; import org.apache.lucene.store.directory; import org.apache.lucene.analysis.standard.standardanalyzer;... private IndexWriter writer;... public Indexer(String indexdir) throws IOException { } Directory dir = FSDirectory.open(new File(indexDir)); writer = new IndexWriter( dir, new StandardAnalyzer(Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED);

Core indexing classes Document Represents a collection of named Fields. Text in these Fields are indexed. Field Note: Lucene Fields can represent both fields and zones as described in the textbook

A Document contains Fields import org.apache.lucene.document.document; import org.apache.lucene.document.field;... protected Document getdocument(file f) throws Exception { Document doc = new Document(); doc.add(new Field("contents, new FileReader(f))) doc.add(new Field("filename, f.getname(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field("fullpath, f.getcanonicalpath(), Field.Store.YES, Field.Index.NOT_ANALYZED)); return doc; }

Index a Document with IndexWriter private IndexWriter writer;... private void indexfile(file f) throws Exception { Document doc = getdocument(f); writer.adddocument(doc); }

Indexing a directory private IndexWriter writer;... public int index(string datadir, FileFilter filter) throws Exception { File[] files = new File(dataDir).listFiles(); for (File f: files) { if (... && (filter == null filter.accept(f))) { indexfile(f); } } return writer.numdocs(); }

Closing the IndexWriter private IndexWriter writer;... public void close() throws IOException { writer.close(); }

Fields Fields may Be indexed or not Indexed fields may or may not be analyzed (i.e., tokenized with an Analyzer) Non-analyzed fields view the entire value as a single token (useful for URLs, paths, dates, social security numbers,...) Be stored or not Useful for fields that you d like to display to users Optionally store term vectors Like a positional index on the Field s terms Useful for highlighting, finding similar documents, categorization

Field construction Lots of different constructors import org.apache.lucene.document.field Field(String name, String value, Field.Store store, // store or not Field.Index index, // index or not Field.TermVector termvector); value can also be specified with a Reader, a TokenStream, or a byte[]

Field options Field.Store NO : Don t store the field value in the index YES : Store the field value in the index Field.Index ANALYZED : Tokenize with an Analyzer NOT_ANALYZED : Do not tokenize NO : Do not index this field Couple of other advanced options Field.TermVector NO : Don t store term vectors YES : Store term vectors Several other options to store positions and offsets

Field vector options TermVector.Yes TermVector.With_POSITIONS TermVector.With_OFFSETS TermVector.WITH_POSITIONS_OFFSETS TermVector.No

Using Field options Index Store TermVector Example usage NOT_ANALYZED YES NO Identifiers, telephone/ssns, URLs, dates,... ANALYZED YES WITH_POSITIONS_OFFSETS Title, abstract ANALYZED NO WITH_POSITIONS_OFFSETS Body NO YES NO Document type, DB keys (if not used for searching) NOT_ANALYZED NO NO Hidden keywords

Document import org.apache.lucene.document.field Constructor: Document(); Methods void add(fieldable field); // Field implements // Fieldable String get(string name); // Returns value of // Field with given // name Fieldable getfieldable(string name);... and many more

Multi-valued fields You can add multiple Fields with the same name Lucene simply concatenates the different values for that named Field Document doc = new Document(); doc.add(new Field( author, chris manning, Field.Store.YES, Field.Index.ANALYZED)); doc.add(new Field( author, prabhakar raghavan, Field.Store.YES, Field.Index.ANALYZED));...

Analyzers Tokenizes the input text Common Analyzers WhitespaceAnalyzer Splits tokens on whitespace SimpleAnalyzer Splits tokens on non-letters, and then lowercases StopAnalyzer Same as SimpleAnalyzer, but also removes stop words StandardAnalyzer Most sophisticated analyzer that knows about certain token types, lowercases, removes stop words,...

Analysis examples The quick brown fox jumped over the lazy dog WhitespaceAnalyzer [The] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dog] SimpleAnalyzer [the] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dog] StopAnalyzer [quick] [brown] [fox] [jumped] [over] [lazy] [dog] StandardAnalyzer [quick] [brown] [fox] [jumped] [over] [lazy] [dog]

More analysis examples XY&Z Corporation xyz@example.com WhitespaceAnalyzer [XY&Z] [Corporation] [-] [xyz@example.com] SimpleAnalyzer [xy] [z] [corporation] [xyz] [example] [com] StopAnalyzer [xy] [z] [corporation] [xyz] [example] [com] StandardAnalyzer [xy&z] [corporation] [xyz@example.com]

What s inside an Analyzer? Analyzers need to return a TokenStream public TokenStream tokenstream(string fieldname, Reader reader) TokenStream Tokenizer TokenFilter Reader Tokenizer TokenFilter TokenFilter

Tokenizers and TokenFilters Tokenizer WhitespaceTokenizer KeywordTokenizer LetterTokenizer StandardTokenizer... TokenFilter LowerCaseFilter StopFilter PorterStemFilter ASCIIFoldingFilter StandardFilter...

Adding/deleting Documents to/from an IndexWriter void adddocument(document d); void adddocument(document d, Analyzer a); Important: Need to ensure that Analyzers used at indexing time are consistent with Analyzers used at searching time // deletes docs containing term or matching // query. The term version is useful for // deleting one document. void deletedocuments(term term); void deletedocuments(query query);

Index format Each Lucene index consists of one or more segments A segment is a standalone index for a subset of documents All segments are searched A segment is created whenever IndexWriter flushes adds/deletes Periodically, IndexWriter will merge a set of segments into a single segment Policy specified by a MergePolicy You can explicitly invoke optimize() to merge segments

Basic merge policy Segments are grouped into levels Segments within a group are roughly equal size (in log space) Once a level has enough segments, they are merged into a segment at the next level up

Core searching classes

Core searching classes IndexSearcher Central class that exposes several search methods on an index (a class that opens the index) requires a Directory instance that holds the previously created index Term Basic unit of searching, contains a pair of string elements (field and word) Query Abstract query class. Concrete subclasses represent specific types of queries, e.g., matching terms in fields, boolean queries, phrase queries,, most basic TermQuery QueryParser Parses a textual representation of a query into a Query instance

Creating an IndexSearcher import org.apache.lucene.search.indexsearcher;... public static void search(string indexdir, String q) throws IOException, ParseException { Directory dir = FSDirectory.open( new File(indexDir)); IndexSearcher is = new IndexSearcher(dir);... }

Query and QueryParser import org.apache.lucene.search.query; import org.apache.lucene.queryparser.queryparser;... public static void search(string indexdir, String q) throws IOException, ParseException... QueryParser parser = new QueryParser(Version.LUCENE_30, "contents, new StandardAnalyzer( Version.LUCENE_30)); Query query = parser.parse(q);... }

Core searching classes (contd.) TopDocs Contains references to the top N documents returned by a search (the docid and its score) ScoreDoc Provides access to a single search result

search() returns TopDocs import org.apache.lucene.search.topdocs;... public static void search(string indexdir, String q) throws IOException, ParseException... IndexSearcher is =...;... Query query =...;... TopDocs hits = is.search(query, 10); }

TopDocs contain ScoreDocs import org.apache.lucene.search.scoredoc;... public static void search(string indexdir, String q) throws IOException, ParseException... IndexSearcher is =...;... TopDocs hits =...;... for(scoredoc scoredoc : hits.scoredocs) { Document doc = is.doc(scoredoc.doc); System.out.println(doc.get("fullpath")); } }

Closing IndexSearcher public static void search(string indexdir, String q) throws IOException, ParseException... IndexSearcher is =...;... is.close(); }

IndexSearcher Constructor: IndexSearcher(Directory d); deprecated

IndexReader Query IndexSearcher TopDocs IndexReader Directory

IndexSearcher Constructor: IndexSearcher(Directory d); deprecated IndexSearcher(IndexReader r); Construct an IndexReader with static method IndexReader.open(dir)

Searching a changing index Directory dir = FSDirectory.open(...); IndexReader reader = IndexReader.open(dir); IndexSearcher searcher = new IndexSearcher(reader); Above reader does not reflect changes to the index unless you reopen it. Reopening is more resource efficient than opening a new IndexReader. IndexReader newreader = reader.reopen(); If (reader!= newreader) { reader.close(); reader = newreader; searcher = new IndexSearcher(reader); }

Near-real-time search IndexWriter writer =...; IndexReader reader = writer.getreader(); IndexSearcher searcher = new IndexSearcher(reader); Now let us say there s a change to the index using writer // reopen() and getreader() force writer to flush IndexReader newreader = reader.reopen(); if (reader!= newreader) { reader.close(); reader = newreader; searcher = new IndexSearcher(reader); }

IndexSearcher Methods TopDocs search(query q, int n); Document doc(int docid);

QueryParser Constructor QueryParser(Version matchversion, String defaultfield, Analyzer analyzer); Parsing methods Query parse(string query) throws ParseException;... and many more

QueryParser syntax examples Query expression java java junit java OR junit +java +junit java AND junit title:ant title:extreme subject:sports (agile OR extreme) AND java title: junit in action title: junit action ~5 java* java~ lastmodified:[1/1/09 TO 12/31/09] Document matches if Contains the term java in the default field Contains the term java or junit or both in the default field (the default operator can be changed to AND) Contains both java and junit in the default field Contains the term ant in the title field Contains extreme in the title and not sports in subject Boolean expression matches Phrase matches in title Proximity matches (within 5) in title Wildcard matches Fuzzy matches Range matches

Construct Querys programmatically TermQuery Constructed from a Term TermRangeQuery NumericRangeQuery PrefixQuery BooleanQuery PhraseQuery WildcardQuery FuzzyQuery MatchAllDocsQuery

TopDocs and ScoreDoc TopDocs methods Number of documents that matched the search totalhits Array of ScoreDoc instances containing results scoredocs Returns best score of all matches getmaxscore() ScoreDoc methods Document id doc Document score score

Scoring Scoring function uses basic tf-idf scoring with Programmable boost values for certain fields in documents Length normalization Boosts for documents containing more of the query terms IndexSearcher provides an explain() method that explains the scoring of a document

Based on Lucene in Action By Michael McCandless, Erik Hatcher, Otis Gospodnetic

ΤΕΛΟΣ 11 ου Μαθήματος Ερωτήσεις? Υλικό των: Pandu Nayak and Prabhakar Raghavan, CS276:Information Retrieval and Web Search (Stanford) 61