// Define all public methods in this region
        #region PUBLIC METHODS

        /// <summary>
        ///
        /// </summary>
        /// <param name="doc_i"></param>
        /// <param name="doc_j"></param>
        /// <returns></returns>
        public float GetSimilarity(int doc_i, int doc_j)
        {
            float[] vector1 = GetTermVector(doc_i);
            float[] vector2 = GetTermVector(doc_j);

            return(TermVector.ComputeCosineSimilarity(vector1, vector2));
        }
        public double GetSimilarity(int doc_i, int doc_j)
        {
            double[] vector1 = GetTermVector(doc_i);
            double[] vector2 = GetTermVector(doc_j);

            return(TermVector.ComputeCosineSimilarity(vector1, vector2));
        }
Exemple #3
0
        /// <summary> Create a tokenized and indexed field that is not stored, optionally with
        /// storing term vectors.  This is useful for pre-analyzed fields.
        /// The TokenStream is read only when the Document is added to the index,
        /// i.e. you may not close the TokenStream until {@link IndexWriter#AddDocument(Document)}
        /// has been called.
        ///
        /// </summary>
        /// <param name="name">The name of the field
        /// </param>
        /// <param name="tokenStream">The TokenStream with the content
        /// </param>
        /// <param name="termVector">Whether term vector should be stored
        /// </param>
        /// <throws>  NullPointerException if name or tokenStream is <code>null</code> </throws>
        public Field(System.String name, TokenStream tokenStream, TermVector termVector)
        {
            if (name == null)
            {
                throw new System.NullReferenceException("name cannot be null");
            }
            if (tokenStream == null)
            {
                throw new System.NullReferenceException("tokenStream cannot be null");
            }

            this.name        = StringHelper.Intern(name);      // field names are interned
            this.fieldsData  = null;
            this.tokenStream = tokenStream;

            this.isStored     = false;
            this.isCompressed = false;

            this.isIndexed   = true;
            this.isTokenized = true;

            this.isBinary = false;

            SetStoreTermVector(termVector);
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="indexName">The name of the field that will be stored in the index. Defaults to the property/field name</param>
        /// <param name="store">Set to yes the store actual field in the index, no to not store it. Defaults to no (note, the JSON document itself is stored, and it can be retrieved from it).
        /// </param>
        /// <param name="index">Set to analyzed for the field to be indexed and searchable after being broken down into token using an analyzer. not_analyzed means that its still searchable, but does not go through any analysis process or broken down into tokens. no means that it won’t be searchable at all. Defaults to analyzed.</param>
        /// <param name="termVector">Possible values are no, yes, with_offsets, with_positions, with_positions_offsets. Defaults to no.</param>
        /// <param name="boost">The boost value. Defaults to 1.0.</param>
        /// <param name="nullValue">When there is a (JSON) null value for the field, use the null_value as the field value. Defaults to not adding the field at all.</param>
        /// <param name="omitNorms">Boolean value if norms should be omitted or not. Defaults to false.</param>
        /// <param name="omitTermFreqAndPositions">Boolean value if term freq and positions should be omitted. Defaults to false.</param>
        /// <param name="analyzer">The analyzer used to analyze the text contents when analyzed during indexing and when searching using a query string. Defaults to the globally configured analyzer.</param>
        /// <param name="indexAnalyzer">The analyzer used to analyze the text contents when analyzed during indexing.</param>
        /// <param name="searchAnalyzer">The analyzer used to analyze the field when part of a query string.</param>
        /// <param name="includeInAll">Should the field be included in the _all field (if enabled). Defaults to true or to the parent object type setting.</param>
        public StringFieldSetting AddStringField(string name, string indexName = null, Store store           = Store.no, IndexType index = IndexType.analyzed,
                                                 TermVector termVector         = TermVector.no, double boost = 1.0, string nullValue     = null,
                                                 bool omitNorms       = false, bool omitTermFreqAndPositions = false, string analyzer    = null,
                                                 string indexAnalyzer = null, string searchAnalyzer          = null, bool includeInAll   = true)
        {
            Contract.Assert(_fieldSettings != null);

            var field = new StringFieldSetting();

            field.Name       = name;
            field.IndexName  = indexName;
            field.Store      = store;
            field.Index      = index;
            field.TermVector = termVector;
            field.Boost      = boost;
            field.NullValue  = nullValue;
            field.OmitNorms  = omitNorms;
            field.OmitTermFreqAndPositions = omitTermFreqAndPositions;
            field.Analyzer       = analyzer;
            field.IndexAnalyzer  = indexAnalyzer;
            field.SearchAnalyzer = searchAnalyzer;
            field.IncludeInAll   = includeInAll;

            _fieldSettings[name] = field;
            return(field);
        }
Exemple #5
0
        public float GiveEqual(int doc_i, int doc_j)
        {
            float[] v1 = GetTerVec(doc_i);
            float[] v2 = GetTerVec(doc_j);

            return(TermVector.CosineEquality(v1, v2));
        }
Exemple #6
0
 private static void AssertTermVector(TermVector termvector)
 {
     termvector.Should().NotBeNull();
     termvector.FieldStatistics.Should().NotBeNull();
     termvector.FieldStatistics.DocumentCount.Should().BeGreaterThan(0);
     termvector.FieldStatistics.SumOfDocumentFrequencies.Should().BeGreaterThan(0);
     termvector.FieldStatistics.SumOfTotalTermFrequencies.Should().BeGreaterThan(0);
     termvector.Terms.Should().NotBeNull();
 }
Exemple #7
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Storage.GetHashCode();
         hashCode = (hashCode * 397) ^ Indexing.GetHashCode();
         hashCode = (hashCode * 397) ^ TermVector.GetHashCode();
         hashCode = (hashCode * 397) ^ (Spatial?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Analyzer != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(Analyzer) : 0);
         hashCode = (hashCode * 397) ^ Suggestions.GetHashCode();
         return(hashCode);
     }
 }
        private static void AssertTermVectors(TermVector vectors)
        {
            vectors.Terms.Should().NotBeEmpty();
            foreach (var vectorTerm in vectors.Terms)
            {
                vectorTerm.Key.Should().NotBeNullOrWhiteSpace();
                vectorTerm.Value.Should().NotBeNull();
                vectorTerm.Value.TermFrequency.Should().BeGreaterThan(0);
                vectorTerm.Value.TotalTermFrequency.Should().BeGreaterThan(0);
                vectorTerm.Value.Tokens.Should().NotBeEmpty();

                var token = vectorTerm.Value.Tokens.First();
                token.EndOffset.Should().BeGreaterThan(0);
            }
        }
Exemple #9
0
        /// <summary> Create a tokenized and indexed field that is not stored, optionally with
        /// storing term vectors.  The Reader is read only when the Document is added to the index,
        /// i.e. you may not close the Reader until <see cref="IndexWriter.AddDocument(Document)" />
        /// has been called.
        ///
        /// </summary>
        /// <param name="name">The name of the field
        /// </param>
        /// <param name="reader">The reader with the content
        /// </param>
        /// <param name="termVector">Whether term vector should be stored
        /// </param>
        /// <throws>  NullPointerException if name or reader is <c>null</c> </throws>
        public Field(System.String name, System.IO.TextReader reader, TermVector termVector)
        {
            if (name == null)
            {
                throw new System.NullReferenceException("name cannot be null");
            }
            if (reader == null)
            {
                throw new System.NullReferenceException("reader cannot be null");
            }

            this.internalName = StringHelper.Intern(name); // field names are interned
            this.fieldsData   = reader;

            this.internalIsStored = false;

            this.internalIsIndexed   = true;
            this.internalIsTokenized = true;

            this.internalIsBinary = false;

            SetStoreTermVector(termVector);
        }
Exemple #10
0
 private void  SetStoreTermVector(TermVector termVector)
 {
     if (termVector == TermVector.NO)
     {
         this.storeTermVector             = false;
         this.storePositionWithTermVector = false;
         this.storeOffsetWithTermVector   = false;
     }
     else if (termVector == TermVector.YES)
     {
         this.storeTermVector             = true;
         this.storePositionWithTermVector = false;
         this.storeOffsetWithTermVector   = false;
     }
     else if (termVector == TermVector.WITH_POSITIONS)
     {
         this.storeTermVector             = true;
         this.storePositionWithTermVector = true;
         this.storeOffsetWithTermVector   = false;
     }
     else if (termVector == TermVector.WITH_OFFSETS)
     {
         this.storeTermVector             = true;
         this.storePositionWithTermVector = false;
         this.storeOffsetWithTermVector   = true;
     }
     else if (termVector == TermVector.WITH_POSITIONS_OFFSETS)
     {
         this.storeTermVector             = true;
         this.storePositionWithTermVector = true;
         this.storeOffsetWithTermVector   = true;
     }
     else
     {
         throw new System.ArgumentException("unknown termVector parameter " + termVector);
     }
 }
Exemple #11
0
		/// <summary> Create a field by specifying its name, value and how it will
		/// be saved in the index.
		/// 
		/// </summary>
		/// <param name="name">The name of the field
		/// </param>
		/// <param name="internName">Whether to .intern() name or not
		/// </param>
		/// <param name="value">The string to process
		/// </param>
		/// <param name="store">Whether <code>value</code> should be stored in the index
		/// </param>
		/// <param name="index">Whether the field should be indexed, and if so, if it should
		/// be tokenized before indexing 
		/// </param>
		/// <param name="termVector">Whether term vector should be stored
		/// </param>
		/// <throws>  NullPointerException if name or value is <code>null</code> </throws>
		/// <throws>  IllegalArgumentException in any of the following situations: </throws>
		/// <summary> <ul> 
		/// <li>the field is neither stored nor indexed</li> 
		/// <li>the field is not indexed but termVector is <code>TermVector.YES</code></li>
		/// </ul> 
		/// </summary>
		public Field(System.String name, bool internName, System.String value_Renamed, Store store, Index index, TermVector termVector)
		{
			if (name == null)
				throw new System.NullReferenceException("name cannot be null");
			if (value_Renamed == null)
				throw new System.NullReferenceException("value cannot be null");
			if (name.Length == 0 && value_Renamed.Length == 0)
				throw new System.ArgumentException("name and value cannot both be empty");
			if (index == Index.NO && store == Store.NO)
				throw new System.ArgumentException("it doesn't make sense to have a field that " + "is neither indexed nor stored");
			if (index == Index.NO && termVector != TermVector.NO)
				throw new System.ArgumentException("cannot store term vector information " + "for a field that is not indexed");
			
			if (internName)
			// field names are optionally interned
				name = StringHelper.Intern(name);
			
			this.name = name;
			
			this.fieldsData = value_Renamed;
			
			if (store == Store.YES)
			{
				this.isStored = true;
				this.isCompressed = false;
			}
			else if (store == Store.COMPRESS)
			{
				this.isStored = true;
				this.isCompressed = true;
			}
			else if (store == Store.NO)
			{
				this.isStored = false;
				this.isCompressed = false;
			}
			else
			{
				throw new System.ArgumentException("unknown store parameter " + store);
			}
			
			if (index == Index.NO)
			{
				this.isIndexed = false;
				this.isTokenized = false;
				this.omitTermFreqAndPositions = false;
				this.omitNorms = true;
			}
			else if (index == Index.ANALYZED)
			{
				this.isIndexed = true;
				this.isTokenized = true;
			}
			else if (index == Index.NOT_ANALYZED)
			{
				this.isIndexed = true;
				this.isTokenized = false;
			}
			else if (index == Index.NOT_ANALYZED_NO_NORMS)
			{
				this.isIndexed = true;
				this.isTokenized = false;
				this.omitNorms = true;
			}
			else if (index == Index.ANALYZED_NO_NORMS)
			{
				this.isIndexed = true;
				this.isTokenized = true;
				this.omitNorms = true;
			}
			else
			{
				throw new System.ArgumentException("unknown index parameter " + index);
			}
			
			this.isBinary = false;
			
			SetStoreTermVector(termVector);
		}
Exemple #12
0
		/// <summary> Create a field by specifying its name, value and how it will
		/// be saved in the index.
		/// 
		/// </summary>
		/// <param name="name">The name of the field
		/// </param>
		/// <param name="value">The string to process
		/// </param>
		/// <param name="store">Whether <code>value</code> should be stored in the index
		/// </param>
		/// <param name="index">Whether the field should be indexed, and if so, if it should
		/// be tokenized before indexing 
		/// </param>
		/// <param name="termVector">Whether term vector should be stored
		/// </param>
		/// <throws>  NullPointerException if name or value is <code>null</code> </throws>
		/// <throws>  IllegalArgumentException in any of the following situations: </throws>
		/// <summary> <ul> 
		/// <li>the field is neither stored nor indexed</li> 
		/// <li>the field is not indexed but termVector is <code>TermVector.YES</code></li>
		/// </ul> 
		/// </summary>
		public Field(System.String name, System.String value_Renamed, Store store, Index index, TermVector termVector):this(name, true, value_Renamed, store, index, termVector)
		{
		}
        /// <summary> Create a field by specifying its name, value and how it will
        /// be saved in the index.
        /// 
        /// </summary>
        /// <param name="name">The name of the field
        /// </param>
        /// <param name="internName">Whether to .intern() name or not
        /// </param>
        /// <param name="value">The string to process
        /// </param>
        /// <param name="store">Whether <c>value</c> should be stored in the index
        /// </param>
        /// <param name="index">Whether the field should be indexed, and if so, if it should
        /// be tokenized before indexing 
        /// </param>
        /// <param name="termVector">Whether term vector should be stored
        /// </param>
        /// <throws>  NullPointerException if name or value is <c>null</c> </throws>
        /// <throws>  IllegalArgumentException in any of the following situations: </throws>
        /// <summary> <list> 
        /// <item>the field is neither stored nor indexed</item> 
        /// <item>the field is not indexed but termVector is <c>TermVector.YES</c></item>
        /// </list> 
        /// </summary>
        public Field(System.String name, bool internName, System.String value, Store store, Index index, TermVector termVector)
        {
            if (name == null)
                throw new System.NullReferenceException("name cannot be null");
            if (value == null)
                throw new System.NullReferenceException("value cannot be null");
            if (name.Length == 0 && value.Length == 0)
                throw new System.ArgumentException("name and value cannot both be empty");
            if (index == Index.NO && store == Store.NO)
                throw new System.ArgumentException("it doesn't make sense to have a field that " + "is neither indexed nor stored");
            if (index == Index.NO && termVector != TermVector.NO)
                throw new System.ArgumentException("cannot store term vector information " + "for a field that is not indexed");
            
            if (internName)
            // field names are optionally interned
                name = StringHelper.Intern(name);
            
            this.internalName = name;
            
            this.fieldsData = value;

            this.internalIsStored = store.IsStored();

            this.internalIsIndexed = index.IsIndexed();
            this.internalIsTokenized = index.IsAnalyzed();
            this.internalOmitNorms = index.OmitNorms();

            if (index == Index.NO)
            {
                this.internalOmitTermFreqAndPositions = false;
            }
            
            this.internalIsBinary = false;
            
            SetStoreTermVector(termVector);
        }
Exemple #14
0
		/// <summary> Create a field by specifying its name, value and how it will
		/// be saved in the index.
		/// 
		/// </summary>
		/// <param name="name">The name of the field
		/// </param>
		/// <param name="value">The string to process
		/// </param>
		/// <param name="store">Whether <code>value</code> should be stored in the index
		/// </param>
		/// <param name="index">Whether the field should be indexed, and if so, if it should
		/// be tokenized before indexing 
		/// </param>
		/// <param name="termVector">Whether term vector should be stored
		/// </param>
		/// <throws>  NullPointerException if name or value is <code>null</code> </throws>
		/// <throws>  IllegalArgumentException in any of the following situations: </throws>
		/// <summary> <ul> 
		/// <li>the field is neither stored nor indexed</li> 
		/// <li>the field is not indexed but termVector is <code>TermVector.YES</code></li>
		/// </ul> 
		/// </summary>
		public Field(System.String name, System.String value_Renamed, Store store, Index index, TermVector termVector)
		{
			if (name == null)
				throw new System.NullReferenceException("name cannot be null");
			if (value_Renamed == null)
				throw new System.NullReferenceException("value cannot be null");
			if (index == Index.NO && store == Store.NO)
				throw new System.ArgumentException("it doesn't make sense to have a field that " + "is neither indexed nor stored");
			if (index == Index.NO && termVector != TermVector.NO)
				throw new System.ArgumentException("cannot store term vector information " + "for a field that is not indexed");
			
			this.name = String.Intern(name); // field names are interned
			this.fieldsData = value_Renamed;
			
			if (store == Store.YES)
			{
				this.isStored = true;
				this.isCompressed = false;
			}
			else if (store == Store.COMPRESS)
			{
				this.isStored = true;
				this.isCompressed = true;
			}
			else if (store == Store.NO)
			{
				this.isStored = false;
				this.isCompressed = false;
			}
			else
			{
				throw new System.ArgumentException("unknown store parameter " + store);
			}
			
			if (index == Index.NO)
			{
				this.isIndexed = false;
				this.isTokenized = false;
			}
			else if (index == Index.TOKENIZED)
			{
				this.isIndexed = true;
				this.isTokenized = true;
			}
			else if (index == Index.UN_TOKENIZED)
			{
				this.isIndexed = true;
				this.isTokenized = false;
			}
			else if (index == Index.NO_NORMS)
			{
				this.isIndexed = true;
				this.isTokenized = false;
				this.omitNorms = true;
			}
			else
			{
				throw new System.ArgumentException("unknown index parameter " + index);
			}
			
			this.isBinary = false;
			
			SetStoreTermVector(termVector);
		}
Exemple #15
0
 public Field(String name, TextReader reader, TermVector termVector)
     : this(name, reader, TranslateFieldType(Store.NO, Index.ANALYZED, termVector))
 {
 }
Exemple #16
0
        public static FieldType TranslateFieldType(Store store, Index index, TermVector termVector)
        {
            FieldType ft = new FieldType();

            ft.Stored = store == Store.YES;

            switch (index)
            {
            case Index.ANALYZED:
                ft.Indexed   = true;
                ft.Tokenized = true;
                break;

            case Index.ANALYZED_NO_NORMS:
                ft.Indexed   = true;
                ft.Tokenized = true;
                ft.OmitNorms = true;
                break;

            case Index.NOT_ANALYZED:
                ft.Indexed   = true;
                ft.Tokenized = false;
                break;

            case Index.NOT_ANALYZED_NO_NORMS:
                ft.Indexed   = true;
                ft.Tokenized = false;
                ft.OmitNorms = true;
                break;

            case Index.NO:
                break;
            }

            switch (termVector)
            {
            case TermVector.NO:
                break;

            case TermVector.YES:
                ft.StoreTermVectors = true;
                break;

            case TermVector.WITH_POSITIONS:
                ft.StoreTermVectors         = true;
                ft.StoreTermVectorPositions = true;
                break;

            case TermVector.WITH_OFFSETS:
                ft.StoreTermVectors       = true;
                ft.StoreTermVectorOffsets = true;
                break;

            case TermVector.WITH_POSITIONS_OFFSETS:
                ft.StoreTermVectors         = true;
                ft.StoreTermVectorPositions = true;
                ft.StoreTermVectorOffsets   = true;
                break;
            }
            ft.Freeze();
            return(ft);
        }
Exemple #17
0
        /// <summary> Create a field by specifying its name, value and how it will
        /// be saved in the index.
        ///
        /// </summary>
        /// <param name="name">The name of the field
        /// </param>
        /// <param name="value">The string to process
        /// </param>
        /// <param name="store">Whether <code>value</code> should be stored in the index
        /// </param>
        /// <param name="index">Whether the field should be indexed, and if so, if it should
        /// be tokenized before indexing
        /// </param>
        /// <param name="termVector">Whether term vector should be stored
        /// </param>
        /// <throws>  NullPointerException if name or value is <code>null</code> </throws>
        /// <throws>  IllegalArgumentException in any of the following situations: </throws>
        /// <summary> <ul>
        /// <li>the field is neither stored nor indexed</li>
        /// <li>the field is not indexed but termVector is <code>TermVector.YES</code></li>
        /// </ul>
        /// </summary>
        public Field(System.String name, System.String value_Renamed, Store store, Index index, TermVector termVector)
        {
            if (name == null)
            {
                throw new System.NullReferenceException("name cannot be null");
            }
            if (value_Renamed == null)
            {
                throw new System.NullReferenceException("value cannot be null");
            }
            if (name.Length == 0 && value_Renamed.Length == 0)
            {
                throw new System.ArgumentException("name and value cannot both be empty");
            }
            if (index == Index.NO && store == Store.NO)
            {
                throw new System.ArgumentException("it doesn't make sense to have a field that " + "is neither indexed nor stored");
            }
            if (index == Index.NO && termVector != TermVector.NO)
            {
                throw new System.ArgumentException("cannot store term vector information " + "for a field that is not indexed");
            }

            this.name       = String.Intern(name);       // field names are interned
            this.fieldsData = value_Renamed;

            if (store == Store.YES)
            {
                this.isStored     = true;
                this.isCompressed = false;
            }
            else if (store == Store.COMPRESS)
            {
                this.isStored     = true;
                this.isCompressed = true;
            }
            else if (store == Store.NO)
            {
                this.isStored     = false;
                this.isCompressed = false;
            }
            else
            {
                throw new System.ArgumentException("unknown store parameter " + store);
            }

            if (index == Index.NO)
            {
                this.isIndexed   = false;
                this.isTokenized = false;
            }
            else if (index == Index.TOKENIZED)
            {
                this.isIndexed   = true;
                this.isTokenized = true;
            }
            else if (index == Index.UN_TOKENIZED)
            {
                this.isIndexed   = true;
                this.isTokenized = false;
            }
            else if (index == Index.NO_NORMS)
            {
                this.isIndexed   = true;
                this.isTokenized = false;
                this.omitNorms   = true;
            }
            else
            {
                throw new System.ArgumentException("unknown index parameter " + index);
            }

            this.isBinary = false;

            SetStoreTermVector(termVector);
        }
Exemple #18
0
 public Field(String name, TokenStream tokenStream, TermVector termVector)
     : this(name, tokenStream, TranslateFieldType(Store.NO, Index.ANALYZED, termVector))
 {
 }
Exemple #19
0
        /// <summary> Create a field by specifying its name, value and how it will
        /// be saved in the index.
        ///
        /// </summary>
        /// <param name="name">The name of the field
        /// </param>
        /// <param name="internName">Whether to .intern() name or not
        /// </param>
        /// <param name="value">The string to process
        /// </param>
        /// <param name="store">Whether <c>value</c> should be stored in the index
        /// </param>
        /// <param name="index">Whether the field should be indexed, and if so, if it should
        /// be tokenized before indexing
        /// </param>
        /// <param name="termVector">Whether term vector should be stored
        /// </param>
        /// <throws>  NullPointerException if name or value is <c>null</c> </throws>
        /// <throws>  IllegalArgumentException in any of the following situations: </throws>
        /// <summary> <list>
        /// <item>the field is neither stored nor indexed</item>
        /// <item>the field is not indexed but termVector is <c>TermVector.YES</c></item>
        /// </list>
        /// </summary>
        public Field(System.String name, bool internName, System.String value, Store store, Index index, TermVector termVector)
        {
            if (name == null)
            {
                throw new System.NullReferenceException("name cannot be null");
            }
            if (value == null)
            {
                throw new System.NullReferenceException("value cannot be null");
            }
            if (name.Length == 0 && value.Length == 0)
            {
                throw new System.ArgumentException("name and value cannot both be empty");
            }
            if (index == Index.NO && store == Store.NO)
            {
                throw new System.ArgumentException("it doesn't make sense to have a field that " + "is neither indexed nor stored");
            }
            if (index == Index.NO && termVector != TermVector.NO)
            {
                throw new System.ArgumentException("cannot store term vector information " + "for a field that is not indexed");
            }

            if (internName)
            {
                // field names are optionally interned
                name = StringHelper.Intern(name);
            }

            this.internalName = name;

            this.fieldsData = value;

            this.internalIsStored = store.IsStored();

            this.internalIsIndexed   = index.IsIndexed();
            this.internalIsTokenized = index.IsAnalyzed();
            this.internalOmitNorms   = index.OmitNorms();

            if (index == Index.NO)
            {
                this.internalOmitTermFreqAndPositions = false;
            }

            this.internalIsBinary = false;

            SetStoreTermVector(termVector);
        }
Exemple #20
0
        public static FieldType TranslateFieldType(Store store, Index index, TermVector termVector)
        {
            FieldType ft = new FieldType();

            ft.Stored = store == Store.YES;

            switch (index)
            {
                case Index.ANALYZED:
                    ft.Indexed = true;
                    ft.Tokenized = true;
                    break;

                case Index.ANALYZED_NO_NORMS:
                    ft.Indexed = true;
                    ft.Tokenized = true;
                    ft.OmitNorms = true;
                    break;

                case Index.NOT_ANALYZED:
                    ft.Indexed = true;
                    ft.Tokenized = false;
                    break;

                case Index.NOT_ANALYZED_NO_NORMS:
                    ft.Indexed = true;
                    ft.Tokenized = false;
                    ft.OmitNorms = true;
                    break;

                case Index.NO:
                    break;
            }

            switch (termVector)
            {
                case TermVector.NO:
                    break;

                case TermVector.YES:
                    ft.StoreTermVectors = true;
                    break;

                case TermVector.WITH_POSITIONS:
                    ft.StoreTermVectors = true;
                    ft.StoreTermVectorPositions = true;
                    break;

                case TermVector.WITH_OFFSETS:
                    ft.StoreTermVectors = true;
                    ft.StoreTermVectorOffsets = true;
                    break;

                case TermVector.WITH_POSITIONS_OFFSETS:
                    ft.StoreTermVectors = true;
                    ft.StoreTermVectorPositions = true;
                    ft.StoreTermVectorOffsets = true;
                    break;
            }
            ft.Freeze();
            return ft;
        }
Exemple #21
0
		private void  SetStoreTermVector(TermVector termVector)
		{
			if (termVector == TermVector.NO)
			{
				this.storeTermVector = false;
				this.storePositionWithTermVector = false;
				this.storeOffsetWithTermVector = false;
			}
			else if (termVector == TermVector.YES)
			{
				this.storeTermVector = true;
				this.storePositionWithTermVector = false;
				this.storeOffsetWithTermVector = false;
			}
			else if (termVector == TermVector.WITH_POSITIONS)
			{
				this.storeTermVector = true;
				this.storePositionWithTermVector = true;
				this.storeOffsetWithTermVector = false;
			}
			else if (termVector == TermVector.WITH_OFFSETS)
			{
				this.storeTermVector = true;
				this.storePositionWithTermVector = false;
				this.storeOffsetWithTermVector = true;
			}
			else if (termVector == TermVector.WITH_POSITIONS_OFFSETS)
			{
				this.storeTermVector = true;
				this.storePositionWithTermVector = true;
				this.storeOffsetWithTermVector = true;
			}
			else
			{
				throw new System.ArgumentException("unknown termVector parameter " + termVector);
			}
		}
Exemple #22
0
		/// <summary> Create a tokenized and indexed field that is not stored, optionally with 
		/// storing term vectors.  The Reader is read only when the Document is added to the index,
		/// i.e. you may not close the Reader until {@link IndexWriter#AddDocument(Document)}
		/// has been called.
		/// 
		/// </summary>
		/// <param name="name">The name of the field
		/// </param>
		/// <param name="reader">The reader with the content
		/// </param>
		/// <param name="termVector">Whether term vector should be stored
		/// </param>
		/// <throws>  NullPointerException if name or reader is <code>null</code> </throws>
		public Field(System.String name, System.IO.TextReader reader, TermVector termVector)
		{
			if (name == null)
				throw new System.NullReferenceException("name cannot be null");
			if (reader == null)
				throw new System.NullReferenceException("reader cannot be null");
			
			this.name = StringHelper.Intern(name); // field names are interned
			this.fieldsData = reader;
			
			this.isStored = false;
			this.isCompressed = false;
			
			this.isIndexed = true;
			this.isTokenized = true;
			
			this.isBinary = false;
			
			SetStoreTermVector(termVector);
		}
Exemple #23
0
		/// <summary> Create a tokenized and indexed field that is not stored, optionally with 
		/// storing term vectors.  This is useful for pre-analyzed fields.
		/// The TokenStream is read only when the Document is added to the index,
		/// i.e. you may not close the TokenStream until {@link IndexWriter#AddDocument(Document)}
		/// has been called.
		/// 
		/// </summary>
		/// <param name="name">The name of the field
		/// </param>
		/// <param name="tokenStream">The TokenStream with the content
		/// </param>
		/// <param name="termVector">Whether term vector should be stored
		/// </param>
		/// <throws>  NullPointerException if name or tokenStream is <code>null</code> </throws>
		public Field(System.String name, TokenStream tokenStream, TermVector termVector)
		{
			if (name == null)
				throw new System.NullReferenceException("name cannot be null");
			if (tokenStream == null)
				throw new System.NullReferenceException("tokenStream cannot be null");
			
			this.name = StringHelper.Intern(name); // field names are interned
			this.fieldsData = null;
			this.tokenStream = tokenStream;
			
			this.isStored = false;
			this.isCompressed = false;
			
			this.isIndexed = true;
			this.isTokenized = true;
			
			this.isBinary = false;
			
			SetStoreTermVector(termVector);
		}
Exemple #24
0
 public Field(String name, TextReader reader, TermVector termVector)
     : this(name, reader, TranslateFieldType(Store.NO, Index.ANALYZED, termVector))
 {
 }
Exemple #25
0
 public Field(String name, String value, Store store, Index index, TermVector termVector)
     : this(name, value, TranslateFieldType(store, index, termVector))
 {
 }
Exemple #26
0
 public Field(String name, String value, Store store, Index index, TermVector termVector)
     : this(name, value, TranslateFieldType(store, index, termVector))
 {
 }
Exemple #27
0
 public Field(String name, TokenStream tokenStream, TermVector termVector)
     : this(name, tokenStream, TranslateFieldType(Store.NO, Index.ANALYZED, termVector))
 {
 }
Exemple #28
0
 public StringMap <T> TermVector(TermVector termVector)
 {
     RegisterCustomJsonMap("'term_vector': {0}", termVector.AsString().Quotate());
     return(this);
 }
Exemple #29
0
 /// <summary> Create a field by specifying its name, value and how it will
 /// be saved in the index.
 ///
 /// </summary>
 /// <param name="name">The name of the field
 /// </param>
 /// <param name="value">The string to process
 /// </param>
 /// <param name="store">Whether <code>value</code> should be stored in the index
 /// </param>
 /// <param name="index">Whether the field should be indexed, and if so, if it should
 /// be tokenized before indexing
 /// </param>
 /// <param name="termVector">Whether term vector should be stored
 /// </param>
 /// <throws>  NullPointerException if name or value is <code>null</code> </throws>
 /// <throws>  IllegalArgumentException in any of the following situations: </throws>
 /// <summary> <ul>
 /// <li>the field is neither stored nor indexed</li>
 /// <li>the field is not indexed but termVector is <code>TermVector.YES</code></li>
 /// </ul>
 /// </summary>
 public Field(System.String name, System.String value_Renamed, Store store, Index index, TermVector termVector) : this(name, true, value_Renamed, store, index, termVector)
 {
 }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="indexName">The name of the field that will be stored in the index. Defaults to the property/field name</param>
		/// <param name="store">Set to yes the store actual field in the index, no to not store it. Defaults to no (note, the JSON document itself is stored, and it can be retrieved from it).
		/// </param>
		/// <param name="index">Set to analyzed for the field to be indexed and searchable after being broken down into token using an analyzer. not_analyzed means that its still searchable, but does not go through any analysis process or broken down into tokens. no means that it won’t be searchable at all. Defaults to analyzed.</param>
		/// <param name="termVector">Possible values are no, yes, with_offsets, with_positions, with_positions_offsets. Defaults to no.</param>
		/// <param name="boost">The boost value. Defaults to 1.0.</param>
		/// <param name="nullValue">When there is a (JSON) null value for the field, use the null_value as the field value. Defaults to not adding the field at all.</param>
		/// <param name="omitNorms">Boolean value if norms should be omitted or not. Defaults to false.</param>
		/// <param name="omitTermFreqAndPositions">Boolean value if term freq and positions should be omitted. Defaults to false.</param>
		/// <param name="analyzer">The analyzer used to analyze the text contents when analyzed during indexing and when searching using a query string. Defaults to the globally configured analyzer.</param>
		/// <param name="indexAnalyzer">The analyzer used to analyze the text contents when analyzed during indexing.</param>
		/// <param name="searchAnalyzer">The analyzer used to analyze the field when part of a query string.</param>
		/// <param name="includeInAll">Should the field be included in the _all field (if enabled). Defaults to true or to the parent object type setting.</param>
        public StringFieldSetting AddStringField(string name, string indexName = null, Store store = Store.no, IndexType index = IndexType.analyzed,
									  TermVector termVector = TermVector.no, double boost = 1.0, string nullValue = null,
									  bool omitNorms = false, bool omitTermFreqAndPositions = false, string analyzer = null,
									  string indexAnalyzer = null, string searchAnalyzer = null, bool includeInAll = true)
		{
			Contract.Assert(_fieldSettings != null);

			var field = new StringFieldSetting();
			field.Name = name;
			field.IndexName = indexName;
			field.Store = store;
			field.Index = index;
			field.TermVector = termVector;
			field.Boost = boost;
			field.NullValue = nullValue;
			field.OmitNorms = omitNorms;
			field.OmitTermFreqAndPositions = omitTermFreqAndPositions;
			field.Analyzer = analyzer;
			field.IndexAnalyzer = indexAnalyzer;
			field.SearchAnalyzer = searchAnalyzer;
			field.IncludeInAll = includeInAll;

			_fieldSettings[name] = field;
		    return field;
		}