Package ca.cgjennings.algo
Class TextIndex
- java.lang.Object
-
- ca.cgjennings.algo.TextIndex
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.String>
public class TextIndex extends java.lang.Object implements java.lang.Iterable<java.lang.String>A searchable reverse index of the words contained in a set of documents. Each document is represented by a string (such as a URL) that identifies it. Given a query, the index returns the set of IDs whose documents match the query. ATextIndexis not constructed directly; the index data is generated as a separate step and stored in a file, and theTextIndexinstance is created from that file.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTextIndex.AndA query that matches only documents that match both of two child queries.static classTextIndex.AtomAn atom is a query that matches all documents that contain a specified one-word search term.static classTextIndex.NotA query that matches every document except the documents matched by its child query.static classTextIndex.OrA query that matches any documents that match either of two child queries.static classTextIndex.QueryAQueryrepresents a query expression to be matched against a text index.static classTextIndex.QueryParserA parser that converts a plain text query string into a query.static interfaceTextIndex.ResultAResultcaptures the result of a query.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<java.lang.String>iterator()An iterator over the index words.static TextIndexread(java.io.File file)Creates a text index from the specified file.static TextIndexread(java.io.InputStream in)Creates a text index from a stream.static TextIndexread(java.net.URL url)Creates a text index from the file at the specified URL.
-
-
-
Method Detail
-
read
public static TextIndex read(java.io.File file) throws java.io.IOException
Creates a text index from the specified file.- Parameters:
file- the previously written text index- Returns:
- an index generated from the stored index data
- Throws:
java.io.IOException- if an I/O error occurs while reading the index
-
read
public static TextIndex read(java.net.URL url) throws java.io.IOException
Creates a text index from the file at the specified URL.- Parameters:
url- the location of the previously written text index- Returns:
- an index generated from the stored index data
- Throws:
java.io.IOException- if an I/O error occurs while reading the index
-
read
public static TextIndex read(java.io.InputStream in) throws java.io.IOException
Creates a text index from a stream.- Parameters:
in- a stream containing the previously written text index- Returns:
- an index generated from the stored index data
- Throws:
java.io.IOException- if an I/O error occurs while reading the index
-
iterator
public java.util.Iterator<java.lang.String> iterator()
An iterator over the index words.- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.String>- Returns:
- word iterator
-
-