Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Lucene.Net中使用空格分析器和小写过滤器创建自己的分析器? 在我的例子中,我需要搜索C类、.NET、C++等关键字,在这里标准分析器会输出特殊字符,所以我使用空白分析程序,对我来说不起作用。 编制索引时: public void Indexing(DataSet ds) { string indexFileLocation = @"D:\Lucene.Net\Data"; Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation, true); IndexWriter indexWriter = new IndexWriter(dir, new WhitespaceAnalyzer(), Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED); if (ds.Tables[0] != null) { DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { //Create the Document object Document doc = new Document(); foreach (DataColumn dc in dt.Columns) { string check = dc.ToString(); if (check.Equals("Skill_Summary")) { doc.Add(new Field(dc.ColumnName, dr[dc.ColumnName].ToString(), Field.Store.YES, Field.Index.ANALYZED)); } if (check.Equals("Title")) { doc.Add(new Field(dc.ColumnName, dr[dc.ColumnName].ToString(), Field.Store.YES, Field.Index.ANALYZED)); } } // Write the Document to the catalog indexWriter.AddDocument(doc); } } } // Close the writer indexWriter.Close(); }_C#_Lucene_Lucene.net - Fatal编程技术网

C# 如何在Lucene.Net中使用空格分析器和小写过滤器创建自己的分析器? 在我的例子中,我需要搜索C类、.NET、C++等关键字,在这里标准分析器会输出特殊字符,所以我使用空白分析程序,对我来说不起作用。 编制索引时: public void Indexing(DataSet ds) { string indexFileLocation = @"D:\Lucene.Net\Data"; Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation, true); IndexWriter indexWriter = new IndexWriter(dir, new WhitespaceAnalyzer(), Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED); if (ds.Tables[0] != null) { DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { //Create the Document object Document doc = new Document(); foreach (DataColumn dc in dt.Columns) { string check = dc.ToString(); if (check.Equals("Skill_Summary")) { doc.Add(new Field(dc.ColumnName, dr[dc.ColumnName].ToString(), Field.Store.YES, Field.Index.ANALYZED)); } if (check.Equals("Title")) { doc.Add(new Field(dc.ColumnName, dr[dc.ColumnName].ToString(), Field.Store.YES, Field.Index.ANALYZED)); } } // Write the Document to the catalog indexWriter.AddDocument(doc); } } } // Close the writer indexWriter.Close(); }

C# 如何在Lucene.Net中使用空格分析器和小写过滤器创建自己的分析器? 在我的例子中,我需要搜索C类、.NET、C++等关键字,在这里标准分析器会输出特殊字符,所以我使用空白分析程序,对我来说不起作用。 编制索引时: public void Indexing(DataSet ds) { string indexFileLocation = @"D:\Lucene.Net\Data"; Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation, true); IndexWriter indexWriter = new IndexWriter(dir, new WhitespaceAnalyzer(), Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED); if (ds.Tables[0] != null) { DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { //Create the Document object Document doc = new Document(); foreach (DataColumn dc in dt.Columns) { string check = dc.ToString(); if (check.Equals("Skill_Summary")) { doc.Add(new Field(dc.ColumnName, dr[dc.ColumnName].ToString(), Field.Store.YES, Field.Index.ANALYZED)); } if (check.Equals("Title")) { doc.Add(new Field(dc.ColumnName, dr[dc.ColumnName].ToString(), Field.Store.YES, Field.Index.ANALYZED)); } } // Write the Document to the catalog indexWriter.AddDocument(doc); } } } // Close the writer indexWriter.Close(); },c#,lucene,lucene.net,C#,Lucene,Lucene.net,并搜索字段,如: string[] searchfields = new string[] { "Skill_Summary", "Title" }; var parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, searchfields, new WhitespaceAnalyzer()); string searchText = "C#"; //Split the search string into s

并搜索字段,如:

string[] searchfields = new string[] { "Skill_Summary", "Title" };
var parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, searchfields, new WhitespaceAnalyzer());
string searchText = "C#";

//Split the search string into separate search terms by word
string[] terms = searchText.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
foreach (string term in terms)
{
    finalQuery.Add(parser.Parse(term.Replace("*", "") + "*"), BooleanClause.Occur.MUST);
}
hits = searcher.Search(finalQuery);
在我的例子中,如何使用空格分析器和小写过滤器构建自己的分析器

在我的例子中,如何使用空格分析器和小写过滤器构建自己的分析器

公共类CaseInsensitiveWhitespaceAnalyzer:Analyzer
{
/// 
/// 
公共覆盖令牌流令牌流(字符串字段名,文本阅读器)
{
令牌流t=null;
t=新的空白标记符(读取器);
t=新的小写过滤器(t);
返回t;
}
}

PS:当您使用通配符(
*
)时,查询解析器不使用任何分析器,只使用术语的小写形式(取决于QueryParser.LowercaseExpandedTerms的值)

谢谢@I4V,它通过在技能摘要周围留出空格(如{e:C#,.Net,java.}非常有效,但是用户插入了如下数据{例如:C#,.net,java}(不带空格),我需要向用户视图显示准确的短语,所以我需要按(,)拆分和搜索单词,这是可能的吗?代替空格标记符,您可以尝试小写标记符或标准标记符,这里是另一种选择
public class CaseInsensitiveWhitespaceAnalyzer : Analyzer
{
    /// <summary>
    /// </summary>
    public override TokenStream TokenStream(string fieldName, TextReader reader)
    {
        TokenStream t = null;
        t = new WhitespaceTokenizer(reader);
        t = new LowerCaseFilter(t);

        return t;
    }
}