public Document BuildRecord()
        {
            var doc = new Document();

            var numericField = new NumericField("DatabaseID", Field.Store.YES, false);
            numericField.SetIntValue(Email.ID);
            doc.Add(numericField);

            var field = new Field("UniqueID", UniqueID, Field.Store.YES, Field.Index.NOT_ANALYZED);
            doc.Add(field);

            field = new Field("Title", Title, Field.Store.YES, Field.Index.NOT_ANALYZED);
            doc.Add(field);

            field = new Field("Description", Description, Field.Store.YES, Field.Index.NOT_ANALYZED);
            doc.Add(field);

            field = new Field("Type", Type, Field.Store.YES, Field.Index.ANALYZED);
            doc.Add(field);

               /* field = new Field("Name", EventDescription.Name, Field.Store.YES, Field.Index.ANALYZED);
            doc.Add(field);*/

            return doc;
        }
        public Document BuildRecord()
        {
            var doc = new Document();

            var numericField = new NumericField("DatabaseID", Field.Store.YES, false);
            numericField.SetIntValue(User.ID);
            doc.Add(numericField);

            var field = new Field("UniqueID", UniqueID, Field.Store.YES, Field.Index.NOT_ANALYZED);
            doc.Add(field);

            field = new Field("Title", Title, Field.Store.YES, Field.Index.NOT_ANALYZED);
            doc.Add(field);

            field = new Field("Description", Description, Field.Store.YES, Field.Index.NOT_ANALYZED);
            doc.Add(field);

            field = new Field("Type", Type, Field.Store.YES, Field.Index.ANALYZED);
            doc.Add(field);

            field = new Field("Username", User.Username, Field.Store.YES, Field.Index.ANALYZED);
            doc.Add(field);

            field = new Field("Forename", User.Forename, Field.Store.NO, Field.Index.ANALYZED);
            doc.Add(field);

            field = new Field("Surname", User.Surname, Field.Store.NO, Field.Index.ANALYZED);
            doc.Add(field);

            field = new Field("EventDescription", User.Email, Field.Store.NO, Field.Index.ANALYZED);
            doc.Add(field);

            if (User.Roles.HasContent())
            {
                foreach (var role in User.Roles)
                {
                    field = new Field("Role", role.Name, Field.Store.NO, Field.Index.ANALYZED);
                    doc.Add(field);
                }
            }

            field = new Field("Enabled", User.Enabled.ToString(), Field.Store.NO, Field.Index.ANALYZED);
            doc.Add(field);

            field = new Field("Archived", User.Archived.ToString(), Field.Store.NO, Field.Index.ANALYZED);
            doc.Add(field);

            return doc;
        }
Beispiel #3
0
        public IFieldable CreateLuceneField(string fieldName, object fieldValue)
        {
            if (!Numeric)
            {
                return new Field(fieldName, LuceneUtility.ToFieldStringValue(fieldValue), Store, Index)
                {
                    Boost = Boost
                };
            }

            var field = new NumericField(fieldName, Store, Index != Field.Index.NO)
            {
                Boost = Boost
            };

            if (fieldValue is Int32)
            {
                field.SetIntValue((int)fieldValue);
            }
            else if (fieldValue is Int64)
            {
                field.SetLongValue((long)fieldValue);
            }
            else if (fieldValue is Single)
            {
                field.SetFloatValue((float)fieldValue);
            }
            else if (fieldValue is Double)
            {
                field.SetDoubleValue((double)fieldValue);
            }
            else if (fieldValue is Decimal)
            {
                field.SetDoubleValue((double)(decimal)fieldValue);
            }
            else
            {
                throw new NotSupportedException();
            }

            return field;
        }
Beispiel #4
0
        public void FillDocument(Song song, Document doc)
        {
            if (!string.IsNullOrWhiteSpace(song.RelativePath))
                doc.Add(new Field(nameof(song.RelativePath), song.RelativePath, Field.Store.YES, Field.Index.ANALYZED));

            if (!string.IsNullOrWhiteSpace(song.Name))
                doc.Add(new Field(nameof(song.Name), song.Name, Field.Store.YES, Field.Index.ANALYZED));

            if (!string.IsNullOrWhiteSpace(song.Artist))
                doc.Add(new Field(nameof(song.Artist), song.Artist, Field.Store.YES, Field.Index.ANALYZED));

            var fieldFileLenght = new NumericField(nameof(song.FileLength), Field.Store.YES, false);
            fieldFileLenght.SetIntValue(song.FileLength);
            doc.Add(fieldFileLenght);

            var fieldLenght = new NumericField(nameof(song.Length), Field.Store.YES, false);
            fieldLenght.SetIntValue((int)song.Length.TotalMilliseconds);
            doc.Add(fieldLenght);

            doc.Add(new Field(nameof(song.LastModified), DateTools.DateToString(song.LastModified, DateTools.Resolution.SECOND), Field.Store.YES,
                Field.Index.NOT_ANALYZED));
        }
Beispiel #5
0
		private static Document CloneDocument(Document luceneDoc)
		{
			var clonedDocument = new Document();
			foreach (AbstractField field in luceneDoc.GetFields())
			{
				var numericField = field as NumericField;
				if (numericField != null)
				{
					var clonedNumericField = new NumericField(numericField.Name,
															numericField.IsStored ? Field.Store.YES : Field.Store.NO,
															numericField.IsIndexed);
					var numericValue = numericField.NumericValue;
					if (numericValue is int)
					{
						clonedNumericField.SetIntValue((int)numericValue);
					}
					else if (numericValue is long)
					{
						clonedNumericField.SetLongValue((long)numericValue);
					}
					else if (numericValue is double)
					{
						clonedNumericField.SetDoubleValue((double)numericValue);
					}
					else if (numericValue is float)
					{
						clonedNumericField.SetFloatValue((float)numericValue);
					}
					clonedDocument.Add(clonedNumericField);
				}
				else
				{
					Field clonedField;
					if (field.IsBinary)
					{
						clonedField = new Field(field.Name, field.GetBinaryValue(),
												field.IsStored ? Field.Store.YES : Field.Store.NO);
					}
					else if (field.StringValue != null)
					{
						clonedField = new Field(field.Name, field.StringValue,
												field.IsStored ? Field.Store.YES : Field.Store.NO,
												field.IsIndexed ? Field.Index.ANALYZED_NO_NORMS : Field.Index.NOT_ANALYZED_NO_NORMS,
												field.IsTermVectorStored ? Field.TermVector.YES : Field.TermVector.NO);
					}
					else
					{
						//probably token stream, and we can't handle fields with token streams, so we skip this.
						continue;
					}
					clonedDocument.Add(clonedField);
				}
			}
			return clonedDocument;
		}
		/// <summary>
		/// This method generate the fields for indexing documents in lucene from the values.
		/// Given a name and a value, it has the following behavior:
		/// * If the value is enumerable, index all the items in the enumerable under the same field name
		/// * If the value is null, create a single field with the supplied name with the unanalyzed value 'NULL_VALUE'
		/// * If the value is string or was set to not analyzed, create a single field with the supplied name
		/// * If the value is date, create a single field with millisecond precision with the supplied name
		/// * If the value is numeric (int, long, double, decimal, or float) will create two fields:
		///		1. with the supplied name, containing the numeric value as an unanalyzed string - useful for direct queries
		///		2. with the name: name +'_Range', containing the numeric value in a form that allows range queries
		/// </summary>
		private static IEnumerable<AbstractField> CreateFields(string name, object value, IndexDefinition indexDefinition, Field.Store defaultStorage)
		{
            if(string.IsNullOrWhiteSpace(name))
                throw new ArgumentException("Field must be not null, not empty and cannot contain whitespace", "name");

            if (char.IsLetter(name[0]) == false &&
                name[0] != '_')
            {
                name = "_" + name;
            }

			if (value == null)
			{
				yield return new Field(name, Constants.NullValue, indexDefinition.GetStorage(name, defaultStorage),
								 Field.Index.NOT_ANALYZED);
				yield break;
			}
			if (value is DynamicNullObject)
			{
				if(((DynamicNullObject)value ).IsExplicitNull)
				{
					yield return new Field(name, Constants.NullValue, indexDefinition.GetStorage(name, defaultStorage),
							 Field.Index.NOT_ANALYZED);
				}
				yield break;
			}

            if(value is AbstractField)
            {
                yield return (AbstractField)value;
                yield break;
            }


			var itemsToIndex = value as IEnumerable;
			if( itemsToIndex != null && ShouldTreatAsEnumerable(itemsToIndex))
			{
                yield return new Field(name + "_IsArray", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
                foreach (var itemToIndex in itemsToIndex)
				{
                    foreach (var field in CreateFields(name, itemToIndex, indexDefinition, defaultStorage))
                    {
                        yield return field;
                    }
				}
				yield break;
			}

            if (indexDefinition.GetIndex(name, null) == Field.Index.NOT_ANALYZED)// explicitly not analyzed
            {
                yield return new Field(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
                                 indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
                yield break;
			    
            }
			if (value is string) 
			{
			    var index = indexDefinition.GetIndex(name, Field.Index.ANALYZED);
			    yield return new Field(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
                                 index); 
				yield break;
			}

			if (value is DateTime)
			{
				yield return new Field(name, DateTools.DateToString((DateTime)value, DateTools.Resolution.MILLISECOND),
					indexDefinition.GetStorage(name, defaultStorage),
					indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
			}
            else if(value is bool)
            {
                yield return new Field(name, ((bool) value) ? "true" : "false", indexDefinition.GetStorage(name, defaultStorage),
                              indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));

            }
			else if(value is IConvertible) // we need this to store numbers in invariant format, so JSON could read them
			{
				var convert = ((IConvertible) value);
				yield return new Field(name, convert.ToString(CultureInfo.InvariantCulture), indexDefinition.GetStorage(name, defaultStorage),
				                       indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
			}
			else if (value is DynamicJsonObject)
			{
				var inner = ((DynamicJsonObject)value).Inner;
				yield return new Field(name + "_ConvertToJson", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
				yield return new Field(name, inner.ToString(), indexDefinition.GetStorage(name, defaultStorage),
                                       indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
			}
			else 
			{
				yield return new Field(name + "_ConvertToJson", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
				yield return new Field(name, JToken.FromObject(value).ToString(), indexDefinition.GetStorage(name, defaultStorage),
                                       indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
			}


			var numericField = new NumericField(name + "_Range", indexDefinition.GetStorage(name, defaultStorage), true);
			if (value is int)
			{
				if(indexDefinition.GetSortOption(name) == SortOptions.Long)
					yield return numericField.SetLongValue((int)value);
				else
					yield return numericField.SetIntValue((int)value);
			}
			if (value is long)
			{
				yield return numericField
					.SetLongValue((long) value);

			}
			if (value is decimal)
            {
				yield return numericField
					.SetDoubleValue((double)(decimal)value);
            }
			if (value is float)
            {
				if (indexDefinition.GetSortOption(name) == SortOptions.Double)
					yield return numericField.SetDoubleValue((float)value);
				else
            		yield return numericField.SetFloatValue((float) value);
            }
			if (value is double)
            {
				yield return numericField
					.SetDoubleValue((double)value);
            }
		}
Beispiel #7
0
        private Document CreateDocument(App app) {
            Document doc = new Document();
            Field id = new Field("Id", app.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED);
            Field name = new Field("Name", app.Brief.Name, Field.Store.NO, Field.Index.ANALYZED);
            Field description = new Field("Description", app.Description ?? String.Empty, Field.Store.NO, Field.Index.ANALYZED);
            Field developerName = new Field("DeveloperName", app.Brief.Developer.Name ?? String.Empty, Field.Store.NO, Field.Index.ANALYZED);
            Field category = new Field("Category", String.Join(" ", app.Categories.Select(c => c.Id)), Field.Store.NO, Field.Index.ANALYZED);
            NumericField deviceType = new NumericField("DeviceType", Field.Store.NO, true);
            deviceType.SetIntValue((int)app.Brief.DeviceType);
            NumericField languagePriority = new NumericField("LanguagePriority", Field.Store.NO, true);
            languagePriority.SetIntValue(app.Brief.LanguagePriority);

            doc.Add(id);
            doc.Add(name);
            doc.Add(description);
            doc.Add(developerName);
            doc.Add(category);
            doc.Add(deviceType);
            doc.Add(languagePriority);

            // 排序字段
            Field nameForSort = new Field("NameForSort", app.Brief.Name, Field.Store.NO, Field.Index.NOT_ANALYZED);
            NumericField lastValidUpdateTimee = new NumericField("LastValidUpdateTime", Field.Store.NO, true);
            lastValidUpdateTimee.SetLongValue(app.Brief.LastValidUpdate.Time.Ticks);
            NumericField price = new NumericField("Price", Field.Store.NO, true);
            price.SetFloatValue(app.Brief.Price);
            NumericField ratingCount = new NumericField("Rating", Field.Store.NO, true);
            ratingCount.SetIntValue(app.Brief.AverageUserRatingForCurrentVersion.HasValue ? (int)app.Brief.AverageUserRatingForCurrentVersion : 0);

            doc.Add(nameForSort);
            doc.Add(lastValidUpdateTimee);
            doc.Add(price);
            doc.Add(ratingCount);

            return doc;
        }
Beispiel #8
0
		private static Document CloneDocument(Document luceneDoc)
		{
			var clonedDocument = new Document();
			foreach (AbstractField field in luceneDoc.GetFields())
			{
				var numericField = field as NumericField;
				if (numericField != null)
				{
					var clonedNumericField = new NumericField(numericField.Name(),
															  numericField.IsStored() ? Field.Store.YES : Field.Store.NO,
															  numericField.IsIndexed());
					var numericValue = numericField.GetNumericValue();
					if (numericValue is int)
					{
						clonedNumericField.SetIntValue((int)numericValue);
					}
					if (numericValue is long)
					{
						clonedNumericField.SetLongValue((long)numericValue);
					}
					if (numericValue is double)
					{
						clonedNumericField.SetDoubleValue((double)numericValue);
					}
					if (numericValue is float)
					{
						clonedNumericField.SetFloatValue((float)numericValue);
					}
					clonedDocument.Add(clonedNumericField);
				}
				else
				{
					var clonedField = new Field(field.Name(), field.BinaryValue(),
												field.IsStored() ? Field.Store.YES : Field.Store.NO);
					clonedDocument.Add(clonedField);
				}
			}
			return clonedDocument;
		}
Beispiel #9
0
		private static Document CloneDocument(Document luceneDoc)
		{
			var clonedDocument = new Document();
			foreach (AbstractField field in luceneDoc.GetFields())
			{
				var numericField = field as NumericField;
				if (numericField != null)
				{
					var clonedNumericField = new NumericField(numericField.Name,
															numericField.IsStored ? Field.Store.YES : Field.Store.NO,
															numericField.IsIndexed);
					var numericValue = numericField.NumericValue;
					if (numericValue is int)
					{
						clonedNumericField.SetIntValue((int)numericValue);
					}
					else if (numericValue is long)
					{
						clonedNumericField.SetLongValue((long)numericValue);
					}
					else if (numericValue is double)
					{
						clonedNumericField.SetDoubleValue((double)numericValue);
					}
					else if (numericValue is float)
					{
						clonedNumericField.SetFloatValue((float)numericValue);
					}
					clonedDocument.Add(clonedNumericField);
				}
				else
				{
					Field clonedField;
					if (field.IsBinary)
					{
						clonedField = new Field(field.Name, field.GetBinaryValue(),
												field.IsStored ? Field.Store.YES : Field.Store.NO);
					}
					else
					{
						clonedField = new Field(field.Name, field.StringValue,
										field.IsStored ? Field.Store.YES : Field.Store.NO,
										field.IsIndexed ? Field.Index.ANALYZED_NO_NORMS : Field.Index.NOT_ANALYZED_NO_NORMS);
					}
					clonedDocument.Add(clonedField);
				}
			}
			return clonedDocument;
		}
		/// <summary>
		/// This method generate the fields for indexing documents in lucene from the values.
		/// Given a name and a value, it has the following behavior:
		/// * If the value is null, create a single field with the supplied name with the unanalyzed value 'NULL_VALUE'
		/// * If the value is string or was set to not analyzed, create a single field with the supplied name
		/// * If the value is date, create a single field with millisecond precision with the supplied name
		/// * If the value is numeric (int, long, double, decimal, or float) will create two fields:
		///		1. with the supplied name, containing the numeric value as an unanalyzed string - useful for direct queries
		///		2. with the name: name +'_Range', containing the numeric value in a form that allows range queries
		/// </summary>
		private static IEnumerable<AbstractField> CreateFields(string name, object value, IndexDefinition indexDefinition, Field.Store defaultStorage)
		{
			if (value == null)
			{
				yield return new Field(name, "NULL_VALUE", indexDefinition.GetStorage(name, defaultStorage),
								 Field.Index.NOT_ANALYZED);
				yield break;
			}

			var fields = value as IEnumerable<AbstractField>;
			if(fields != null)
			{
				foreach (var field in fields)
				{
					yield return field;
				}
				yield break;
			}

            if (indexDefinition.GetIndex(name, null) == Field.Index.NOT_ANALYZED)// explicitly not analyzed
            {
                yield return new Field(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
                                 indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
                yield break;
			    
            }
			if (value is string) 
			{
			    var index = indexDefinition.GetIndex(name, Field.Index.ANALYZED);
			    yield return new Field(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
                                 index); 
				yield break;
			}

			if (value is DateTime)
			{
				yield return new Field(name, DateTools.DateToString((DateTime)value, DateTools.Resolution.MILLISECOND),
					indexDefinition.GetStorage(name, defaultStorage),
					indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
			}
            else if(value is bool)
            {
                yield return new Field(name, ((bool) value) ? "true" : "false", indexDefinition.GetStorage(name, defaultStorage),
                              indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));

            }
			else if(value is IConvertible) // we need this to store numbers in invariant format, so JSON could read them
			{
				var convert = ((IConvertible) value);
				yield return new Field(name, convert.ToString(CultureInfo.InvariantCulture), indexDefinition.GetStorage(name, defaultStorage),
				                       indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
			}
			else if (value is DynamicJsonObject)
			{
				var inner = ((DynamicJsonObject)value).Inner;
				yield return new Field(name + "_ConvertToJson", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
				yield return new Field(name, inner.ToString(), indexDefinition.GetStorage(name, defaultStorage),
                                       indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
			}
			else 
			{
				yield return new Field(name + "_ConvertToJson", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
				yield return new Field(name, JToken.FromObject(value).ToString(), indexDefinition.GetStorage(name, defaultStorage),
                                       indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
			}


			var numericField = new NumericField(name + "_Range", indexDefinition.GetStorage(name, defaultStorage), true);
			if (value is int)
			{
				if(indexDefinition.GetSortOption(name) == SortOptions.Long)
					yield return numericField.SetLongValue((int)value);
				else
					yield return numericField.SetIntValue((int)value);
			}
			if (value is long)
			{
				yield return numericField
					.SetLongValue((long) value);

			}
			if (value is decimal)
            {
				yield return numericField
					.SetDoubleValue((double)(decimal)value);
            }
			if (value is float)
            {
				if (indexDefinition.GetSortOption(name) == SortOptions.Double)
					yield return numericField.SetDoubleValue((float)value);
				else
            		yield return numericField.SetFloatValue((float) value);
            }
			if (value is double)
            {
				yield return numericField
					.SetDoubleValue((double)value);
            }
		}
        private void AddFakeDocument(int fromNodeId)
        {
            //minimal fakeobject: NodeId, VersionId, Path, Version, NodeTimestamp, VersionTimestamp

            var node = Node.LoadNode(fromNodeId);
            var doc = IndexDocumentInfo.CreateDocument(node);
            doc.RemoveField(LucObject.FieldName.NodeId);
            doc.RemoveField(LucObject.FieldName.VersionId);
            doc.RemoveField(LucObject.FieldName.Name);
            doc.RemoveField(LucObject.FieldName.Path);

            var nf = new NumericField(LucObject.FieldName.NodeId, LucField.Store.YES, true);
            nf.SetIntValue(99999);
            doc.Add(nf);
            nf = new NumericField(LucObject.FieldName.VersionId, LucField.Store.YES, true);
            nf.SetIntValue(99999);
            doc.Add(nf);
            doc.Add(new LucField(LucObject.FieldName.Name, "fakedocument", LucField.Store.YES, LucField.Index.NOT_ANALYZED, LucField.TermVector.NO));
            doc.Add(new LucField(LucObject.FieldName.Path, "/root/fakedocument", LucField.Store.YES, LucField.Index.NOT_ANALYZED, LucField.TermVector.NO));

            LuceneManager.AddCompleteDocument(doc);
            LuceneManager.ApplyChanges();
        }
 public override void SetUp()
 {
     base.SetUp();
     ramDir = new RAMDirectory();
     IndexWriter writer = new IndexWriter(ramDir, new StandardAnalyzer(TEST_VERSION), true,
                                          IndexWriter.MaxFieldLength.UNLIMITED);
     for (int i = 0; i < texts.Length; i++)
     {
         AddDoc(writer, texts[i]);
     }
     Document doc = new Document();
     NumericField nfield = new NumericField(NUMERIC_FIELD_NAME, Field.Store.YES, true);
     nfield.SetIntValue(1);
     doc.Add(nfield);
     writer.AddDocument(doc, analyzer);
     nfield = new NumericField(NUMERIC_FIELD_NAME, Field.Store.YES, true);
     nfield.SetIntValue(3);
     doc = new Document();
     doc.Add(nfield);
     writer.AddDocument(doc, analyzer);
     nfield = new NumericField(NUMERIC_FIELD_NAME, Field.Store.YES, true);
     nfield.SetIntValue(5);
     doc = new Document();
     doc.Add(nfield);
     writer.AddDocument(doc, analyzer);
     nfield = new NumericField(NUMERIC_FIELD_NAME, Field.Store.YES, true);
     nfield.SetIntValue(7);
     doc = new Document();
     doc.Add(nfield);
     writer.AddDocument(doc, analyzer);
     writer.Optimize();
     writer.Close();
     reader = IndexReader.Open(ramDir, true);
     numHighlights = 0;
 }
Beispiel #13
0
 private static AbstractField CreateField(IndexFieldInfo fieldInfo)
 {
     NumericField nf;
     switch (fieldInfo.Type)
     {
         case FieldInfoType.StringField:
             return new Field(fieldInfo.Name, fieldInfo.Value, fieldInfo.Store, fieldInfo.Index, fieldInfo.TermVector);
         case FieldInfoType.IntField:
             nf = new NumericField(fieldInfo.Name, fieldInfo.Store, fieldInfo.Index != Field.Index.NO);
             nf.SetIntValue(Int32.Parse(fieldInfo.Value, CultureInfo.InvariantCulture));
             return nf;
         case FieldInfoType.LongField:
             nf = new NumericField(fieldInfo.Name, 8, fieldInfo.Store, fieldInfo.Index != Field.Index.NO);
             nf.SetLongValue(Int64.Parse(fieldInfo.Value, CultureInfo.InvariantCulture));
             return nf;
         case FieldInfoType.SingleField:
             nf = new NumericField(fieldInfo.Name, fieldInfo.Store, fieldInfo.Index != Field.Index.NO);
             nf.SetFloatValue(Single.Parse(fieldInfo.Value, CultureInfo.InvariantCulture));
             return nf;
         case FieldInfoType.DoubleField:
             nf = new NumericField(fieldInfo.Name, 8, fieldInfo.Store, fieldInfo.Index != Field.Index.NO);
             nf.SetDoubleValue(Double.Parse(fieldInfo.Value, CultureInfo.InvariantCulture));
             return nf;
         default:
             throw new NotImplementedException("IndexFieldInfo." + fieldInfo.Type);
     }
 }
Beispiel #14
0
        internal static Document CreateDocument(IndexDocumentInfo info, IndexDocumentData docData)
        {
            var doc = new Document();
            foreach (var fieldInfo in info.fields)
                doc.Add(CreateField(fieldInfo));

            var path = docData.Path.ToLower();

            //doc.Add(new Field(LucObject.FieldName.Name, RepositoryPath.GetFileName(path), Field.Store.YES, Field.Index.ANALYZED));
            //doc.Add(new Field(LucObject.FieldName.Path, path, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));

            doc.Add(CreateStringField(LucObject.FieldName.Name, RepositoryPath.GetFileName(path), NameFieldIndexingInfo));
            doc.Add(CreateStringField(LucObject.FieldName.Path, path, NameFieldIndexingInfo));

            //LucObject.FieldName.Depth
            var nf = new NumericField(LucObject.FieldName.Depth, Field.Store.YES, true);
            nf.SetIntValue(DepthIndexHandler.GetDepth(docData.Path));
            doc.Add(nf);

            //LucObject.FieldName.InTree
            //var fields = InTreeIndexHandlerInstance.GetIndexFields(LucObject.FieldName.InTree, docData.Path);
            var fields = CreateInTreeFields(LucObject.FieldName.InTree, docData.Path);
            foreach (var field in fields)
                doc.Add(field);

            //LucObject.FieldName.InFolder
            doc.Add(CreateInFolderField(LucObject.FieldName.InFolder, path));

            //LucObject.FieldName.ParentId
            nf = new NumericField(LucObject.FieldName.ParentId, Field.Store.NO, true);
            nf.SetIntValue(docData.ParentId);
            doc.Add(nf);

            // flags
            doc.Add(new Field(LucObject.FieldName.IsLastPublic, docData.IsLastPublic ? BooleanIndexHandler.YES : BooleanIndexHandler.NO, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO));
            doc.Add(new Field(LucObject.FieldName.IsLastDraft, docData.IsLastDraft ? BooleanIndexHandler.YES : BooleanIndexHandler.NO, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO));

            // timestamps
            nf = new NumericField(LucObject.FieldName.NodeTimestamp, Field.Store.YES, true);
            nf.SetLongValue(docData.NodeTimestamp);
            doc.Add(nf);
            nf = new NumericField(LucObject.FieldName.VersionTimestamp, Field.Store.YES, true);
            nf.SetLongValue(docData.VersionTimestamp);
            doc.Add(nf);

            // custom fields
            if (info.HasCustomField)
            {
                var customFields = CustomIndexFieldManager.GetFields(info, docData);
                if (customFields != null)
                    foreach (var field in customFields)
                        doc.Add(field);
            }

            return doc;
        }
Beispiel #15
0
        private static AbstractField CreateNumericField(FieldMapping mapping, ValueType value, string fieldName)
        {
            NumericField numField = new NumericField(
                    fieldName, DefaultPrecisionStep,
                    mapping.Store, mapping.Index != Field.Index.NO);

            if (value is int)
                numField.SetIntValue((int)value);
            else if (value is long)
                numField.SetLongValue((long)value);
            else if (value is float)
                numField.SetFloatValue((float)value);
            else if (value is double)
                numField.SetDoubleValue((double)value);
            else if (value is decimal)
                numField.SetDoubleValue((double)(decimal)value);
            else if (value is DateTime)
                numField.SetLongValue(((DateTime)value).ToBinary());
            else
                throw new Exception(String.Format(Properties.Resources.EXC_TYPE_NOT_SUPPORTED, value));

            return numField;
        }
        protected override Document CreateDocument(string fileName, string dataRootDirectory)
        {
            Console.WriteLine("CreateDocument: {0}", fileName);

            var pbp = new BookPropsParsed(fileName, dataRootDirectory);

            var doc = new Document();

            doc.Add(new Field("isbn", pbp.ISBN, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("category", pbp.Category, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("title", pbp.Title, Field.Store.YES, Field.Index.ANALYZED,
                Field.TermVector.WITH_POSITIONS_OFFSETS));
            doc.Add(new Field("title2", pbp.LowerdTitle, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS,
                Field.TermVector.WITH_POSITIONS_OFFSETS));

            foreach (string author in pbp.Authors)
            {
                doc.Add(new Field("author", author, Field.Store.YES, Field.Index.NOT_ANALYZED,
                    Field.TermVector.WITH_POSITIONS_OFFSETS));
            }

            doc.Add(new Field("url", pbp.Url, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
            doc.Add(new Field("subject", pbp.Subject, Field.Store.YES, Field.Index.ANALYZED,
                Field.TermVector.WITH_POSITIONS_OFFSETS));
            if (pbp.PubMonthInt != null)
            {
                var pubMonthAsIntNumericField = new NumericField("pubmonth", Field.Store.YES, true);
                pubMonthAsIntNumericField.SetIntValue((int) pbp.PubMonthInt);
                doc.Add(pubMonthAsIntNumericField);
                if (pbp.PubMonthAsDay != null)
                {
                    var pubMonthAsDayNumericField = new NumericField("pubmonthAsDay", Field.Store.YES, true);
                    pubMonthAsDayNumericField.SetIntValue((int) pbp.PubMonthAsDay);
                    doc.Add(pubMonthAsDayNumericField);
                }
            }

            foreach (string text in pbp.Content)
            {
                doc.Add(new Field("contents", text, Field.Store.NO, Field.Index.ANALYZED,
                    Field.TermVector.WITH_POSITIONS_OFFSETS));
            }
            return doc;
        }