本文整理汇总了C#中Lucene.Net.Documents.Field类的典型用法代码示例。如果您正苦于以下问题:C# Field类的具体用法?C# Field怎么用?C# Field使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Field类属于Lucene.Net.Documents命名空间,在下文中一共展示了Field类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BuildLuceneDocument
protected override Document BuildLuceneDocument(Document document)
{
Field.Store storeContent = Field.Store.YES;
#if DEBUG
storeContent = Field.Store.YES;
#endif
var fieldTitle = new Field("title", photo.Title, storeContent, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
document.Add(fieldTitle);
var fieldTitleSort = new Field("title_sort", photo.Title, storeContent, Field.Index.NOT_ANALYZED_NO_NORMS);
document.Add(fieldTitleSort);
var fieldAuthor = new Field("owner", photo.Owner ?? String.Empty, storeContent, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
document.Add(fieldAuthor);
var ownerId = new Field("owner_id", photo.OwnerId.ToString(), storeContent, Field.Index.NOT_ANALYZED_NO_NORMS);
document.Add(ownerId);
var fieldAuthorIndex = new Field("owner_index", photo.Owner ?? String.Empty, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
document.Add(fieldAuthorIndex);
var fieldDescription = new Field("description", photo.Description ?? String.Empty, storeContent, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
document.Add(fieldDescription);
return document;
}
开发者ID:sdluxeon,项目名称:MyPhoto,代码行数:26,代码来源:BookSearchDocument.cs
示例2: CreateIndex
public static IndexWriter CreateIndex(Content[] contents)
{
var v = Lucene.Net.Util.Version.LUCENE_30;
var l = Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED;
var d = FSDirectory.Open(new DirectoryInfo(IndexPath));
IndexWriter writer = new IndexWriter(d, new StandardAnalyzer(v), l);
try
{
foreach (var item in contents)
{
Document doc = new Document();
Field id = new Field("id", item.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED);
Field title = new Field("title", item.Title, Field.Store.YES, Field.Index.ANALYZED);
Field username = new Field("username", item.User.UserName, Field.Store.YES, Field.Index.ANALYZED);
doc.Add(id);
doc.Add(title);
doc.Add(username);
writer.AddDocument(doc);
}
writer.Optimize();
writer.Dispose();
}
catch (System.Exception ex)
{
}
return writer;
}
开发者ID:alienblog,项目名称:ahcms,代码行数:32,代码来源:IndexHelper.cs
示例3: AddField
internal static void AddField(this Document doc, string propertyName, string propertyValue, Field.Store fieldStore, Field.Index fieldIndex)
{
if (string.IsNullOrWhiteSpace(propertyValue))
return;
doc.Add(new Field(propertyName, propertyValue, fieldStore, fieldIndex));
}
开发者ID:kiwipiet,项目名称:AddressFinder,代码行数:7,代码来源:DocumentExtensions.cs
示例4: GetIndex
public static Field.Index GetIndex(this IndexDefinition self, string name, Field.Index? defaultIndex)
{
if (self.Indexes == null)
return defaultIndex ?? Field.Index.ANALYZED_NO_NORMS;
FieldIndexing value;
if (self.Indexes.TryGetValue(name, out value) == false)
{
if (self.Indexes.TryGetValue(Constants.AllFields, out value) == false)
{
string ignored;
if (self.Analyzers.TryGetValue(name, out ignored) ||
self.Analyzers.TryGetValue(Constants.AllFields, out ignored))
{
return Field.Index.ANALYZED; // if there is a custom analyzer, the value should be analyzed
}
return defaultIndex ?? Field.Index.ANALYZED_NO_NORMS;
}
}
switch (value)
{
case FieldIndexing.No:
return Field.Index.NO;
case FieldIndexing.Analyzed:
return Field.Index.ANALYZED_NO_NORMS;
case FieldIndexing.NotAnalyzed:
return Field.Index.NOT_ANALYZED_NO_NORMS;
case FieldIndexing.Default:
return defaultIndex ?? Field.Index.ANALYZED_NO_NORMS;
default:
throw new ArgumentOutOfRangeException();
}
}
开发者ID:925coder,项目名称:ravendb,代码行数:32,代码来源:IndexingExtensions.cs
示例5: TestMultiValueSource
public virtual void TestMultiValueSource()
{
Directory dir = new MockRAMDirectory();
IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
Document doc = new Document();
Field f = new Field("field", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
doc.Add(f);
for (int i = 0; i < 17; i++)
{
f.SetValue("" + i);
w.AddDocument(doc);
w.Commit();
}
IndexReader r = w.GetReader();
w.Close();
Assert.IsTrue(r.GetSequentialSubReaders().Length > 1);
ValueSource s1 = new IntFieldSource("field");
DocValues v1 = s1.GetValues(r);
DocValues v2 = new MultiValueSource(s1).GetValues(r);
for (int i = 0; i < r.MaxDoc(); i++)
{
Assert.AreEqual(v1.IntVal(i), i);
Assert.AreEqual(v2.IntVal(i), i);
}
Lucene.Net.Search.FieldCache_Fields.DEFAULT.PurgeAllCaches();
r.Close();
dir.Close();
}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:35,代码来源:TestValueSource.cs
示例6: ToDocument
public Document ToDocument()
{
var document = new Document();
var hash = new Field(ExtensionHashField, ModelHelpers.GetMD5Hash(ToString()), Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO);
hash.Boost = ExtensionHashFieldBoost;
var name = new Field(ExtensionNameField, Name, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO);
name.Boost = ExtensionNameFieldBoost;
var fullName = new Field(ExtensionFullNameField, FullName, Field.Store.YES, Field.Index.NO, Field.TermVector.NO);
var ns = new Field(ExtensionNamespaceField, Namespace, Field.Store.YES, Field.Index.NO, Field.TermVector.NO);
var assemblyName = new Field(ExtensionAssemblyNameField, AssemblyName, Field.Store.YES, Field.Index.NO, Field.TermVector.NO);
var packageName = new Field(ExtensionPackageNameField, PackageName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO);
var packageVersion = new Field(ExtensionPackageVersionField, PackageVersion, Field.Store.YES, Field.Index.NO, Field.TermVector.NO);
var targetFrameworks = new Field(ExtensionTargetFrameworksField, GetTargetFrameworksString(), Field.Store.YES, Field.Index.NO, Field.TermVector.NO);
document.Add(hash);
document.Add(name);
document.Add(fullName);
document.Add(ns);
document.Add(assemblyName);
document.Add(packageName);
document.Add(packageVersion);
document.Add(targetFrameworks);
return document;
}
开发者ID:digideskio,项目名称:NuGet.PackageIndex,代码行数:26,代码来源:ExtensionModel.cs
示例7: InsertExternalFields
/// <summary>
/// Кастомизация индекса
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void InsertExternalFields(object sender, Examine.LuceneEngine.DocumentWritingEventArgs e)
{
if (!e.Fields.ContainsKey("criteria")) return;
var criteriaString = e.Fields["criteria"];
var xCriteriaField = new Field("xCriteria", criteriaString.Replace(',', ' '), Field.Store.YES, Field.Index.ANALYZED_NO_NORMS, Field.TermVector.NO);
e.Document.Add(xCriteriaField);
}
开发者ID:AzarinSergey,项目名称:UmbracoE-commerceBadPractic_1,代码行数:12,代码来源:ProjectEventHandler.cs
示例8: Index
public IEnumerable<AbstractField> Index(RavenJObject document, Field.Store defaultStorage)
{
return from property in document
where property.Key != Constants.DocumentIdFieldName
from field in CreateFields(property.Key, GetPropertyValue(property.Value), defaultStorage)
select field;
}
开发者ID:denno-secqtinstien,项目名称:ravendb,代码行数:7,代码来源:AnonymousObjectToLuceneDocumentConverter.cs
示例9: CreateInstance
public static Field CreateInstance(object data, XmlNode node)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
if (node == null)
{
throw new ArgumentNullException("node");
}
String name = node.Attributes["name"].Value.ToLower();
String datasource = node.Attributes["datasource"].Value;
String store = node.Attributes["store"].Value;
String index = node.Attributes["index"].Value;
Lucene.Net.Documents.Field.Store st;
Enum.TryParse<Lucene.Net.Documents.Field.Store>(store,out st);
Lucene.Net.Documents.Field.Index idx ;
Enum.TryParse<Lucene.Net.Documents.Field.Index>(index,out idx);
String value = getData(data,datasource);
//name = name.ToLower();
Field ret = new Field(name,value,st,idx);
return ret;
}
开发者ID:sharpend,项目名称:Sharpend,代码行数:30,代码来源:FieldDescription.cs
示例10: TestReadersWriters
public void TestReadersWriters()
{
Directory dir;
using(dir = new RAMDirectory())
{
Document doc;
IndexWriter writer;
IndexReader reader;
using (writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED))
{
Field field = new Field("name", "value", Field.Store.YES,Field.Index.ANALYZED);
doc = new Document();
doc.Add(field);
writer.AddDocument(doc);
writer.Commit();
using (reader = writer.GetReader())
{
IndexReader r1 = reader.Reopen();
}
Assert.Throws<AlreadyClosedException>(() => reader.Reopen(), "IndexReader shouldn't be open here");
}
Assert.Throws<AlreadyClosedException>(() => writer.AddDocument(doc), "IndexWriter shouldn't be open here");
Assert.IsTrue(dir.isOpen_ForNUnit, "RAMDirectory");
}
Assert.IsFalse(dir.isOpen_ForNUnit, "RAMDirectory");
}
开发者ID:hanabi1224,项目名称:lucene.net,代码行数:32,代码来源:TestIDisposable.cs
示例11: Save
public void Save(SearchDocument doc)
{
if (doc == null) throw new ArgumentNullException(nameof(doc));
if (doc.Fields == null || doc.Fields.Count == 0)
return;
var document = new Document();
foreach (var docField in doc.Fields)
{
if (string.IsNullOrWhiteSpace(docField.FieldName))
throw new Exception("Field name cannot be empty");
if (string.IsNullOrWhiteSpace(docField.Value))
continue;
var field = new Field(docField.FieldName, docField.Value, Field.Store.YES, Field.Index.ANALYZED);
document.Add(field);
}
var writer = new IndexWriter(
_directory,
new StandardAnalyzer(global::Lucene.Net.Util.Version.LUCENE_30),
!_created,
IndexWriter.MaxFieldLength.UNLIMITED);
using (writer)
{
writer.AddDocument(document);
}
_created = true;
}
开发者ID:mantasaudickas,项目名称:software-architect,代码行数:33,代码来源:LuceneSearchService.cs
示例12: AddField
/// <summary>
/// Adds a field to the index, bit more configurable than the other helper methods, but more verbose as a consequence.
/// </summary>
/// <param name="document">The document to add the field to </param>
/// <param name="fieldName">The name of the field to add</param>
/// <param name="value">The value of the field</param>
/// <param name="store">A boolean denoting whether to store the value in the index - allows retrieval of the original value from the index</param>
/// <param name="caseSensitive">Whether to store the value in its original case</param>
/// <param name="index">The type of indexing to apply to the field</param>
/// <returns>The input document object</returns>
public static Document AddField(this Document document, string fieldName, string value, bool caseSensitive, Field.Store store, Field.Index index)
{
if (value == null)
{
return document;
}
if (store == null)
{
store = Field.Store.NO;
}
if (!caseSensitive)
{
value = value.ToLower();
}
if (index == null)
{
index = Field.Index.ANALYZED;
}
Field field = new Field(fieldName, value, store, index);
document.Add(field);
return document;
}
开发者ID:simonproctor,项目名称:Lucinq,代码行数:36,代码来源:DocumentExtensions.cs
示例13: BuildLuceneDocument
protected override Document BuildLuceneDocument(Document document)
{
Field.Store storeContent = Field.Store.YES;
#if DEBUG
storeContent = Field.Store.YES;
#endif
var name = new Field("author_name", author.Name, storeContent, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
document.Add(name);
var fieldNameSort = new Field("author_sort", author.Name, storeContent, Field.Index.NOT_ANALYZED_NO_NORMS);
document.Add(fieldNameSort);
var fieldName = new Field("author_firstName", author.FirstName, storeContent, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
document.Add(fieldName);
var lastName = new Field("author_lastName", author.LastName, storeContent, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
document.Add(lastName);
var fieldBiography = new Field("biography", author.Biography ?? String.Empty, storeContent, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
document.Add(fieldBiography);
var fieldAuthorId = new Field("author_id", author.ElanId.ToString(), storeContent, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
document.Add(fieldAuthorId);
return document;
}
开发者ID:sdluxeon,项目名称:MyPhoto,代码行数:27,代码来源:AuthorSearchDocument.cs
示例14: Set
public void Set(string name, object value, Document document, Field.Store store, Field.Index index, float? boost)
{
DateTime date = (DateTime) value;
int year = date.Year;
int month = date.Month;
int day = date.Day;
// set year
Field field = new Field(name + ".year", year.ToString(), store, index);
if (boost != null)
{
field.SetBoost(boost.Value);
}
document.Add(field);
// set month and pad it if necessary
field = new Field(name + ".month", month.ToString("D2"), store, index);
if (boost != null)
{
field.SetBoost(boost.Value);
}
document.Add(field);
// set day and pad it if necessary
field = new Field(name + ".day", day.ToString("D2"), store, index);
if (boost != null)
{
field.SetBoost(boost.Value);
}
document.Add(field);
throw new NotImplementedException();
}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:34,代码来源:DateSplitBridge.cs
示例15: CreateIndex
public void CreateIndex()
{
IProductService productService = new ProductService();
int count = productService.GetProductCount(string.Empty);
var data = productService.GetProducts(count, 1, string.Empty);
//设置为多文件索引的格式,默认情况下为true,会建立复合索引的文件结构,这里为了分析,先设置为false,生成多文件的索引结构
//this.indexWriter.SetUseCompoundFile(false);
foreach (var productInfo in data)
{
var doc = new Document();
var field1 = new Field("title", productInfo.Title, Field.Store.YES, Field.Index.ANALYZED);
// 向文档中添加域
doc.Add(field1);
field1 = new Field("Category", productInfo.CategoryName, Field.Store.YES, Field.Index.ANALYZED);
doc.Add(field1);
field1 = new Field("Desc", productInfo.Desc??"", Field.Store.YES, Field.Index.ANALYZED);
doc.Add(field1);
this.indexWriter.AddDocument(doc);
}
// 优化索引结构
this.indexWriter.Optimize();
this.indexWriter.Commit();
// 关闭写入
this.indexWriter.Close();
}
开发者ID:jiangguang5201314,项目名称:DotNetFramework,代码行数:29,代码来源:SearchEngine.cs
示例16: AddMetaDataField
private void AddMetaDataField(Document doc, Term term, int[] meta)
{
IntMetaDataTokenStream tokenStream = new IntMetaDataTokenStream(term.Text);
tokenStream.SetMetaData(meta);
Field field = new Field(term.Field, tokenStream);
doc.Add(field);
}
开发者ID:modulexcite,项目名称:BoboBrowse.Net,代码行数:7,代码来源:SectionSearchTest.cs
示例17: BuildRecord
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;
}
开发者ID:parrymike,项目名称:myMDS_Dev,代码行数:25,代码来源:EmailSearchDocument.cs
示例18: Test_IndexReader_IsCurrent
public void Test_IndexReader_IsCurrent()
{
RAMDirectory ramDir = new RAMDirectory();
IndexWriter writer = new IndexWriter(ramDir, new KeywordAnalyzer(), true, new IndexWriter.MaxFieldLength(1000));
Field field = new Field("TEST", "mytest", Field.Store.YES, Field.Index.ANALYZED);
Document doc = new Document();
doc.Add(field);
writer.AddDocument(doc);
IndexReader reader = writer.GetReader();
writer.DeleteDocuments(new Lucene.Net.Index.Term("TEST", "mytest"));
Assert.IsFalse(reader.IsCurrent());
int resCount1 = new IndexSearcher(reader).Search(new TermQuery(new Term("TEST", "mytest")),100).TotalHits;
Assert.AreEqual(1, resCount1);
writer.Commit();
Assert.IsFalse(reader.IsCurrent());
int resCount2 = new IndexSearcher(reader).Search(new TermQuery(new Term("TEST", "mytest")),100).TotalHits;
Assert.AreEqual(1, resCount2, "Reopen not invoked yet, resultCount must still be 1.");
reader = reader.Reopen();
Assert.IsTrue(reader.IsCurrent());
int resCount3 = new IndexSearcher(reader).Search(new TermQuery(new Term("TEST", "mytest")), 100).TotalHits;
Assert.AreEqual(0, resCount3, "After reopen, resultCount must be 0.");
reader.Close();
writer.Dispose();
}
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:34,代码来源:TestOldPatches.cs
示例19: AddTextField
private void AddTextField(Document doc, string fieldName, string[] sections)
{
for (int i = 0; i < sections.Length; i++)
{
Field field = new Field(fieldName, new SectionTokenStream(analyzer.TokenStream(fieldName, new System.IO.StringReader(sections[i])), i));
doc.Add(field);
}
}
开发者ID:modulexcite,项目名称:BoboBrowse.Net,代码行数:8,代码来源:SectionSearchTest.cs
示例20: AddField
public static Document AddField(this Document document, string name, string value, Field.Store store, Field.Index index)
{
if (String.IsNullOrEmpty(value))
return document;
document.Add(new Field(name, value, store, index));
return document;
}
开发者ID:modulexcite,项目名称:MultiFacetLuceneNet,代码行数:8,代码来源:DocumentExtensions.cs
注:本文中的Lucene.Net.Documents.Field类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论