Exemple #1
0
        public void IndexConfigTest()
        {
            var x = new IndexOptions();

            Console.WriteLine(x.ToString());

            x.Name = "name";
            Assert.That(x.Name, Is.EqualTo("name"));

            Assert.That(x.Type, Is.EqualTo(IndexOptions.DefaultType));
            x.Type = IndexType.Hashed;
            Assert.That(x.Type, Is.EqualTo(IndexType.Hashed));

            x = new IndexOptions(new [] { "aaa", "bbb" });
            Assert.That(x.Attributes.Count, Is.EqualTo(2));
            x.AddAttribute("ccc");
            Assert.That(x.Attributes.Count, Is.EqualTo(3));
            Assert.That(x.Attributes, Does.Contain("aaa"));
            Assert.That(x.Attributes, Does.Contain("bbb"));
            Assert.That(x.Attributes, Does.Contain("ccc"));

            Assert.That(x.BitmapIndexOptions, Is.Not.Null);
            var y = new BitmapIndexOptions();

            x.BitmapIndexOptions = y;
            Assert.That(x.BitmapIndexOptions, Is.SameAs(y));

            IndexOptions.ValidateAttribute(x, "flub");

            Assert.Throws <ArgumentNullException>(() => IndexOptions.ValidateAttribute(x, null));
            Assert.Throws <ArgumentException>(() => IndexOptions.ValidateAttribute(x, ""));
            Assert.Throws <ArgumentException>(() => IndexOptions.ValidateAttribute(x, "duh."));
        }
        public override string JsonString()
        {
            var elasticsearchCrudJsonWriter = new ElasticsearchCrudJsonWriter();

            elasticsearchCrudJsonWriter.JsonWriter.WriteStartObject();

            JsonHelper.WriteValue("type", "string", elasticsearchCrudJsonWriter);
            JsonHelper.WriteValue("index_name", _indexName, elasticsearchCrudJsonWriter, _indexNameSet);
            JsonHelper.WriteValue("store", _store, elasticsearchCrudJsonWriter, _storeSet);
            JsonHelper.WriteValue("index", _index.ToString(), elasticsearchCrudJsonWriter, _indexSet);
            JsonHelper.WriteValue("doc_values", _docValues, elasticsearchCrudJsonWriter, _docValuesSet);
            JsonHelper.WriteValue("term_vector", _termVector.ToString(), elasticsearchCrudJsonWriter, _termVectorSet);
            JsonHelper.WriteValue("boost", _boost, elasticsearchCrudJsonWriter, _boostSet);
            JsonHelper.WriteValue("null_value", _nullValue, elasticsearchCrudJsonWriter, _nullValueSet);

            //"norms" : {
            //		"enabled" : false
            //	}
            if (_normsEnabledSet || _normsLoadingSet)
            {
                elasticsearchCrudJsonWriter.JsonWriter.WritePropertyName("norms");
                elasticsearchCrudJsonWriter.JsonWriter.WriteStartObject();
                JsonHelper.WriteValue("enabled", _normsEnabled, elasticsearchCrudJsonWriter, _normsEnabledSet);
                JsonHelper.WriteValue("loading", _normsLoading.ToString(), elasticsearchCrudJsonWriter, _normsLoadingSet);
                elasticsearchCrudJsonWriter.JsonWriter.WriteEndObject();
            }

            JsonHelper.WriteValue("index_options", _indexOptions.ToString(), elasticsearchCrudJsonWriter, _indexOptionsSet);
            JsonHelper.WriteValue("analyzer", _analyzer, elasticsearchCrudJsonWriter, _analyzerSet);
            JsonHelper.WriteValue("index_analyzer", _indexAnalyzer, elasticsearchCrudJsonWriter, _indexAnalyzerSet);
            JsonHelper.WriteValue("search_analyzer", _searchAnalyzer, elasticsearchCrudJsonWriter, _searchAnalyzerSet);
            JsonHelper.WriteValue("include_in_all", _includeInAll, elasticsearchCrudJsonWriter, _includeInAllSet);
            JsonHelper.WriteValue("ignore_above", _ignoreAbove, elasticsearchCrudJsonWriter, _ignoreAboveSet);
            JsonHelper.WriteValue("position_offset_gap", _positionOffsetGap, elasticsearchCrudJsonWriter, _positionOffsetGapSet);

            WriteBaseValues(elasticsearchCrudJsonWriter);

            elasticsearchCrudJsonWriter.JsonWriter.WriteEndObject();
            return(elasticsearchCrudJsonWriter.Stringbuilder.ToString());
        }
Exemple #3
0
        /// <summary>
        /// Prints a <see cref="FieldType"/> for human consumption. </summary>
        public override sealed string ToString()
        {
            var result = new StringBuilder();

            if (IsStored)
            {
                result.Append("stored");
            }
            if (IsIndexed)
            {
                if (result.Length > 0)
                {
                    result.Append(",");
                }
                result.Append("indexed");
                if (IsTokenized)
                {
                    result.Append(",tokenized");
                }
                if (StoreTermVectors)
                {
                    result.Append(",termVector");
                }
                if (StoreTermVectorOffsets)
                {
                    result.Append(",termVectorOffsets");
                }
                if (StoreTermVectorPositions)
                {
                    result.Append(",termVectorPosition");
                    if (StoreTermVectorPayloads)
                    {
                        result.Append(",termVectorPayloads");
                    }
                }
                if (OmitNorms)
                {
                    result.Append(",omitNorms");
                }
                if (indexOptions != IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
                {
                    result.Append(",indexOptions=");
                    // LUCENENET: duplcate what would happen if you print a null indexOptions in Java
                    result.Append(indexOptions != IndexOptions.NONE ? indexOptions.ToString() : string.Empty);
                }
                if (numericType != NumericType.NONE)
                {
                    result.Append(",numericType=");
                    result.Append(numericType);
                    result.Append(",numericPrecisionStep=");
                    result.Append(numericPrecisionStep);
                }
            }
            if (docValueType != DocValuesType.NONE)
            {
                if (result.Length > 0)
                {
                    result.Append(",");
                }
                result.Append("docValueType=");
                result.Append(docValueType);
            }

            return(result.ToString());
        }