Ejemplo n.º 1
0
 /// <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()));
 }
Ejemplo n.º 2
0
        /// <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;
        }
Ejemplo n.º 3
0
        /// <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;
        }
Ejemplo n.º 4
0
 /// <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()));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds a range clause to this instance
        /// </summary>
        /// <remarks>Adds a range to search into the query</remarks>
        /// <remarks>All values specified in the startTerm are applied to this entire clause</remarks>
        /// <param name="startTerm">Starting half of the range to add to this query</param>
        /// <param name="endValue">Ending half of the range to add to this query</param>
        /// <param name="occurrence">Defines how the term is added to this query</param>
        /// <param name="includeStartValue">Determines if the starting term is included or excluded in the search results</param>
        /// <param name="includeEndValue">Determines if the ending term is included or excluded in the search results</param>
        public void AddTermRangeClause(SearchTerm startTerm, string endValue, ClauseOccurrence occurrence, bool includeStartValue, bool includeEndValue)
        {
            if (startTerm == null)
            {
                throw new ArgumentNullException("startTerm", "startTerm cannot be null");
            }
            if (string.IsNullOrEmpty(endValue))
            {
                throw new ArgumentNullException("endValue", "endValue cannot be null or empty");
            }
            IncrementTotalClauses(1);
            TermRangeQuery rangeQuery = new TermRangeQuery(startTerm.FieldName, startTerm.FieldValue, endValue, includeStartValue, includeEndValue);

            rangeQuery.SetBoost(startTerm.Boost);
            this.luceneQuery.Add(rangeQuery, TypeConverter.ConvertToLuceneClauseOccurrence(occurrence));
            rangeQuery = null;
        }
Ejemplo n.º 6
0
 /// <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;
 }
Ejemplo n.º 7
0
 /// <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>
 public void AddFuzzyClause(SearchTerm term, ClauseOccurrence occurrence)
 {
     this.AddFuzzyClause(term, occurrence, FuzzyQuery.defaultMinSimilarity);
 }
Ejemplo n.º 8
0
        /// <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;
            }
        }
Ejemplo n.º 9
0
 /// <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>
 public void AddBooleanClause(SearchTerm term, ClauseOccurrence occurrence)
 {
     this.AddBooleanClause(term, occurrence, StaticValues.DefaultSlop);
 }
Ejemplo n.º 10
0
 /// <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>
 public void AddBooleanClause(SearchTerm term, ClauseOccurrence occurrence)
 {
     this.AddBooleanClause(term, occurrence, StaticValues.DefaultSlop);
 }
Ejemplo n.º 11
0
 /// <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>
 public void AddWildcardClause(SearchTerm term)
 {
     this.AddWildcardClause(term, ClauseOccurrence.Default);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Removes the specified field from this document.
 /// </summary>
 /// <param name="field">The field to remove.</param>
 public void RemoveField(SearchTerm field)
 {
     if (field == null)
         throw new ArgumentNullException("field", "field cannot be null");
     this.luceneDoc.RemoveField(field.FieldName);
 }
Ejemplo n.º 13
0
 /// <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>
 public void AddWildcardClause(SearchTerm term)
 {
     this.AddWildcardClause(term, ClauseOccurrence.Default);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Adds a range clause to this instance
 /// </summary>
 /// <remarks>Adds a range to search into the query</remarks>
 /// <remarks>All values specified in the startTerm are applied to this entire clause</remarks>
 /// <param name="startTerm">Starting half of the range to add to this query</param>
 /// <param name="endValue">Ending half of the range to add to this query</param>
 /// <param name="occurrence">Defines how the term is added to this query</param>
 public void AddTermRangeClause(SearchTerm startTerm, string endValue, ClauseOccurrence occurrence)
 {
     this.AddTermRangeClause(startTerm, endValue, occurrence, true, true);
 }
Ejemplo n.º 15
0
 /// <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>
 public void AddFuzzyClause(SearchTerm term, ClauseOccurrence occurrence)
 {
     this.AddFuzzyClause(term, occurrence, FuzzyQuery.defaultMinSimilarity);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Adds a range clause to this instance
 /// </summary>
 /// <remarks>Adds a range to search into the query</remarks>
 /// <remarks>All values specified in the startTerm are applied to this entire clause</remarks>
 /// <param name="startTerm">Starting half of the range to add to this query</param>
 /// <param name="endValue">Ending half of the range to add to this query</param>
 /// <param name="occurrence">Defines how the term is added to this query</param>
 public void AddTermRangeClause(SearchTerm startTerm, string endValue, ClauseOccurrence occurrence)
 {
     this.AddTermRangeClause(startTerm, endValue, occurrence, true, true);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Adds a range clause to this instance
 /// </summary>
 /// <remarks>Adds a range to search into the query</remarks>
 /// <remarks>All values specified in the startTerm are applied to this entire clause</remarks>
 /// <param name="startTerm">Starting half of the range to add to this query</param>
 /// <param name="endValue">Ending half of the range to add to this query</param>
 /// <param name="occurrence">Defines how the term is added to this query</param>
 /// <param name="includeStartValue">Determines if the starting term is included or excluded in the search results</param>
 /// <param name="includeEndValue">Determines if the ending term is included or excluded in the search results</param>
 public void AddTermRangeClause(SearchTerm startTerm, string endValue, ClauseOccurrence occurrence, bool includeStartValue, bool includeEndValue)
 {
     if (startTerm == null)
         throw new ArgumentNullException("startTerm", "startTerm cannot be null");
     if (string.IsNullOrEmpty(endValue))
         throw new ArgumentNullException("endValue", "endValue cannot be null or empty");
     IncrementTotalClauses(1);
     TermRangeQuery rangeQuery = new TermRangeQuery(startTerm.FieldName, startTerm.FieldValue, endValue, includeStartValue, includeEndValue);
     rangeQuery.SetBoost(startTerm.Boost);
     this.luceneQuery.Add(rangeQuery, TypeConverter.ConvertToLuceneClauseOccurrence(occurrence));
     rangeQuery = null;
 }
Ejemplo n.º 18
0
 /// <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());
 }
Ejemplo n.º 19
0
 /// <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;
 }
Ejemplo n.º 20
0
 /// <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());
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Adds a standard type clause to this instance
 /// </summary>
 /// <param name="term">Term to add to this query</param>
 public void AddBooleanClause(SearchTerm term)
 {
     this.AddBooleanClause(term, ClauseOccurrence.Default);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Adds a standard type clause to this instance
 /// </summary>
 /// <param name="term">Term to add to this query</param>
 public void AddBooleanClause(SearchTerm term)
 {
     this.AddBooleanClause(term, ClauseOccurrence.Default);
 }