本文整理汇总了C#中Lucene.Net.Index.IndexWriter.DeleteAll方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.DeleteAll方法的具体用法?C# IndexWriter.DeleteAll怎么用?C# IndexWriter.DeleteAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了IndexWriter.DeleteAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateIndexFromDirectory
public void CreateIndexFromDirectory()
{
string DirecotryPath = outputDirectoryName == null
? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
: Path.GetDirectoryName(outputDirectoryName);
var directory = FSDirectory.Open(DirecotryPath);
Analyzer analyzer = new TermAnalyzer();
IndexWriter writer =
new IndexWriter(directory, analyzer, true,
IndexWriter.MaxFieldLength.UNLIMITED);
var files = FileHelper.GetFilesFromRelativePath(inputDirectoryName);
writer.DeleteAll();
foreach (var fileInfo in files)
{
//var detailedPath = DirecotryPath + "\\" + fileInfo.Name;
//var detailedDirectory = FSDirectory.Open(detailedPath);
//IndexWriter detailedlWriter = new IndexWriter(detailedDirectory, analyzer, true,
// IndexWriter.MaxFieldLength.UNLIMITED);
Document doc = new Document();
Document detailedDocument = new Document();
var path = fileInfo.Directory + "\\" + fileInfo.Name;
var reader = new StreamReader(path);
doc.Add(new Field("content", reader, Field.TermVector.WITH_POSITIONS));
writer.AddDocument(doc);
reader.Close();
reader = new StreamReader(path);
detailedDocument.Add(new Field(fileInfo.Name, reader, Field.TermVector.WITH_POSITIONS));
//detailedlWriter.AddDocument(detailedDocument);
//detailedlWriter.Optimize();
//detailedlWriter.Commit();
}
writer.Optimize();
writer.Commit();
}
示例2: Run
public static void Run(string[] args)
{
IDictionary<string, string> arguments = CommandHelpers.GetArguments(args, 1);
if (arguments == null)
{
PrintUsage();
return;
}
Lucene.Net.Store.Directory directory = CommandHelpers.GetLuceneDirectory(arguments);
if (directory == null)
{
PrintUsage();
return;
}
if (IndexReader.IndexExists(directory))
{
using (IndexWriter writer = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED))
{
writer.DeleteAll();
writer.Commit(new Dictionary<string, string>());
}
}
Console.WriteLine("All Done");
}
示例3: ClearIndex
public void ClearIndex()
{
if (System.IO.Directory.GetFiles(this.index.Directory.FullName).Any())
{
try
{
var analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
using (var writer = new IndexWriter(this.index, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED))
{
// remove older index entries
writer.DeleteAll();
// close handles
analyzer.Close();
writer.Dispose();
}
ForceUnlockIndex();
}
catch (Exception)
{
throw;
}
}
}
示例4: DeleteAllItemsFromIndex
public void DeleteAllItemsFromIndex()
{
using (var writer = new IndexWriter(LuceneDirectory, new StandardAnalyzer(Version.LUCENE_30), IndexWriter.MaxFieldLength.UNLIMITED))
{
writer.DeleteAll();
}
}
示例5: Main
static void Main(string[] args)
{
// Initialize Lucene
Directory directory = FSDirectory.Open(new System.IO.DirectoryInfo("LuceneIndex"));
StandardAnalyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
// Open DB connection
OpenConnections();
// Insert documents into the index
// Clear the index
writer.DeleteAll();
string sql = "SELECT a.ArticleId, a.Title, a.IntroText, a.Content, a.Published, a.DateCreated, " +
"u.UserName, a.SectionId FROM Article AS a INNER JOIN aspnet_Users AS u ON " +
"a.CreatedBy = u.UserId";
SqlCommand cmd = new SqlCommand(sql, dbConn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
// Extract the fields to be indexed
int articleId = reader.GetInt32(reader.GetOrdinal("ArticleId"));
string title = reader["Title"].ToString();
string content = reader["IntroText"].ToString() + reader["Content"].ToString();
string intro = content.Substring(0, content.Length > 100 ? 100 : content.Length);
string author = reader["UserName"].ToString();
int sectionId = reader.GetInt32(reader.GetOrdinal("SectionId"));
bool published = reader.GetBoolean(reader.GetOrdinal("Published"));
DateTime pubDate = reader.GetDateTime(reader.GetOrdinal("DateCreated"));
string strPubDate = DateTools.DateToString(pubDate, DateTools.Resolution.DAY);
Document doc = new Document();
doc.Add(new Field("ArticleId", articleId.ToString(), Field.Store.YES, Field.Index.NO));
doc.Add(new Field("Title", title, Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("Content", content, Field.Store.NO, Field.Index.ANALYZED));
doc.Add(new Field("Intro", title, Field.Store.YES, Field.Index.NO));
doc.Add(new Field("Author", author, Field.Store.YES, Field.Index.NO));
doc.Add(new Field("SectionId", sectionId.ToString(), Field.Store.NO, Field.Index.NOT_ANALYZED));
doc.Add(new Field("Published", published.ToString(), Field.Store.NO, Field.Index.NOT_ANALYZED));
doc.Add(new Field("PubDate", strPubDate, Field.Store.YES, Field.Index.NOT_ANALYZED));
writer.AddDocument(doc);
}
// Close everything, shut down.
writer.Optimize();
writer.Commit();
writer.Close();
dbConn.Close();
}
示例6: ClearIndex
/// <summary>
/// Clears the entire index.
/// </summary>
/// <param name="luceneVersion">The lucene version.</param>
/// <param name="fsDirectory">The fs directory.</param>
/// <param name="maxFieldLength">Maximum length of the field.</param>
public virtual void ClearIndex(Version luceneVersion, FSDirectory fsDirectory, IndexWriter.MaxFieldLength maxFieldLength)
{
var analyzer = new StandardAnalyzer(luceneVersion);
using (var indexWriter = new IndexWriter(fsDirectory, analyzer, maxFieldLength))
{
indexWriter.DeleteAll();
analyzer.Close();
}
}
示例7: ClearIndex
/// <summary>
/// Clears the index.
/// </summary>
public void ClearIndex()
{
var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
using (var writer = new IndexWriter(directoryTemp, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
{
writer.DeleteAll();
analyzer.Close();
writer.Optimize();
writer.Dispose();
}
}
示例8: IndexMaker
public IndexMaker(string indexDir, string fieldName)
{
_indexDir = indexDir;
_fieldName = fieldName;
using (Directory directory = FSDirectory.Open(_indexDir))
using (Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
using (IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
{
writer.DeleteAll();
}
}
示例9: Build
public static void Build(IndexWriter writer)
{
writer.DeleteAll();
Populate(GetPrograms(), writer);
Populate(GetApplications(), writer);
Populate(GetInitiatives(), writer);
Populate(GetInitiativeTasks(), writer);
writer.Optimize();
writer.Commit();
writer.Dispose();
}
示例10: RebuildIndex
private static void RebuildIndex(Lucene.Net.Store.Directory directory, Analyzer analyzer, List<Product> products)
{
IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.LIMITED);
writer.DeleteAll();
writer.Commit();
foreach (Product p in products) // Add Documents to the Index.
{
AddDocumentToIndex(p, writer);
}
writer.Optimize();
writer.Commit();
writer.Dispose();
}
示例11: Setup
public void Setup()
{
var dirProvider = new Mock<IDataDirectoryProvider>();
dirProvider.Setup(x => x.DataDirectoryPath).Returns(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\MyJobLeadsTestIndex");
_provider = new LuceneSearchProvider(dirProvider.Object);
// Load the index and delete all documents so it's fresh for the test
_indexDirectory = Lucene.Net.Store.FSDirectory.Open(new DirectoryInfo(_provider.LuceneIndexBaseDirectory));
bool createNewIndex = !IndexReader.IndexExists(_indexDirectory);
var writer = new IndexWriter(_indexDirectory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), createNewIndex, IndexWriter.MaxFieldLength.UNLIMITED);
writer.DeleteAll();
writer.Close();
}
示例12: RunInternal
protected override Task RunInternal(CancellationToken cancellationToken)
{
if (IndexReader.IndexExists(_directory))
{
using (var writer = new IndexWriter(_directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED))
{
writer.DeleteAll();
writer.Commit(new Dictionary<string, string>());
}
}
Logger.LogInformation("All Done");
return Task.FromResult(false);
}
示例13: ClearIndex
/// <summary>
/// Clear all index
/// </summary>
/// <returns>true if sucsess, false if directory was locked</returns>
public bool ClearIndex( )
{
try
{
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
using (var writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED))
{
writer.DeleteAll();
analyzer.Close();
}
return true;
}
catch
{
return false;
}
}
示例14: Index
public void Index(List<invType> types)
{
using( IndexWriter indexWriter = new IndexWriter(azureDirectory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT), true, new Lucene.Net.Index.IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH)))
{
indexWriter.DeleteAll();
types.ForEach(x =>
{
if (x.published != null && ((bool)x.published))
{
Document doc = new Document();
doc.Add(new Field("typeID", "" + x.typeID, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO));
doc.Add(new Field("typeName", x.typeName, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
// doc.Add(new Field("description", , Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
indexWriter.AddDocument(doc);
}
});
}
}
示例15: BuildIndex
public void BuildIndex(List<User> users)
{
FSDirectory directory = FSDirectory.Open(new System.IO.DirectoryInfo(AppData));
Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
IndexWriter indexWriter = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);
indexWriter.DeleteAll();
foreach (User u in users)
{
indexWriter.AddDocument(u.GetDocument());
}
indexWriter.Optimize();
indexWriter.Close();
}