public virtual Term GetKeyTerm(object o) { var converter = ObjectConverters.GetConverter(o.GetType()); var key = converter.GetKeyField(o); return(new Term(key.Key, key.Value.ToLower())); }
public virtual ResultObject ToResultObject(Highlighter highlighter, Document doc) { var nativeTypeName = doc.GetField(NativeTypeNameField).StringValue; var nativeType = Type.GetType(nativeTypeName); var converter = ObjectConverters.GetConverter(nativeType); if (converter != null) { ResultObject result = new ResultObject(); result.Title = doc.GetField(TitleFieldName).StringValue; result.HighlightedTitle = highlighter.GetBestFragment(this.Analyzer, TitleFieldName, result.Title); if (string.IsNullOrEmpty(result.HighlightedTitle)) { result.HighlightedTitle = result.Title; } result.Body = doc.GetField(BodyFieldName).StringValue; result.HighlightedBody = string.Join("...", highlighter.GetBestFragments(Analyzer, BodyFieldName, result.Body, 5)); if (string.IsNullOrEmpty(result.HighlightedBody)) { result.HighlightedBody = result.Body; } NameValueCollection fields = new NameValueCollection(); foreach (Field field in doc.GetFields()) { if (!IsReservedField(field.Name)) { fields[field.Name] = field.StringValue; } } result.NativeObject = converter.GetNativeObject(fields); result.Url = converter.GetUrl(result.NativeObject); return(result); } return(null); }
public virtual Document ToDocument(object o) { Document doc = null; var converter = ObjectConverters.GetConverter(o.GetType()); if (converter != null) { var indexObject = converter.GetIndexObject(o); if (indexObject != null) { doc = new Document(); var key = converter.GetKeyField(o); doc.Add(new Field(key.Key, key.Value.ToLower(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(TitleFieldName, indexObject.Title, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(BodyFieldName, indexObject.Body, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(NativeTypeNameField, indexObject.NativeType, Field.Store.YES, Field.Index.NO)); if (indexObject.StoreFields != null) { foreach (var item in indexObject.StoreFields.AllKeys) { if (!item.EqualsOrNullEmpty(key.Key, StringComparison.OrdinalIgnoreCase)) { doc.Add(new Field(item, indexObject.StoreFields[item], Field.Store.YES, Field.Index.NO)); } } } if (indexObject.SystemFields != null) { foreach (var item in indexObject.SystemFields.AllKeys) { if (!item.EqualsOrNullEmpty(key.Key, StringComparison.OrdinalIgnoreCase)) { doc.Add(new Field(item, indexObject.SystemFields[item], Field.Store.YES, Field.Index.NOT_ANALYZED)); } } } } } return(doc); }