Ejemplo n.º 1
0
        private void EnsureDocument()
        {
            if (document == null)
            {
                document = new Document();
                var fields = DocumentBuilder.GetFields(TypeName);
                foreach (var f in fields)
                {
                    AbstractField af = null;
                    switch (f.FieldType)
                    {
                    case FieldType.Int:
                    case FieldType.Float:
                    case FieldType.Long:
                    case FieldType.Double:
                        af = new LN.Documents.NumericField(f.FieldName, (LN.Documents.Field.Store)((int)f.StoreMode), (int)f.IndexMode > 0);
                        break;

                    case FieldType.String:
                    case FieldType.DateTime:
                    default:
                        af = new LN.Documents.Field(f.FieldName, string.Empty, (LN.Documents.Field.Store)((int)f.StoreMode), (LN.Documents.Field.Index)((int)f.IndexMode));
                        break;
                    }
                    af.Boost = f.Boost;
                    document.Add(af);
                }
            }
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
		public override AbstractField[] CreateIndexableFields(Shape shape)
		{
			var point = shape as Point;
			if (point != null)
			{
				var f = new AbstractField[2];

				var f0 = new NumericField(fieldNameX, precisionStep, Field.Store.NO, true)
				         	{OmitNorms = true, OmitTermFreqAndPositions = true};
				f0.SetDoubleValue(point.GetX());
				f[0] = f0;

				var f1 = new NumericField(fieldNameY, precisionStep, Field.Store.NO, true)
				         	{OmitNorms = true, OmitTermFreqAndPositions = true};
				f1.SetDoubleValue(point.GetY());
				f[1] = f1;

				return f;
			}
			if (!ignoreIncompatibleGeometry)
			{
				throw new ArgumentException("TwoDoublesStrategy can not index: " + shape);
			}
			return new AbstractField[0]; // nothing (solr does not support null) 
		}
 private static void AddNumericPublishedDate(Document document, DateTime publishedDate)
 {
     var publishedDateString = publishedDate.ToString("yyyyMMddhhmmss");
     var publishedDateNumeric = new NumericField(PublishedDateNumericField, Field.Store.YES, true);
     publishedDateNumeric.SetLongValue(long.Parse(publishedDateString));
     document.Add(publishedDateNumeric);
 }
Ejemplo n.º 5
0
        private static NumericField GetNumericField(string fieldName, PerFieldIndexingInfo indexingInfo)
        {
            // Do not reusing any fields.
            var index    = indexingInfo.IndexingMode ?? PerFieldIndexingInfo.DefaultIndexingMode;
            var store    = indexingInfo.IndexStoringMode ?? PerFieldIndexingInfo.DefaultIndexStoringMode;
            var lucField = new Lucene.Net.Documents.NumericField(fieldName, store, index != Lucene.Net.Documents.Field.Index.NO);

            return(lucField);
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
        public static AbstractField CreateField(string name, string type, SearchType searchType, object value) {
            var s = searchType.Store ? global::Lucene.Net.Documents.Field.Store.YES : global::Lucene.Net.Documents.Field.Store.NO;
            AbstractField abstractField;
            switch (type) {
                case "byte":
                    abstractField = new NumericField(name, s, searchType.Index).SetIntValue(Convert.ToInt32(value));
                    break;
                case "int16":
                    abstractField = new NumericField(name, s, searchType.Index).SetIntValue(Convert.ToInt32(value));
                    break;
                case "int":
                    abstractField = new NumericField(name, s, searchType.Index).SetIntValue((int)value);
                    break;
                case "int32":
                    abstractField = new NumericField(name, s, searchType.Index).SetIntValue((int)value);
                    break;
                case "int64":
                    abstractField = new NumericField(name, s, searchType.Index).SetLongValue((long)value);
                    break;
                case "long":
                    abstractField = new NumericField(name, s, searchType.Index).SetLongValue((long)value);
                    break;
                case "double":
                    abstractField = new NumericField(name, s, searchType.Index).SetDoubleValue((double)value);
                    break;
                case "float":
                    abstractField = new NumericField(name, s, searchType.Index).SetFloatValue((float)value);
                    break;
                case "datetime":
                    abstractField = new NumericField(name, s, searchType.Index).SetLongValue(((DateTime)value).Ticks);
                    break;
                case "byte[]":
                    abstractField = searchType.Index ?
                        new global::Lucene.Net.Documents.Field(name, Common.BytesToHexString((byte[])value), s, global::Lucene.Net.Documents.Field.Index.NOT_ANALYZED_NO_NORMS) :
                        new global::Lucene.Net.Documents.Field(name, (byte[])value, global::Lucene.Net.Documents.Field.Store.YES);
                    break;
                case "rowversion":
                    abstractField = searchType.Index ?
                        new global::Lucene.Net.Documents.Field(name, Common.BytesToHexString((byte[])value), s, global::Lucene.Net.Documents.Field.Index.NOT_ANALYZED_NO_NORMS) :
                        new global::Lucene.Net.Documents.Field(name, (byte[])value, global::Lucene.Net.Documents.Field.Store.YES);
                    break;
                case "string":
                    var iString = searchType.Index ? (
                            searchType.Analyzer.Equals("keyword") ?
                            (searchType.Norms ? global::Lucene.Net.Documents.Field.Index.NOT_ANALYZED : global::Lucene.Net.Documents.Field.Index.NOT_ANALYZED_NO_NORMS) :
                            (searchType.Norms ? global::Lucene.Net.Documents.Field.Index.ANALYZED : global::Lucene.Net.Documents.Field.Index.ANALYZED_NO_NORMS)
                         ) :
                            global::Lucene.Net.Documents.Field.Index.NO;
                    abstractField = new global::Lucene.Net.Documents.Field(name, value.ToString(), s, iString);
                    break;
                default:
                    var i = searchType.Index ?
                        (searchType.Norms ? global::Lucene.Net.Documents.Field.Index.NOT_ANALYZED : global::Lucene.Net.Documents.Field.Index.NOT_ANALYZED_NO_NORMS) :
                        global::Lucene.Net.Documents.Field.Index.NO;
                    abstractField = new global::Lucene.Net.Documents.Field(name, value.ToString(), s, i);
                    break;

            }
            return abstractField;

        }
Ejemplo n.º 10
0
            public LogEntryToDocumentConverter()
            {
                document = new Document();

                machineField = new Field(MachineFieldName, string.Empty, Field.Store.YES, Field.Index.ANALYZED);
                sourceField = new Field(SourceFieldName, string.Empty, Field.Store.YES, Field.Index.ANALYZED);
                sourceIdField = new NumericField(SourceIdFieldName, Field.Store.YES, false);
                idField = new NumericField(IdFieldName, Field.Store.YES, true);
                typeField = new Field(TypeFiledName, string.Empty, Field.Store.YES, Field.Index.ANALYZED);
                messageField = new Field(MessageFieldName, string.Empty, Field.Store.YES, Field.Index.ANALYZED);
                timeField = new NumericField(TimeFiledName, Field.Store.YES, true);

                document.Add(idField);
                document.Add(machineField);
                document.Add(sourceField);
                document.Add(typeField);
                document.Add(messageField);
                document.Add(timeField);
                document.Add(sourceIdField);
            }
		/// <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);
            }
		}
Ejemplo n.º 12
0
 private static Document AddNumericField(Document document, NumericField field)
 {
     document.Add(field);
     return document;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="id"></param>
        /// <param name="metadataDoc"></param>
        /// <return></return>
        private void writeBexisIndex(long id, XmlDocument metadataDoc)
        {
            String docId = id.ToString();//metadataDoc.GetElementsByTagName("bgc:id")[0].InnerText;

            var dataset = new Document();
            List<XmlNode> facetNodes = facetXmlNodeList;
            dataset.Add(new Field("doc_id", docId, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NOT_ANALYZED));

            foreach (XmlNode facet in facetNodes)
            {
                String multivalued = facet.Attributes.GetNamedItem("multivalued").Value;
                string[] metadataElementNames = facet.Attributes.GetNamedItem("metadata_name").Value.Split(',');
                String lucene_name = facet.Attributes.GetNamedItem("lucene_name").Value;

                foreach (string metadataElementName in metadataElementNames)
                {
                    XmlNodeList elemList = metadataDoc.SelectNodes(metadataElementName);
                    if (elemList != null)
                    {
                        for (int i = 0; i < elemList.Count; i++)
                        {
                            string eleme = elemList[i].InnerText;
                            if (!elemList[i].InnerText.Trim().Equals(""))
                            {
                                dataset.Add(new Field("facet_" + lucene_name, elemList[i].InnerText,
                                    Lucene.Net.Documents.Field.Store.YES, Field.Index.NOT_ANALYZED));
                                dataset.Add(new Field("ng_all", elemList[i].InnerText,
                                    Lucene.Net.Documents.Field.Store.YES, Field.Index.ANALYZED));
                                writeAutoCompleteIndex(docId, lucene_name, elemList[i].InnerText);
                                writeAutoCompleteIndex(docId, "ng_all", elemList[i].InnerText);
                            }
                        }
                    }
                }
            }

            List<XmlNode> propertyNodes = propertyXmlNodeList;
            foreach (XmlNode property in propertyNodes)
            {
                String multivalued = property.Attributes.GetNamedItem("multivalued").Value;
                String lucene_name = property.Attributes.GetNamedItem("lucene_name").Value;
                string[] metadataElementNames = property.Attributes.GetNamedItem("metadata_name").Value.Split(',');

                foreach (string metadataElementName in metadataElementNames)
                {
                    XmlNodeList elemList = metadataDoc.SelectNodes(metadataElementName);
                    if (elemList != null)
                    {
                        String primitiveType = property.Attributes.GetNamedItem("primitive_type").Value;
                        if (elemList[0] != null)
                        {
                            if (primitiveType.ToLower().Equals("string"))
                            {
                                dataset.Add(new Field("property_" + lucene_name, elemList[0].InnerText,
                                    Lucene.Net.Documents.Field.Store.YES, Field.Index.NOT_ANALYZED));
                                dataset.Add(new Field("ng_all", elemList[0].InnerText,
                                    Lucene.Net.Documents.Field.Store.YES, Field.Index.ANALYZED));
                                writeAutoCompleteIndex(docId, lucene_name, elemList[0].InnerText);
                                writeAutoCompleteIndex(docId, "ng_all", elemList[0].InnerText);
                            }
                            else if (primitiveType.ToLower().Equals("date"))
                            {
                                //DateTime MyDateTime = DateTime.Now;
                                DateTime MyDateTime = new DateTime();
                                /*String dTFormatElementName = property.Attributes.GetNamedItem("date_format").Value;
                            XmlNodeList dtFormatElements = metadataDoc.GetElementsByTagName(dTFormatElementName);
                            String dateTimeFormat = dtFormatElements[0].InnerText;*/

                                if (DateTime.TryParse(elemList[0].InnerText, out MyDateTime))
                                {
                                    //MyDateTime = DateTime.ParseExact(elemList[0].InnerText, dateTimeFormat,
                                    //            CultureInfo.InvariantCulture);
                                    long t = MyDateTime.Ticks;

                                    NumericField xyz =
                                        new NumericField("property_numeric_" + lucene_name).SetLongValue(
                                            MyDateTime.Ticks);
                                    String dateToString = MyDateTime.Date.ToString("d",
                                        CultureInfo.CreateSpecificCulture("en-US"));
                                    dataset.Add(xyz);
                                    dataset.Add(new Field("property_" + lucene_name, dateToString,
                                        Lucene.Net.Documents.Field.Store.NO, Field.Index.NOT_ANALYZED));

                                    writeAutoCompleteIndex(docId, lucene_name, MyDateTime.Date.ToString());
                                    writeAutoCompleteIndex(docId, "ng_all", MyDateTime.Date.ToString());
                                }
                            }
                            else if (primitiveType.ToLower().Equals("integer"))
                            {
                                dataset.Add(
                                    new NumericField("property_numeric" + lucene_name).SetIntValue(
                                        Convert.ToInt32(elemList[0].InnerText)));
                                dataset.Add(new Field("property_" + lucene_name, elemList[0].InnerText,
                                    Lucene.Net.Documents.Field.Store.NO, Field.Index.NOT_ANALYZED));
                                //  writeAutoCompleteIndex(lucene_name, elemList[0].InnerText);
                            }
                            else if (primitiveType.ToLower().Equals("double"))
                            {
                                dataset.Add(
                                    new NumericField("property_numeric" + lucene_name).SetDoubleValue(
                                        Convert.ToDouble(elemList[0].InnerText)));
                                dataset.Add(new Field("property_" + lucene_name, elemList[0].InnerText,
                                    Lucene.Net.Documents.Field.Store.NO, Field.Index.NOT_ANALYZED));
                                writeAutoCompleteIndex(docId, lucene_name, elemList[0].InnerText);
                                writeAutoCompleteIndex(docId, "ng_all", elemList[0].InnerText);
                            }
                        }
                    }
                }
            }
            List<XmlNode> categoryNodes = categoryXmlNodeList;
            foreach (XmlNode category in categoryNodes)
            {
                if (category.Attributes.GetNamedItem("type").Value.Equals("primary_data_field"))
                {
                    String primitiveType = category.Attributes.GetNamedItem("primitive_type").Value;
                    String lucene_name = category.Attributes.GetNamedItem("lucene_name").Value;
                    String analysing = category.Attributes.GetNamedItem("analysed").Value;
                    float boosting = Convert.ToSingle(category.Attributes.GetNamedItem("boost").Value);
                    var toAnalyse = Lucene.Net.Documents.Field.Index.NOT_ANALYZED;
                    if (analysing.ToLower().Equals("yes"))
                    {
                        toAnalyse = Lucene.Net.Documents.Field.Index.ANALYZED;
                    }

                    DatasetManager dm = new DatasetManager();
                    if (dm.IsDatasetCheckedIn(id))
                    {
                        DatasetVersion dsv = dm.GetDatasetLatestVersion(id);
                        DataStructureManager dsm = new DataStructureManager();
                        StructuredDataStructure sds = dsm.StructuredDataStructureRepo.Get(dsv.Dataset.DataStructure.Id);
                        // Javad: check if the dataset is "checked-in". If yes, then use the paging version of the GetDatasetVersionEffectiveTuples method
                        // number of tuples for the for loop is also available via GetDatasetVersionEffectiveTupleCount
                        // a proper fetch (page) size can be obtained by calling dm.PreferedBatchSize
                        int fetchSize = dm.PreferedBatchSize;
                        long tupleSize = dm.GetDatasetVersionEffectiveTupleCount(dsv);
                        long noOfFetchs = tupleSize/fetchSize + 1;
                        for (int round = 0; round < noOfFetchs; round++)
                        {
                            List<AbstractTuple> dsVersionTuples = dm.GetDatasetVersionEffectiveTuples(dsv, round,
                                fetchSize);
                            List<string> primaryDataStringToindex = generateStringFromTuples(dsVersionTuples, sds);
                            if (primaryDataStringToindex != null)
                            {
                                foreach (string pDataValue in primaryDataStringToindex)
                                    // Loop through List with foreach
                                {
                                    Field a = new Field("category_" + lucene_name, pDataValue,
                                        Lucene.Net.Documents.Field.Store.NO, toAnalyse);
                                    a.Boost = boosting;
                                    dataset.Add(a);
                                    dataset.Add(new Field("ng_" + lucene_name, pDataValue,
                                        Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED));
                                    dataset.Add(new Field("ng_all", pDataValue, Lucene.Net.Documents.Field.Store.YES,
                                        Lucene.Net.Documents.Field.Index.ANALYZED));
                                    writeAutoCompleteIndex(docId, lucene_name, pDataValue);
                                    writeAutoCompleteIndex(docId, "ng_all", pDataValue);
                                }
                            }
                            GC.Collect();
                        }
                    }
                }
                else
                {
                    String multivalued = category.Attributes.GetNamedItem("multivalued").Value;
                    String primitiveType = category.Attributes.GetNamedItem("primitive_type").Value;
                    String lucene_name = category.Attributes.GetNamedItem("lucene_name").Value;
                    String storing = category.Attributes.GetNamedItem("store").Value;
                    String analysing = category.Attributes.GetNamedItem("analysed").Value;
                    float boosting = Convert.ToSingle(category.Attributes.GetNamedItem("boost").Value);
                    var toStore = Lucene.Net.Documents.Field.Store.NO;
                    var toAnalyse = Lucene.Net.Documents.Field.Index.NOT_ANALYZED;

                    if (storing.ToLower().Equals("yes"))
                    {
                        toStore = Lucene.Net.Documents.Field.Store.YES;
                    }
                    if (analysing.ToLower().Equals("yes"))
                    {
                        toAnalyse = Lucene.Net.Documents.Field.Index.ANALYZED;
                    }

                    string[] metadataElementNames = category.Attributes.GetNamedItem("metadata_name").Value.Split(',');

                    foreach (string metadataElementName in metadataElementNames)
                    {
                        XmlNodeList elemList = metadataDoc.SelectNodes(metadataElementName);
                        if (elemList != null)
                        {
                            for (int i = 0; i < elemList.Count; i++)
                            {
                                Field a = new Field("category_" + lucene_name, elemList[i].InnerText, toStore, toAnalyse);
                                a.Boost = boosting;
                                dataset.Add(a);
                                dataset.Add(new Field("ng_" + lucene_name, elemList[i].InnerText,
                                    Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED));
                                dataset.Add(new Field("ng_all", elemList[i].InnerText,
                                    Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED));
                                writeAutoCompleteIndex(docId, lucene_name, elemList[i].InnerText);
                                writeAutoCompleteIndex(docId, "ng_all", elemList[i].InnerText);
                            }
                        }
                    }

                }
            }

            List<XmlNode> generalNodes = generalXmlNodeList;

            foreach (XmlNode general in generalNodes)
            {

                String multivalued = general.Attributes.GetNamedItem("multivalued").Value;
                String primitiveType = general.Attributes.GetNamedItem("primitive_type").Value;
                String lucene_name = general.Attributes.GetNamedItem("lucene_name").Value;

                String storing = general.Attributes.GetNamedItem("store").Value;
                String analysing = general.Attributes.GetNamedItem("analysed").Value;

                var toStore = Lucene.Net.Documents.Field.Store.NO;
                var toAnalyse = Lucene.Net.Documents.Field.Index.NOT_ANALYZED;

                if (storing.ToLower().Equals("yes"))
                {
                    toStore = Lucene.Net.Documents.Field.Store.YES;
                }
                if (analysing.ToLower().Equals("yes"))
                {
                    toAnalyse = Lucene.Net.Documents.Field.Index.ANALYZED;
                }
                float boosting = Convert.ToSingle(general.Attributes.GetNamedItem("boost").Value);

                string[] metadataElementNames = general.Attributes.GetNamedItem("metadata_name").Value.Split(',');

                foreach (string metadataElementName in metadataElementNames)
                {

                    XmlNodeList elemList = metadataDoc.SelectNodes(metadataElementName);
                    for (int i = 0; i < elemList.Count; i++)
                    {
                        Field a = new Field(lucene_name, elemList[i].InnerText, toStore, toAnalyse);
                        a.Boost = boosting;
                        dataset.Add(a);
                        dataset.Add(new Field("ng_all", elemList[i].InnerText, Lucene.Net.Documents.Field.Store.NO, Field.Index.ANALYZED));
                        writeAutoCompleteIndex(docId, lucene_name, elemList[i].InnerText);
                        writeAutoCompleteIndex(docId, "ng_all", elemList[i].InnerText);
                    }
                }

            }

            indexWriter.AddDocument(dataset);
        }
Ejemplo n.º 14
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;
		}
Ejemplo n.º 15
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;
		}
Ejemplo n.º 16
0
 private void EnsureDocument()
 {
     if (document == null)
     {
         document = new Document();
         var fields = DocumentBuilder.GetFields(TypeName);
         foreach (var f in fields)
         {
             AbstractField af = null;
             switch (f.FieldType)
             {
                 case FieldType.Int:
                 case FieldType.Float:
                 case FieldType.Long:
                 case FieldType.Double:
                     af = new LN.Documents.NumericField(f.FieldName, (LN.Documents.Field.Store)((int)f.StoreMode), (int)f.IndexMode > 0);
                     break;
                 case FieldType.String:
                 case FieldType.DateTime:
                 default:
                     af = new LN.Documents.Field(f.FieldName, string.Empty, (LN.Documents.Field.Store)((int)f.StoreMode), (LN.Documents.Field.Index)((int)f.IndexMode));
                     break;
             }
             af.Boost = f.Boost;
             document.Add(af);
         }
     }
 }
Ejemplo n.º 17
0
 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;
 }
        /// <summary>
        /// Given the string versions, this will put them into the index as numerical versions, this way we can compare/range query, etc... on versions
        /// </summary>
        /// <param name="e"></param>
        /// <param name="fieldName"></param>
        /// <param name="versions"></param>
        /// <remarks>
        /// This stores a numerical version as a Right padded 3 digit combined long number. Example:
        /// 7.5.0 would be:
        ///     007005000 = 7005000
        /// 4.11.0 would be:
        ///     004011000 = 4011000
        /// </remarks>
        private static void AddNumericalVersionValue(DocumentWritingEventArgs e, string fieldName, IEnumerable<string> versions)
        {
            var numericalVersions = versions.Select(x =>
                {
                    System.Version o;
                    return System.Version.TryParse(x, out o) ? o : null;
                })
                .Where(x => x != null)
                .Select(x => x.GetNumericalValue())
                .ToArray();

            foreach (var numericalVersion in numericalVersions)
            {
                //don't store, we're just using this to search
                var versionField = new NumericField(fieldName, Field.Store.NO, true).SetLongValue(numericalVersion);
                e.Document.Add(versionField);
            }
        }
Ejemplo n.º 19
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);
     }
 }
Ejemplo n.º 20
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;
        }
Ejemplo n.º 21
0
        public Document ToDocument()
        {
            var doc = new Document();

            doc.Add(new Field("Id", Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Text", Text, Field.Store.YES, Field.Index.ANALYZED));

            var timestamp = new NumericField("Timestamp", Field.Store.YES, true);
            timestamp.SetLongValue(Timestamp.Ticks);
            doc.Add(timestamp);

            doc.Add(new Field("SourceHost", SourceHost, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("SourceFile", SourceFile, Field.Store.YES, Field.Index.NOT_ANALYZED));

            return doc;
        }
Ejemplo n.º 22
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;
        }
		/// <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);
            }
		}
Ejemplo n.º 24
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;
		}
Ejemplo n.º 25
0
 private void InitializeDocumentCache()
 {
     fLogID = new NumericField(FieldKeys.LogID, 8, Field.Store.YES, true);
     fLogName = new Field(FieldKeys.LogName, string.Empty, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
     fSvc = new Field(FieldKeys.Service, string.Empty, Field.Store.NO, Field.Index.ANALYZED_NO_NORMS);
     fMethod = new Field(FieldKeys.Method, string.Empty, Field.Store.NO, Field.Index.ANALYZED_NO_NORMS);
     fClientIP = new Field(FieldKeys.ClientIP, string.Empty, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS);
     fServerIP = new Field(FieldKeys.ServerIP, string.Empty, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS);
     fException = new NumericField(FieldKeys.Exception, 1, Field.Store.NO, true);
     fCreated = new NumericField(FieldKeys.CreatedDT, 8, Field.Store.NO, true);
     fElapsed = new NumericField(FieldKeys.Elapsed, 8, Field.Store.NO, true);
     fDetail_Desc = new Field(FieldKeys.Detail_Desc, string.Empty, Field.Store.NO, Field.Index.ANALYZED_NO_NORMS);
     fDetail_Parm = new Field(FieldKeys.Detail_Parm, string.Empty, Field.Store.NO, Field.Index.ANALYZED_NO_NORMS);
     fDetail_Elapsed = new NumericField(FieldKeys.Detail_Elapsed, 8, Field.Store.NO, true);
 }
Ejemplo n.º 26
0
        protected void AddNumericField(string name, long value) {
            NumericField numericField = new NumericField(name, 4, Field.Store.YES, true);
            numericField.SetLongValue(value);

            _document.Add(numericField);
        }
Ejemplo n.º 27
0
 private AbstractField DoubleField(string field, double value)
 {
     var f = new NumericField(field, precisionStep, Field.Store.NO, true)
                 {OmitNorms = true, OmitTermFreqAndPositions = true};
     f.SetDoubleValue(value);
     return f;
 }
Ejemplo n.º 28
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;
        }
Ejemplo n.º 29
0
        public AbstractField[] CreateIndexableFields(Point point)
        {
                var f = new AbstractField[2];

                var f0 = new NumericField(fieldNameX, precisionStep, Field.Store.NO, true)
                             {OmitNorms = true, OmitTermFreqAndPositions = true};
                f0.SetDoubleValue(point.GetX());
                f[0] = f0;

                var f1 = new NumericField(fieldNameY, precisionStep, Field.Store.NO, true)
                             {OmitNorms = true, OmitTermFreqAndPositions = true};
                f1.SetDoubleValue(point.GetY());
                f[1] = f1;

                return f;
        }
		private IEnumerable<AbstractField> CreateNumericFieldWithCaching(string name, object value,
			Field.Store defaultStorage)
		{

			var fieldName = name + "_Range";
			var storage = indexDefinition.GetStorage(name, defaultStorage);
			var cacheKey = new FieldCacheKey(name, null, storage, multipleItemsSameFieldCount.ToArray());
			NumericField numericField;
			if (numericFieldsCache.TryGetValue(cacheKey, out numericField) == false)
			{
				numericFieldsCache[cacheKey] = numericField = new NumericField(fieldName, storage, 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);
			}
		}
Ejemplo n.º 31
0
        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();
        }
Ejemplo n.º 32
0
        private void AddDocumentTimeStampField()
        {
            var numField = new NumericField(TimeStampFieldName, Field.Store.YES, true);
            numField.SetLongValue(_searchableObject.Timestamp.ToFileTime());

            _document.Add(numField);
        }
Ejemplo n.º 33
0
        public static Lucene.Net.Documents.Document ConvertToLuceneDocument(DocumentDto document)
        {
            //Convert WCF document to Lucene document
            var luceneDocument = new Lucene.Net.Documents.Document();

            foreach (var field in document.Fields)
            {
                Lucene.Net.Documents.Field.Index indexType;
                switch (field.Index)
                {
                case FieldIndexType.NotIndexed:
                    indexType = Field.Index.NO;
                    break;

                case FieldIndexType.Analyzed:
                    indexType = Field.Index.ANALYZED;
                    break;

                case FieldIndexType.AnalyzedNoNorms:
                    indexType = Field.Index.ANALYZED_NO_NORMS;
                    break;

                case FieldIndexType.NotAnalyzed:
                    indexType = Field.Index.NOT_ANALYZED;
                    break;

                case FieldIndexType.NotAnalyzedNoNorms:
                    indexType = Field.Index.NOT_ANALYZED_NO_NORMS;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("Unknown or invalid field index type: " + field.Index);
                }

                Lucene.Net.Documents.Field.Store storeType;
                switch (field.Store)
                {
                case FieldStorageType.Stored:
                    storeType = Field.Store.YES;
                    break;

                case FieldStorageType.NotStored:
                    storeType = Field.Store.NO;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("Unknown or invalid field store type: " + field.Store);
                }

                Lucene.Net.Documents.Field.TermVector termVectorType;
                switch (field.TermVector)
                {
                case FieldTermVectorType.Yes:
                    termVectorType = Field.TermVector.YES;
                    break;

                case FieldTermVectorType.WithOffsets:
                    termVectorType = Field.TermVector.WITH_OFFSETS;
                    break;

                case FieldTermVectorType.WithPositions:
                    termVectorType = Field.TermVector.WITH_POSITIONS;
                    break;

                case FieldTermVectorType.WithPositionsOffsets:
                    termVectorType = Field.TermVector.WITH_POSITIONS_OFFSETS;
                    break;

                case FieldTermVectorType.No:
                    termVectorType = Field.TermVector.NO;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("Unknown or invalid field term vector type: " + field.TermVector);
                }

                IFieldable luceneField;

                if (field is StringFieldDto)
                {
                    var stringField = field as StringFieldDto;

                    luceneField = new Lucene.Net.Documents.Field(stringField.Name, true, stringField.Value,
                                                                 storeType, indexType, termVectorType);
                }
                else if (field is DateFieldDto)
                {
                    var dateField = field as DateFieldDto;

                    var dateString = DateTools.DateToString(dateField.Value, DateTools.Resolution.MILLISECOND);
                    luceneField = new Field(dateField.Name, dateString, storeType, Field.Index.NOT_ANALYZED, termVectorType);
                }
                else if (field is NumericFieldDto)
                {
                    var numericField = field as NumericFieldDto;

                    luceneField = new Lucene.Net.Documents.NumericField(numericField.Name, numericField.PrecisionStep,
                                                                        storeType,
                                                                        field.Index != FieldIndexType.NotIndexed);
                }
                else
                {
                    throw new NotImplementedException();
                }

                if (field.Boost.HasValue)
                {
                    luceneField.Boost = field.Boost.Value;
                }

                luceneDocument.Add(luceneField);
            }

            return(luceneDocument);
        }