/// <summary> </summary> /// <param name="directory">The directory to write the document information to /// </param> /// <param name="analyzer">The analyzer to use for the document /// </param> /// <param name="similarity">The Similarity function /// </param> /// <param name="maxFieldLength">The maximum number of tokens a Field may have /// </param> public /*internal*/ DocumentWriter(Directory directory, Analyzer analyzer, Similarity similarity, int maxFieldLength) { this.directory = directory; this.analyzer = analyzer; this.similarity = similarity; this.maxFieldLength = maxFieldLength; }
/// <summary> <p> /// Parses a query which searches on the fields specified. /// <p> /// If x fields are specified, this effectively constructs: /// <pre> /// <code> /// (field1:query) (field2:query) (field3:query)...(fieldx:query) /// </code> /// </pre> /// /// </summary> /// <param name="query">Query string to parse /// </param> /// <param name="fields">Fields to search on /// </param> /// <param name="analyzer">Analyzer to use /// </param> /// <throws> ParseException if query parsing fails </throws> /// <throws> TokenMgrError if query parsing fails </throws> public static Query Parse(System.String query, System.String[] fields, Analyzer analyzer) { BooleanQuery bQuery = new BooleanQuery(); for (int i = 0; i < fields.Length; i++) { Query q = Parse(query, fields[i], analyzer); bQuery.Add(q, false, false); } return bQuery; }
/// <summary> <p> /// Parses a query which searches on the fields specified. /// <p> /// If x fields are specified, this effectively constructs: /// <pre> /// <code> /// (field1:query) (field2:query) (field3:query)...(fieldx:query) /// </code> /// </pre> /// /// </summary> /// <param name="query">Query string to parse /// </param> /// <param name="fields">Fields to search on /// </param> /// <param name="analyzer">Analyzer to use /// </param> /// <throws> ParseException if query parsing fails </throws> /// <throws> TokenMgrError if query parsing fails </throws> public static Query Parse(System.String query, System.String[] fields, Analyzer analyzer) { BooleanQuery bQuery = new BooleanQuery(); for (int i = 0; i < fields.Length; i++) { Query q = Parse(query, fields[i], analyzer); bQuery.Add(q, false, false); } return(bQuery); }
/// <summary> Adds a document to this index, using the provided analyzer instead of the /// value of {@link #GetAnalyzer()}. If the document contains more than /// {@link #maxFieldLength} terms for a given Field, the remainder are /// discarded. /// </summary> public virtual void AddDocument(Document doc, Analyzer analyzer) { DocumentWriter dw = new DocumentWriter(ramDirectory, analyzer, similarity, maxFieldLength); System.String segmentName = NewSegmentName(); dw.AddDocument(segmentName, doc); lock (this) { segmentInfos.Add(new SegmentInfo(segmentName, 1, ramDirectory)); MaybeMergeSegments(); } }
private IndexWriter(Directory d, Analyzer a, bool create, bool closeDir) { InitBlock(); this.closeDir = closeDir; directory = d; analyzer = a; Lock writeLock = directory.MakeLock(IndexWriter.WRITE_LOCK_NAME); if (!writeLock.Obtain(WRITE_LOCK_TIMEOUT)) // obtain write lock { throw new System.IO.IOException("Index locked for write: " + writeLock); } this.writeLock = writeLock; // save it lock (directory) { // in- & inter-process sync new AnonymousClassWith(create, this, directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT).Run(); } }
public QueryTermVector(System.String queryString, Analyzer analyzer) { if (analyzer != null) { TokenStream stream = analyzer.TokenStream("", new System.IO.StringReader(queryString)); if (stream != null) { Token next = null; System.Collections.ArrayList terms = new System.Collections.ArrayList(); try { while ((next = stream.Next()) != null) { terms.Add(next.TermText()); } ProcessTerms((System.String[])terms.ToArray(typeof(System.String))); } catch (System.IO.IOException) { } } } }
public QueryTermVector(System.String queryString, Analyzer analyzer) { if (analyzer != null) { TokenStream stream = analyzer.TokenStream("", new System.IO.StringReader(queryString)); if (stream != null) { Token next = null; System.Collections.ArrayList terms = new System.Collections.ArrayList(); try { while ((next = stream.Next()) != null) { terms.Add(next.TermText()); } ProcessTerms((System.String[]) terms.ToArray(typeof(System.String))); } catch (System.IO.IOException) { } } } }
/// <summary> Constructs an IndexWriter for the index in <code>d</code>. /// Text will be analyzed with <code>a</code>. If <code>create</code> /// is true, then a new, empty index will be created in /// <code>d</code>, replacing the index already there, if any. /// /// </summary> /// <param name="d">the index directory /// </param> /// <param name="a">the analyzer to use /// </param> /// <param name="create"><code>true</code> to create the index or overwrite /// the existing one; <code>false</code> to append to the existing /// index /// </param> /// <throws> IOException if the directory cannot be read/written to, or </throws> /// <summary> if it does not exist, and <code>create</code> is /// <code>false</code> /// </summary> public IndexWriter(Directory d, Analyzer a, bool create) : this(d, a, create, false) { }
/// <summary> Constructs an IndexWriter for the index in <code>path</code>. /// Text will be analyzed with <code>a</code>. If <code>create</code> /// is true, then a new, empty index will be created in /// <code>path</code>, replacing the index already there, if any. /// /// </summary> /// <param name="path">the path to the index directory /// </param> /// <param name="a">the analyzer to use /// </param> /// <param name="create"><code>true</code> to create the index or overwrite /// the existing one; <code>false</code> to append to the existing /// index /// </param> /// <throws> IOException if the directory cannot be read/written to, or </throws> /// <summary> if it does not exist, and <code>create</code> is /// <code>false</code> /// </summary> public IndexWriter(System.IO.FileInfo path, Analyzer a, bool create) : this(FSDirectory.GetDirectory(path, create), a, create, true) { }
public MultiFieldQueryParser(System.String f, Analyzer a):base(f, a) { }
/// <summary> Constructs an IndexWriter for the index in <code>d</code>. /// Text will be analyzed with <code>a</code>. If <code>create</code> /// is true, then a new, empty index will be created in /// <code>d</code>, replacing the index already there, if any. /// /// </summary> /// <param name="d">the index directory /// </param> /// <param name="a">the analyzer to use /// </param> /// <param name="create"><code>true</code> to create the index or overwrite /// the existing one; <code>false</code> to append to the existing /// index /// </param> /// <throws> IOException if the directory cannot be read/written to, or </throws> /// <summary> if it does not exist, and <code>create</code> is /// <code>false</code> /// </summary> public IndexWriter(Directory d, Analyzer a, bool create):this(d, a, create, false) { }
public MultiFieldQueryParser(System.String f, Analyzer a) : base(f, a) { }
/// <summary> <p> /// Parses a query, searching on the fields specified. /// Use this if you need to specify certain fields as required, /// and others as prohibited. /// <p><pre> /// Usage: /// <code> /// String[] fields = {"filename", "contents", "description"}; /// int[] flags = {MultiFieldQueryParser.NORMAL FIELD, /// MultiFieldQueryParser.REQUIRED FIELD, /// MultiFieldQueryParser.PROHIBITED FIELD,}; /// parse(query, fields, flags, analyzer); /// </code> /// </pre> /// <p> /// The code above would construct a query: /// <pre> /// <code> /// (filename:query) +(contents:query) -(description:query) /// </code> /// </pre> /// /// </summary> /// <param name="query">Query string to parse /// </param> /// <param name="fields">Fields to search on /// </param> /// <param name="flags">Flags describing the fields /// </param> /// <param name="analyzer">Analyzer to use /// </param> /// <throws> ParseException if query parsing fails </throws> /// <throws> TokenMgrError if query parsing fails </throws> public static Query Parse(System.String query, System.String[] fields, int[] flags, Analyzer analyzer) { BooleanQuery bQuery = new BooleanQuery(); for (int i = 0; i < fields.Length; i++) { Query q = Parse(query, fields[i], analyzer); int flag = flags[i]; switch (flag) { case REQUIRED_FIELD: bQuery.Add(q, true, false); break; case PROHIBITED_FIELD: bQuery.Add(q, false, true); break; default: bQuery.Add(q, false, false); break; } } return(bQuery); }
/// <summary> <p> /// Parses a query, searching on the fields specified. /// Use this if you need to specify certain fields as required, /// and others as prohibited. /// <p><pre> /// Usage: /// <code> /// String[] fields = {"filename", "contents", "description"}; /// int[] flags = {MultiFieldQueryParser.NORMAL FIELD, /// MultiFieldQueryParser.REQUIRED FIELD, /// MultiFieldQueryParser.PROHIBITED FIELD,}; /// parse(query, fields, flags, analyzer); /// </code> /// </pre> /// <p> /// The code above would construct a query: /// <pre> /// <code> /// (filename:query) +(contents:query) -(description:query) /// </code> /// </pre> /// /// </summary> /// <param name="query">Query string to parse /// </param> /// <param name="fields">Fields to search on /// </param> /// <param name="flags">Flags describing the fields /// </param> /// <param name="analyzer">Analyzer to use /// </param> /// <throws> ParseException if query parsing fails </throws> /// <throws> TokenMgrError if query parsing fails </throws> public static Query Parse(System.String query, System.String[] fields, int[] flags, Analyzer analyzer) { BooleanQuery bQuery = new BooleanQuery(); for (int i = 0; i < fields.Length; i++) { Query q = Parse(query, fields[i], analyzer); int flag = flags[i]; switch (flag) { case REQUIRED_FIELD: bQuery.Add(q, true, false); break; case PROHIBITED_FIELD: bQuery.Add(q, false, true); break; default: bQuery.Add(q, false, false); break; } } return bQuery; }
/// <summary> Constructs an IndexWriter for the index in <code>path</code>. /// Text will be analyzed with <code>a</code>. If <code>create</code> /// is true, then a new, empty index will be created in /// <code>path</code>, replacing the index already there, if any. /// /// </summary> /// <param name="path">the path to the index directory /// </param> /// <param name="a">the analyzer to use /// </param> /// <param name="create"><code>true</code> to create the index or overwrite /// the existing one; <code>false</code> to append to the existing /// index /// </param> /// <throws> IOException if the directory cannot be read/written to, or </throws> /// <summary> if it does not exist, and <code>create</code> is /// <code>false</code> /// </summary> public IndexWriter(System.IO.FileInfo path, Analyzer a, bool create):this(FSDirectory.GetDirectory(path, create), a, create, true) { }