/// <summary> /// Adds a standard type clause to this instance /// </summary> /// <param name="term">Term to add to this query.</param> /// <param name="occurrence">Defines how the term is added to this query.</param> /// <param name="slop">The amount of allowed slop in a phrase query.</param> /// <remarks> /// Slop is the amount of movement each word is allowed in a non-exact phrase query. /// For instance if you search for "Adobe Systems Incorporated" and the slop is set to 0 then /// only results with that term is allowed. If you set the slop to 2 then two movements can be /// made, max, for each word. In the same example with slop set to 2 results would be returned /// for "Adobe Systems Incorporated", "Adobe Incorporated Systems", "Systems Adobe Incorporated", /// and "Systems Incorporated Adobe". /// </remarks> public void AddBooleanClause(SearchTerm term, ClauseOccurrence occurrence, int slop) { if (term == null) { throw new ArgumentNullException("term", "term cannot be null"); } IncrementTotalClauses(1); if (term.IsPhrase) { PhraseQuery phraseQuery = new PhraseQuery(); phraseQuery.Add(term.GetLuceneTerm()); phraseQuery.SetSlop(slop); phraseQuery.SetBoost(term.Boost); this.luceneQuery.Add(phraseQuery, TypeConverter.ConvertToLuceneClauseOccurrence(occurrence)); phraseQuery = null; } else { TermQuery termQuery = new TermQuery(term.GetLuceneTerm()); termQuery.SetBoost(term.Boost); this.luceneQuery.Add(termQuery, TypeConverter.ConvertToLuceneClauseOccurrence(occurrence)); termQuery = null; } }
/// <summary> /// [experimental] Returns the number of documents containing the indexTerm /// </summary> /// <param name="indexTerm">The index term.</param> /// <returns></returns> public int DocumentFrequency(SearchTerm indexTerm) { if (this.isDisposed) { throw new ObjectDisposedException("IndexReader", "You cannot call DocumentFrequency(FieldAbstract) from a disposed IndexReader"); } if (indexTerm == null) { throw new ArgumentNullException("indexTerm", "indexTerm cannot be null"); } return(this.luceneReader.DocFreq(indexTerm.GetLuceneTerm())); }
/// <summary> /// Adds a wildcard clause to this instance /// </summary> /// <remarks>Wildcard clauses include '*' and '?' character</remarks> /// <param name="term">Term to add to this query</param> /// <param name="occurrence">Defines how the term is added to this query</param> public void AddWildcardClause(SearchTerm term, ClauseOccurrence occurrence) { if (term == null) { throw new ArgumentNullException("term", "term cannot be null"); } IncrementTotalClauses(1); WildcardQuery wildcardQuery = new WildcardQuery(term.GetLuceneTerm()); wildcardQuery.SetBoost(term.Boost); this.luceneQuery.Add(wildcardQuery, TypeConverter.ConvertToLuceneClauseOccurrence(occurrence)); wildcardQuery = null; }
/// <summary> /// Adds a fuzzy clause to this instance /// </summary> /// <remarks>Fuzzy clauses find results within a particular relevance distance of each hit</remarks> /// <param name="term">Term to add to this query</param> /// <param name="occurrence">Defines how the term is added to this query</param> /// <param name="minimumSimilarity">Defines the amount of similarity that is allowed between matches</param> public void AddFuzzyClause(SearchTerm term, ClauseOccurrence occurrence, float minimumSimilarity) { if (term == null) { throw new ArgumentNullException("term", "term cannot be null"); } IncrementTotalClauses(1); FuzzyQuery fuzzyQuery = new FuzzyQuery(term.GetLuceneTerm(), minimumSimilarity); fuzzyQuery.SetBoost(term.Boost); this.luceneQuery.Add(fuzzyQuery, TypeConverter.ConvertToLuceneClauseOccurrence(occurrence)); fuzzyQuery = null; }
/// <summary> /// [experimental] Deletes all documents that have a given term indexed. /// </summary> /// <param name="indexTerm">The index term to match against existing documents.</param> /// <returns>The number of documents deleted</returns> /// <remarks> /// This is useful if one uses a document field to hold a unique ID string for the document. Then to delete such a document, one merely constructs a term with the /// appropriate field and the unique ID string as it's text and passes it to this method. /// </remarks> public int DeleteDocuments(SearchTerm indexTerm) { if (this.isDisposed) { throw new ObjectDisposedException("IndexReader", "You cannot call DeleteDocuments(FieldAbstract) from a disposed IndexReader"); } if (this.isReadOnly) { throw new InvalidOperationException("You cannot delete documents from an index that is opened in readonly mode"); } if (indexTerm == null) { throw new ArgumentNullException("indexTerm", "indexTerm cannot be null"); } return(this.luceneReader.DeleteDocuments(indexTerm.GetLuceneTerm())); }
/// <summary> /// Adds a wildcard clause to this instance /// </summary> /// <remarks>Wildcard clauses include '*' and '?' character</remarks> /// <param name="term">Term to add to this query</param> /// <param name="occurrence">Defines how the term is added to this query</param> public void AddWildcardClause(SearchTerm term, ClauseOccurrence occurrence) { if (term == null) throw new ArgumentNullException("term", "term cannot be null"); IncrementTotalClauses(1); WildcardQuery wildcardQuery = new WildcardQuery(term.GetLuceneTerm()); wildcardQuery.SetBoost(term.Boost); this.luceneQuery.Add(wildcardQuery, TypeConverter.ConvertToLuceneClauseOccurrence(occurrence)); wildcardQuery = null; }
/// <summary> /// Adds a fuzzy clause to this instance /// </summary> /// <remarks>Fuzzy clauses find results within a particular relevance distance of each hit</remarks> /// <param name="term">Term to add to this query</param> /// <param name="occurrence">Defines how the term is added to this query</param> /// <param name="minimumSimilarity">Defines the amount of similarity that is allowed between matches</param> public void AddFuzzyClause(SearchTerm term, ClauseOccurrence occurrence, float minimumSimilarity) { if (term == null) throw new ArgumentNullException("term", "term cannot be null"); IncrementTotalClauses(1); FuzzyQuery fuzzyQuery = new FuzzyQuery(term.GetLuceneTerm(), minimumSimilarity); fuzzyQuery.SetBoost(term.Boost); this.luceneQuery.Add(fuzzyQuery, TypeConverter.ConvertToLuceneClauseOccurrence(occurrence)); fuzzyQuery = null; }
/// <summary> /// Adds a standard type clause to this instance /// </summary> /// <param name="term">Term to add to this query.</param> /// <param name="occurrence">Defines how the term is added to this query.</param> /// <param name="slop">The amount of allowed slop in a phrase query.</param> /// <remarks> /// Slop is the amount of movement each word is allowed in a non-exact phrase query. /// For instance if you search for "Adobe Systems Incorporated" and the slop is set to 0 then /// only results with that term is allowed. If you set the slop to 2 then two movements can be /// made, max, for each word. In the same example with slop set to 2 results would be returned /// for "Adobe Systems Incorporated", "Adobe Incorporated Systems", "Systems Adobe Incorporated", /// and "Systems Incorporated Adobe". /// </remarks> public void AddBooleanClause(SearchTerm term, ClauseOccurrence occurrence, int slop) { if (term == null) throw new ArgumentNullException("term", "term cannot be null"); IncrementTotalClauses(1); if (term.IsPhrase) { PhraseQuery phraseQuery = new PhraseQuery(); phraseQuery.Add(term.GetLuceneTerm()); phraseQuery.SetSlop(slop); phraseQuery.SetBoost(term.Boost); this.luceneQuery.Add(phraseQuery, TypeConverter.ConvertToLuceneClauseOccurrence(occurrence)); phraseQuery = null; } else { TermQuery termQuery = new TermQuery(term.GetLuceneTerm()); termQuery.SetBoost(term.Boost); this.luceneQuery.Add(termQuery, TypeConverter.ConvertToLuceneClauseOccurrence(occurrence)); termQuery = null; } }
/// <summary> /// [experimental] Returns the number of documents containing the indexTerm /// </summary> /// <param name="indexTerm">The index term.</param> /// <returns></returns> public int DocumentFrequency(SearchTerm indexTerm) { if (this.isDisposed) throw new ObjectDisposedException("IndexReader", "You cannot call DocumentFrequency(FieldAbstract) from a disposed IndexReader"); if (indexTerm == null) throw new ArgumentNullException("indexTerm", "indexTerm cannot be null"); return this.luceneReader.DocFreq(indexTerm.GetLuceneTerm()); }
/// <summary> /// [experimental] Deletes all documents that have a given term indexed. /// </summary> /// <param name="indexTerm">The index term to match against existing documents.</param> /// <returns>The number of documents deleted</returns> /// <remarks> /// This is useful if one uses a document field to hold a unique ID string for the document. Then to delete such a document, one merely constructs a term with the /// appropriate field and the unique ID string as it's text and passes it to this method. /// </remarks> public int DeleteDocuments(SearchTerm indexTerm) { if (this.isDisposed) throw new ObjectDisposedException("IndexReader", "You cannot call DeleteDocuments(FieldAbstract) from a disposed IndexReader"); if (this.isReadOnly) throw new InvalidOperationException("You cannot delete documents from an index that is opened in readonly mode"); if (indexTerm == null) throw new ArgumentNullException("indexTerm", "indexTerm cannot be null"); return this.luceneReader.DeleteDocuments(indexTerm.GetLuceneTerm()); }