本文整理汇总了C#中Lucene.Net.Index.IndexWriter.SetRAMBufferSizeMB方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.SetRAMBufferSizeMB方法的具体用法?C# IndexWriter.SetRAMBufferSizeMB怎么用?C# IndexWriter.SetRAMBufferSizeMB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了IndexWriter.SetRAMBufferSizeMB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyToWriter
public void ApplyToWriter(IndexWriter writer)
{
try
{
if (MergeFactor != null)
{
writer.SetMergeFactor((int) MergeFactor);
}
if (MaxMergeDocs != null)
{
writer.SetMaxMergeDocs((int) MaxMergeDocs);
}
if (MaxBufferedDocs != null)
{
writer.SetMaxBufferedDocs((int) MaxBufferedDocs);
}
if (RamBufferSizeMb != null)
{
writer.SetRAMBufferSizeMB((int) RamBufferSizeMb);
}
if (TermIndexInterval != null)
{
writer.SetTermIndexInterval((int) TermIndexInterval);
}
}
catch (ArgumentOutOfRangeException)
{
// TODO: Log it
}
}
示例2: GetAzureIndexWriter
public static IndexWriter GetAzureIndexWriter(this LuceneIndexer indexer)
{
indexer.EnsureIndex(false);
var writer = new IndexWriter(indexer.GetLuceneDirectory(), indexer.IndexingAnalyzer, false, IndexWriter.MaxFieldLength.UNLIMITED);
writer.SetRAMBufferSizeMB(10.0);
writer.SetUseCompoundFile(false);
writer.SetMaxMergeDocs(10000);
writer.SetMergeFactor(100);
return writer;
}
示例3: Main
static void Main(string[] args)
{
// default AzureDirectory stores cache in local temp folder
var azureDirectory = new AzureDirectory(CloudStorageAccount.Parse(ConfigurationManager.AppSettings["blobStorage"]), "TestCatalog6");
var findexExists = IndexReader.IndexExists(azureDirectory);
IndexWriter indexWriter = null;
while (indexWriter == null)
{
try
{
indexWriter = new IndexWriter(azureDirectory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT), !IndexReader.IndexExists(azureDirectory), new Lucene.Net.Index.IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH));
}
catch (LockObtainFailedException)
{
Console.WriteLine("Lock is taken, Hit 'Y' to clear the lock, or anything else to try again");
if (Console.ReadLine().ToLower().Trim() == "y" )
azureDirectory.ClearLock("write.lock");
}
};
Console.WriteLine("IndexWriter lock obtained, this process has exclusive write access to index");
indexWriter.SetRAMBufferSizeMB(10.0);
//indexWriter.SetUseCompoundFile(false);
//indexWriter.SetMaxMergeDocs(10000);
//indexWriter.SetMergeFactor(100);
for (int iDoc = 0; iDoc < 10000; iDoc++)
{
if (iDoc % 10 == 0)
Console.WriteLine(iDoc);
var doc = new Document();
doc.Add(new Field("id", DateTime.Now.ToFileTimeUtc().ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
doc.Add(new Field("Title", GeneratePhrase(10), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
doc.Add(new Field("Body", GeneratePhrase(40), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
indexWriter.AddDocument(doc);
}
Console.WriteLine("Total docs is {0}", indexWriter.NumDocs());
indexWriter.Dispose();
IndexSearcher searcher;
using (new AutoStopWatch("Creating searcher"))
{
searcher = new IndexSearcher(azureDirectory);
}
SearchForPhrase(searcher, "dog");
SearchForPhrase(searcher, _random.Next(32768).ToString());
SearchForPhrase(searcher, _random.Next(32768).ToString());
Console.Read();
}
示例4: TestReadAndWrite
public void TestReadAndWrite()
{
var connectionString = Environment.GetEnvironmentVariable("DataConnectionString") ?? "UseDevelopmentStorage=true";
var cloudStorageAccount = CloudStorageAccount.Parse(connectionString);
// default AzureDirectory stores cache in local temp folder
var azureDirectory = new AzureDirectory(cloudStorageAccount, "testcatalog");
using (var indexWriter = new IndexWriter(azureDirectory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), !IndexReader.IndexExists(azureDirectory), new Lucene.Net.Index.IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH)))
{
indexWriter.SetRAMBufferSizeMB(10.0);
for (int iDoc = 0; iDoc < 10000; iDoc++)
{
var doc = new Document();
doc.Add(new Field("id", DateTime.Now.ToFileTimeUtc().ToString() + "-" + iDoc.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
doc.Add(new Field("Title", GeneratePhrase(10), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
doc.Add(new Field("Body", GeneratePhrase(40), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
indexWriter.AddDocument(doc);
}
Console.WriteLine("Total docs is {0}", indexWriter.NumDocs());
}
using (var searcher = new IndexSearcher(azureDirectory))
{
Assert.AreNotEqual(0, SearchForPhrase(searcher, "dog"));
Assert.AreNotEqual(0, SearchForPhrase(searcher, "cat"));
Assert.AreNotEqual(0, SearchForPhrase(searcher, "car"));
}
// check the container exists, and delete it
var blobClient = cloudStorageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("testcatalog");
Assert.IsTrue(container.Exists()); // check the container exists
container.Delete();
}
示例5: CreateIndexWriter
private void CreateIndexWriter()
{
snapshotter = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
indexWriter = new IndexWriter(directory, stopAnalyzer, snapshotter, IndexWriter.MaxFieldLength.UNLIMITED);
using (indexWriter.MergeScheduler) { }
indexWriter.SetMergeScheduler(new ErrorLoggingConcurrentMergeScheduler());
// RavenDB already manages the memory for those, no need for Lucene to do this as well
indexWriter.SetMaxBufferedDocs(IndexWriter.DISABLE_AUTO_FLUSH);
indexWriter.SetRAMBufferSizeMB(1024);
}
示例6: TestTermVectorCorruption3
public virtual void TestTermVectorCorruption3()
{
Directory dir = new MockRAMDirectory();
IndexWriter writer = new IndexWriter(dir, false, new StandardAnalyzer());
writer.SetMaxBufferedDocs(2);
writer.SetRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
writer.SetMergeScheduler(new SerialMergeScheduler());
writer.SetMergePolicy(new LogDocMergePolicy());
Document document = new Document();
document = new Document();
Field storedField = new Field("stored", "stored", Field.Store.YES, Field.Index.NO);
document.Add(storedField);
Field termVectorField = new Field("termVector", "termVector", Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
document.Add(termVectorField);
for (int i = 0; i < 10; i++)
writer.AddDocument(document);
writer.Close();
writer = new IndexWriter(dir, false, new StandardAnalyzer());
writer.SetMaxBufferedDocs(2);
writer.SetRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
writer.SetMergeScheduler(new SerialMergeScheduler());
writer.SetMergePolicy(new LogDocMergePolicy());
for (int i = 0; i < 6; i++)
writer.AddDocument(document);
writer.Optimize();
writer.Close();
IndexReader reader = IndexReader.Open(dir);
for (int i = 0; i < 10; i++)
{
reader.GetTermFreqVectors(i);
reader.Document(i);
}
reader.Close();
dir.Close();
}
示例7: TestHighFreqTerm
public virtual void TestHighFreqTerm()
{
RAMDirectory dir = new RAMDirectory();
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
writer.SetRAMBufferSizeMB(0.01);
writer.SetMaxFieldLength(100000000);
// Massive doc that has 128 K a's
System.Text.StringBuilder b = new System.Text.StringBuilder(1024 * 1024);
for (int i = 0; i < 4096; i++)
{
b.Append(" a a a a a a a a");
b.Append(" a a a a a a a a");
b.Append(" a a a a a a a a");
b.Append(" a a a a a a a a");
}
Document doc = new Document();
doc.Add(new Field("field", b.ToString(), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
writer.AddDocument(doc);
writer.Close();
IndexReader reader = IndexReader.Open(dir);
Assert.AreEqual(1, reader.MaxDoc());
Assert.AreEqual(1, reader.NumDocs());
Term t = new Term("field", "a");
Assert.AreEqual(1, reader.DocFreq(t));
TermDocs td = reader.TermDocs(t);
td.Next();
Assert.AreEqual(128 * 1024, td.Freq());
reader.Close();
dir.Close();
}
示例8: TestChangingRAMBuffer2
public virtual void TestChangingRAMBuffer2()
{
RAMDirectory dir = new RAMDirectory();
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
writer.SetMaxBufferedDocs(10);
writer.SetMaxBufferedDeleteTerms(10);
writer.SetRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
for (int j = 1; j < 52; j++)
{
Document doc = new Document();
doc.Add(new Field("field", "aaa" + j, Field.Store.YES, Field.Index.TOKENIZED));
writer.AddDocument(doc);
}
long lastGen = - 1;
for (int j = 1; j < 52; j++)
{
writer.DeleteDocuments(new Term("field", "aaa" + j));
_TestUtil.SyncConcurrentMerges(writer);
long gen = SegmentInfos.GenerationFromSegmentsFileName(SegmentInfos.GetCurrentSegmentFileName(dir.List()));
if (j == 1)
lastGen = gen;
else if (j < 10)
{
// No new files should be created
Assert.AreEqual(gen, lastGen);
}
else if (10 == j)
{
Assert.IsTrue(gen > lastGen);
lastGen = gen;
writer.SetRAMBufferSizeMB(0.000001);
writer.SetMaxBufferedDeleteTerms(IndexWriter.DISABLE_AUTO_FLUSH);
}
else if (j < 20)
{
Assert.IsTrue(gen > lastGen);
lastGen = gen;
}
else if (20 == j)
{
writer.SetRAMBufferSizeMB(16);
writer.SetMaxBufferedDeleteTerms(IndexWriter.DISABLE_AUTO_FLUSH);
lastGen = gen;
}
else if (j < 30)
{
Assert.AreEqual(gen, lastGen);
}
else if (30 == j)
{
writer.SetRAMBufferSizeMB(0.000001);
writer.SetMaxBufferedDeleteTerms(IndexWriter.DISABLE_AUTO_FLUSH);
}
else if (j < 40)
{
Assert.IsTrue(gen > lastGen);
lastGen = gen;
}
else if (40 == j)
{
writer.SetMaxBufferedDeleteTerms(10);
writer.SetRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
lastGen = gen;
}
else if (j < 50)
{
Assert.AreEqual(gen, lastGen);
writer.SetMaxBufferedDeleteTerms(10);
writer.SetRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
}
else if (50 == j)
{
Assert.IsTrue(gen > lastGen);
}
}
writer.Close();
dir.Close();
}
示例9: Do
static void Do()
{
//var directory = new SimpleFSDirectory(new DirectoryInfo(@"c:\temp\lucene"));
using (var connection = new SqlConnection(@"MultipleActiveResultSets=True;Data Source=(localdb)\v11.0;Initial Catalog=TestLucene;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False"))
{
connection.Open();
var directory = new SqlServerDirectory(connection, new Options() { SchemaName = "[search]" });
for (int outer = 0; outer < 1000; outer++)
{
IndexWriter indexWriter = null;
while (indexWriter == null)
{
try
{
indexWriter = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30),
!IndexReader.IndexExists(directory),
new Lucene.Net.Index.IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH));
}
catch (LockObtainFailedException)
{
Console.WriteLine("Lock is taken, waiting for timeout...");
Thread.Sleep(1000);
}
}
;
Console.WriteLine("IndexWriter lock obtained, this process has exclusive write access to index");
indexWriter.SetRAMBufferSizeMB(100.0);
indexWriter.SetInfoStream(new StreamWriter(Console.OpenStandardOutput()));
indexWriter.UseCompoundFile = false;
for (int iDoc = 0; iDoc < 1000; iDoc++)
{
if (iDoc % 10 == 0)
Console.WriteLine(iDoc);
Document doc = new Document();
doc.Add(new Field("id", DateTime.Now.ToFileTimeUtc().ToString(), Field.Store.YES,
Field.Index.ANALYZED, Field.TermVector.NO));
doc.Add(new Field("Title", "dog " + GeneratePhrase(50), Field.Store.NO, Field.Index.ANALYZED,
Field.TermVector.NO));
doc.Add(new Field("Body", "dog " + GeneratePhrase(50), Field.Store.NO, Field.Index.ANALYZED,
Field.TermVector.NO));
indexWriter.AddDocument(doc);
}
Console.WriteLine("Total docs is {0}", indexWriter.NumDocs());
Console.Write("Flushing and disposing writer...");
indexWriter.Flush(true, true, true);
indexWriter.Dispose();
}
IndexSearcher searcher;
using (new AutoStopWatch("Creating searcher"))
{
searcher = new IndexSearcher(directory);
}
using (new AutoStopWatch("Count"))
Console.WriteLine("Number of docs: {0}", searcher.IndexReader.NumDocs());
while (true)
{
SearchForPhrase(searcher, "microsoft");
Thread.Sleep(1000);
//Console.WriteLine("Press a key to search again");
//Console.ReadKey();
}
}
}
示例10: Main
static void Main(string[] args)
{
// get settings from azure settings or app.config
CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
{
try
{
configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
}
catch (Exception)
{
// for a console app, reading from App.config
configSetter(System.Configuration.ConfigurationManager.AppSettings[configName]);
}
});
// default AzureDirectory stores cache in local temp folder
AzureDirectory azureDirectory = new AzureDirectory(CloudStorageAccount.FromConfigurationSetting("blobStorage"), "TestCatalog6");
bool findexExists = IndexReader.IndexExists(azureDirectory);
IndexWriter indexWriter = null;
while (indexWriter == null)
{
try
{
indexWriter = new IndexWriter(azureDirectory, new StandardAnalyzer(), !IndexReader.IndexExists(azureDirectory));
}
catch (LockObtainFailedException)
{
Console.WriteLine("Lock is taken, Hit 'Y' to clear the lock, or anything else to try again");
if (Console.ReadLine().ToLower().Trim() == "y" )
azureDirectory.ClearLock("write.lock");
}
};
Console.WriteLine("IndexWriter lock obtained, this process has exclusive write access to index");
indexWriter.SetRAMBufferSizeMB(10.0);
indexWriter.SetUseCompoundFile(false);
indexWriter.SetMaxMergeDocs(10000);
indexWriter.SetMergeFactor(100);
for (int iDoc = 0; iDoc < 10000; iDoc++)
{
if (iDoc % 10 == 0)
Console.WriteLine(iDoc);
Document doc = new Document();
doc.Add(new Field("id", DateTime.Now.ToFileTimeUtc().ToString(), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
doc.Add(new Field("Title", GeneratePhrase(10), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
doc.Add(new Field("Body", GeneratePhrase(40), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
indexWriter.AddDocument(doc);
}
Console.WriteLine("Total docs is {0}", indexWriter.DocCount());
indexWriter.Close();
IndexSearcher searcher;
using (new AutoStopWatch("Creating searcher"))
{
searcher = new IndexSearcher(azureDirectory);
}
SearchForPhrase(searcher, "dog");
SearchForPhrase(searcher, _random.Next(32768).ToString());
SearchForPhrase(searcher, _random.Next(32768).ToString());
}
示例11: GetIndexWriter
public virtual IndexWriter GetIndexWriter( string indexName )
{
IndexWriter writer;
if ( !indexWriters.TryGetValue( indexName, out writer ) )
{
var index = GetIndex( indexName );
var analyzer = GetIndexingAnalyzer( indexName );
writer = new IndexWriter( index, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED );
writer.SetRAMBufferSizeMB( configuration.MemoryBufferLimit );
writer.SetWriteLockTimeout( configuration.WriterLockTimeout );
writer.MaybeMerge();
indexWriters.TryAdd( indexName, writer );
}
return writer;
}
示例12: optimizeIndex
public void optimizeIndex(string azureContainerName)
{
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(new Utility().getConfigXML());
XmlNode xNode = xdoc.SelectSingleNode(string.Format("//blobdata[@name='default']"));
string azureAccount = xNode.Attributes["account"].Value;
string azureEndpoint = xNode.Attributes["endpoint"].Value;
string azureSharedKey = xNode.Attributes["accountSharedKey"].Value;
string blobStorage = xNode.Attributes["endpoint"].Value;
xNode = xdoc.SelectSingleNode(string.Format("//fragmentData/Setting[@name='HandlerFragments']"));
string fragmentLocation = xNode.Attributes["value"].Value;
Microsoft.WindowsAzure.StorageCredentialsAccountAndKey scaak = new Microsoft.WindowsAzure.StorageCredentialsAccountAndKey(azureAccount, azureSharedKey);
Microsoft.WindowsAzure.CloudStorageAccount csa = new Microsoft.WindowsAzure.CloudStorageAccount(scaak, false);
AzureDirectory azureDirectory = new AzureDirectory(csa, azureContainerName, new RAMDirectory());
bool findexExists = false;
try
{
findexExists = IndexReader.IndexExists(azureDirectory);
if ((findexExists) && IndexWriter.IsLocked(azureDirectory))
azureDirectory.ClearLock("write.lock");
}
catch (Exception e)
{
Trace.WriteLine(e.ToString());
return;
}
IndexWriter idxW = new IndexWriter(azureDirectory, new SnowballAnalyzer("English"), !findexExists, new IndexWriter.MaxFieldLength(1024));
idxW.SetRAMBufferSizeMB(10.0);
idxW.SetUseCompoundFile(false);
idxW.SetMaxMergeDocs(10000);
idxW.SetMergeFactor(100);
idxW.Optimize();
}
示例13: processRequest
//.........这里部分代码省略.........
case "nvarchar": sp.SqlDbType = SqlDbType.NVarChar; break;
case "real": sp.SqlDbType = SqlDbType.Real; break;
case "smalldatetime": sp.SqlDbType = SqlDbType.SmallDateTime; break;
case "smallint": sp.SqlDbType = SqlDbType.SmallInt; break;
case "smallmoney": sp.SqlDbType = SqlDbType.SmallMoney; break;
case "sql_variant": sp.SqlDbType = SqlDbType.Variant; break;
case "text": sp.SqlDbType = SqlDbType.Text; break;
case "time": sp.SqlDbType = SqlDbType.Time; break;
case "timestamp": sp.SqlDbType = SqlDbType.Timestamp; break;
case "tinyint": sp.SqlDbType = SqlDbType.TinyInt; break;
case "uniqueidentifier": sp.SqlDbType = SqlDbType.UniqueIdentifier; break;
case "varbinary": sp.SqlDbType = SqlDbType.VarBinary; break;
case "varchar": sp.SqlDbType = SqlDbType.VarChar; break;
case "xml": sp.SqlDbType = SqlDbType.Xml; break;
default: sp.SqlDbType = SqlDbType.Variant; break;
}
switch (urlParameterName.ToLower())
{
case "ipaddress": sp.Value = "127.0.0.1"; break;
case "domainname": sp.Value = ""; break;
default: if (htKeys[urlParameterName] != null)
sp.Value = htKeys[urlParameterName];
else
sp.Value = (defaultValue.ToLower() == "dbnull" ? DBNull.Value
: (object)defaultValue);
break;
}
cmd.Parameters.Add(sp);
}
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
Microsoft.WindowsAzure.StorageCredentialsAccountAndKey scaak = new Microsoft.WindowsAzure.StorageCredentialsAccountAndKey(azureAccount, azureSharedKey);
Microsoft.WindowsAzure.CloudStorageAccount csa = new Microsoft.WindowsAzure.CloudStorageAccount(scaak, false);
AzureDirectory azureDirectory = new AzureDirectory(csa, azureContainerName, new RAMDirectory());
bool findexExists = false;
try
{
findexExists = IndexReader.IndexExists(azureDirectory);
if ((findexExists) && IndexWriter.IsLocked(azureDirectory))
azureDirectory.ClearLock("write.lock");
}
catch (Exception e)
{
Trace.WriteLine(e.ToString());
return;
}
IndexWriter idxW = new IndexWriter(azureDirectory, new SnowballAnalyzer("English"), !findexExists, new IndexWriter.MaxFieldLength(1024));
idxW.SetRAMBufferSizeMB(10.0);
idxW.SetUseCompoundFile(false);
idxW.SetMaxMergeDocs(10000);
idxW.SetMergeFactor(100);
while (dr.Read())
{
StringBuilder olioSearch = new StringBuilder();
Document doc = new Document();
for (int i = 0; i <= dataName.GetUpperBound(0); i++)
{
if (isKeyFieldFlag[i])
{
NotifyCaller(string.Format("Processing {0}", dr[dataName[i]].ToString().ToLower()));
idxW.DeleteDocuments(new Term(luceneName[i], dr[dataName[i]].ToString().ToLower()));
doc.Add(new Field(luceneName[i], dr[dataName[i]].ToString().ToLower(), Field.Store.YES, Field.Index.NOT_ANALYZED));
}
else
try
{
doc.Add(new Field(luceneName[i], dr[dataName[i]].ToString(), fieldStore[i], indexType[i]));
if (isIncludedInOlioSearchFlag[i])
olioSearch.AppendFormat("\r\n{0}", dr[dataName[i]].ToString());
}
catch (Exception ex)
{
NotifyError(ex);
}
}
if (olioSearch.ToString() != string.Empty && olioSearchFieldName != string.Empty)
doc.Add(new Field(olioSearchFieldName, olioSearch.ToString(), Field.Store.NO, Field.Index.ANALYZED));
idxW.AddDocument(doc);
}
idxW.Commit();
idxW.Close();
}
}
catch (Exception ex)
{
MOOPFramework.FrameworkUtility u = new MOOPFramework.FrameworkUtility(new Utility().ResolveDataConnection("sqlAzureConnection"));
u.LogData("localhost", "quoteSearchLoader", "testing", string.Empty, string.Empty, "", "QueryError", ex.ToString(),
u.nvc2XML(htKeys));
//retVal = string.Format("<!-- {0} -->", ex.ToString());
NotifyError(new Exception("An error occured but it was logged for later review"));
}
finally { if (retVal == string.Empty) retVal = "<root />"; }
}
示例14: AddUpdateLuceneIndex
/// <summary>
/// add index
/// </summary>
/// <param name="sampleDatas"></param>
public static void AddUpdateLuceneIndex(IEnumerable<SampleData> sampleDatas)
{
// init lucene
using (var luceneDirectory = LuceneDirectory)
{
var analyzer = new StandardAnalyzer(Version);
using (var writer = new IndexWriter(luceneDirectory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
{
writer.SetRAMBufferSizeMB(10);
// add data to lucene search index (replaces older entries if any)
foreach (var sampleData in sampleDatas) AddToLuceneIndex(sampleData, writer);
writer.Commit();
// close handles
analyzer.Close();
}
}
}
示例15: CreateIndexFromDb
public static void CreateIndexFromDb()
{
using (var luceneDirectory = LuceneDirectory)
{
var analyzer = new StandardAnalyzer(Version);
using (var writer = new IndexWriter(luceneDirectory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED))
{
writer.SetRAMBufferSizeMB(20);
// add data to lucene search index (replaces older entries if any)
using (var db = new SQLDataAccess())
{
db.cmd.CommandText = "select Product.productId, Product.ArtNo, Name, " +
"(select ' ' + Offer.Artno from Catalog.Offer where Offer.ProductID=Product.productid FOR XML path('')) as OfferArtno " +
"from Catalog.Product where Product.Enabled=1 and Product.CategoryEnabled=1";
db.cmd.CommandType = CommandType.Text;
db.cnOpen();
using (var reader = db.cmd.ExecuteReader())
{
while (reader.Read())
{
Thread.Sleep(0);
AddToLuceneIndex(
new SampleData(SQLDataHelper.GetInt(reader, "productId"),
SQLDataHelper.GetString(reader, "ArtNo") + " " + SQLDataHelper.GetString(reader, "OfferArtno"),
SQLDataHelper.GetString(reader["Name"])), writer);
}
}
db.cnClose();
}
// close handles
analyzer.Close();
writer.Optimize();
}
}
}