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. ATextIndex
is not constructed directly; the index data is generated as a separate step and stored in a file, and theTextIndex
instance is created from that file.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TextIndex.And
A query that matches only documents that match both of two child queries.static class
TextIndex.Atom
An atom is a query that matches all documents that contain a specified one-word search term.static class
TextIndex.Not
A query that matches every document except the documents matched by its child query.static class
TextIndex.Or
A query that matches any documents that match either of two child queries.static class
TextIndex.Query
AQuery
represents a query expression to be matched against a text index.static class
TextIndex.QueryParser
A parser that converts a plain text query string into a query.static interface
TextIndex.Result
AResult
captures 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 TextIndex
read(java.io.File file)
Creates a text index from the specified file.static TextIndex
read(java.io.InputStream in)
Creates a text index from a stream.static TextIndex
read(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:
iterator
in interfacejava.lang.Iterable<java.lang.String>
- Returns:
- word iterator
-
-