本文整理汇总了C#中Lucene.Net.Analysis.Standard.StandardAnalyzer.Close方法的典型用法代码示例。如果您正苦于以下问题:C# StandardAnalyzer.Close方法的具体用法?C# StandardAnalyzer.Close怎么用?C# StandardAnalyzer.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Analysis.Standard.StandardAnalyzer
的用法示例。
在下文中一共展示了StandardAnalyzer.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformExplain
/// <summary>
/// Performs the explanation.
/// </summary>
/// <param name="luceneVersion">The lucene version.</param>
/// <param name="fsDirectory">The fs directory.</param>
/// <param name="searchQuery">The search query.</param>
/// <param name="resultId">The result identifier.</param>
/// <returns></returns>
protected virtual string PerformExplain(Version luceneVersion, FSDirectory fsDirectory, string searchQuery, int resultId)
{
/*
* The obvious problem here is that we're not using the exact same search as the real one.
*/
var explanation = string.Empty;
using (var indexSearcher = new IndexSearcher(fsDirectory, false))
{
var analyzer = new StandardAnalyzer(luceneVersion);
var queryParser = new MultiFieldQueryParser(luceneVersion, new[] { "Id".ToLowerInvariant() }, analyzer)
{
DefaultOperator = QueryParser.Operator.AND
};
var query = this.searchQueryParser.ParseQuery(searchQuery, queryParser);
explanation = indexSearcher.Explain(query, resultId).ToHtml();
analyzer.Close();
}
return explanation;
}
示例2: v
public void v()
{
//Analyzer analyzer = new CJKAnalyzer();
//TokenStream tokenStream = analyzer.TokenStream("", new StringReader("我爱你中国China中华人名共和国"));
//Lucene.Net.Analysis.Token token = null;
//while ((token = tokenStream.Next()) != null)
//{
// Response.Write(token.TermText() + "<br/>");
//}
Lucene.Net.Analysis.Standard.StandardAnalyzer a = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
string s = "我日中华人民共和国";
System.IO.StringReader reader = new System.IO.StringReader(s);
Lucene.Net.Analysis.TokenStream ts = a.TokenStream(s, reader);
bool hasnext = ts.IncrementToken();
Lucene.Net.Analysis.Tokenattributes.ITermAttribute ita;
while (hasnext)
{
ita = ts.GetAttribute<Lucene.Net.Analysis.Tokenattributes.ITermAttribute>();
Console.WriteLine(ita.Term);
hasnext = ts.IncrementToken();
}
ts.CloneAttributes();
reader.Close();
a.Close();
Console.ReadKey();
}
示例3: _search
// main search method
private static IEnumerable<SampleData> _search(string searchQuery, string searchField = "") {
// validation
if (string.IsNullOrEmpty(searchQuery.Replace("*", "").Replace("?", ""))) return new List<SampleData>();
// set up lucene searcher
using (var searcher = new IndexSearcher(_directory, false)) {
var hits_limit = 1000;
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
// search by single field
if (!string.IsNullOrEmpty(searchField)) {
var parser = new QueryParser(Version.LUCENE_29, searchField, analyzer);
var query = parseQuery(searchQuery, parser);
var hits = searcher.Search(query, hits_limit).ScoreDocs;
var results = _mapLuceneToDataList(hits, searcher);
analyzer.Close();
searcher.Close();
searcher.Dispose();
return results;
}
// search by multiple fields (ordered by RELEVANCE)
else {
var parser = new MultiFieldQueryParser
(Version.LUCENE_29, new[] {"Id", "Name", "Description"}, analyzer);
var query = parseQuery(searchQuery, parser);
var hits = searcher.Search(query, null, hits_limit, Sort.INDEXORDER).ScoreDocs;
var results = _mapLuceneToDataList(hits, searcher);
analyzer.Close();
searcher.Close();
searcher.Dispose();
return results;
}
}
}
示例4: AddUpdateLuceneIndex
// add/update/clear search index data
public static void AddUpdateLuceneIndex()
{
using (var context = new CreativeNetworkEntities())
{
// init lucene
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
using (var writer = new IndexWriter(_directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
{
// add data to lucene search index (replaces older entries if any)
foreach (var creative in context.Creative)
{
_addToLuceneIndex(creative, writer);
foreach (var chapter in creative.Chapter)
{
_addToLuceneIndex(chapter, writer);
}
}
// close handles
analyzer.Close();
writer.Dispose();
}
}
}
示例5: BuildQuery
public static Query BuildQuery(string query)
{
var untokenizedMatches = untokenizedQuery.Matches(query);
var rangeMatches = rangeQuery.Matches(query);
var standardAnalyzer = new StandardAnalyzer(Version.LUCENE_29);
try
{
if (untokenizedMatches.Count == 0 && rangeMatches.Count == 0)
return new QueryParser(Version.LUCENE_29, "", standardAnalyzer).Parse(query);
var sb = new StringBuilder(query);
var booleanQuery = new BooleanQuery();
AddUntokenizedTerms(untokenizedMatches, booleanQuery, sb, query);
AddRangeTerms(rangeMatches, booleanQuery, sb, query);
var remaining = sb.ToString();
remaining = hangingConditionAtStart.Replace(remaining, "");
remaining = hangingConditionAtEnd.Replace(remaining, "");
remaining = remaining.Trim();
if (remaining.Length > 0)
{
booleanQuery.Add(new QueryParser(Version.LUCENE_29, "", standardAnalyzer).Parse(remaining), BooleanClause.Occur.SHOULD);
}
return booleanQuery;
}
finally
{
standardAnalyzer.Close();
}
}
示例6: _search
private static IEnumerable<CustomerId> _search(string searchQuery)
{
// validation
if (string.IsNullOrEmpty(searchQuery.Replace("*", "").Replace("?", ""))) return new List<CustomerId>();
// set up lucene searcher
using (var searcher = new IndexSearcher(_directory, false))
{
var hits_limit = 1000;
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
{
//var query = new TermQuery(new Term("CustomerName", searchQuery));
var query = new BooleanQuery();
query.Add(new TermQuery(new Term("CustomerName", searchQuery)), Occur.MUST);
var hits = searcher.Search(query, hits_limit).ScoreDocs;
var results = _mapLuceneToDataList(hits, searcher);
analyzer.Close();
searcher.Dispose();
return results;
}
}
}
示例7: Optimize
public void Optimize()
{
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
using (var writer = new IndexWriter(Directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
{
analyzer.Close();
writer.Optimize();
}
}
示例8: AddUpdateLuceneIndex
public void AddUpdateLuceneIndex(IEnumerable<IPatient> sampleDatas)
{
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
using (var writer = new IndexWriter(_directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
{
foreach (var sampleData in sampleDatas) _addToLuceneIndex(sampleData, writer);
analyzer.Close();
}
}
示例9: AddToIndex
public void AddToIndex(IEnumerable<Project> projects)
{
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
using (var writer = new IndexWriter(Directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
{
foreach (var group in projects)
AddToIndex(group, writer);
analyzer.Close();
}
}
示例10: DeleteIndex
public void DeleteIndex(int id)
{
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
using (var writer = new IndexWriter(Directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
{
var searchQuery = new TermQuery(new Term(SearchingFields.Id.ToString(), id.ToString()));
writer.DeleteDocuments(searchQuery);
analyzer.Close();
}
}
示例11: AddToIndex
public void AddToIndex(IEnumerable<Student> students)
{
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
using (var writer = new IndexWriter(Directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
{
foreach (var student in students)
AddToIndex(student, writer);
analyzer.Close();
}
}
示例12: ClearIndexRecord
public static void ClearIndexRecord(int id)
{
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
using (var writer = new IndexWriter(Directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
{
var searchQuery = new TermQuery(new Term("Id", Convert.ToString(id)));
writer.DeleteDocuments(searchQuery);
analyzer.Close();
}
}
示例13: Optimize
/// <summary>
/// Optimizes the Lucene 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 Optimize(Version luceneVersion, FSDirectory fsDirectory, IndexWriter.MaxFieldLength maxFieldLength)
{
var analyzer = new StandardAnalyzer(luceneVersion);
using (var indexWriter = new IndexWriter(fsDirectory, analyzer, maxFieldLength))
{
analyzer.Close();
indexWriter.Optimize();
}
}
示例14: AddDocument
public static void AddDocument(Document document)
{
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
using (var writer = new IndexWriter(Directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
{
writer.AddDocument(document);
writer.Optimize();
writer.Commit();
analyzer.Close();
}
}
示例15: 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();
}
}