本文整理汇总了C#中Lucene.Net.Analysis.PerFieldAnalyzerWrapper类的典型用法代码示例。如果您正苦于以下问题:C# PerFieldAnalyzerWrapper类的具体用法?C# PerFieldAnalyzerWrapper怎么用?C# PerFieldAnalyzerWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PerFieldAnalyzerWrapper类属于Lucene.Net.Analysis命名空间,在下文中一共展示了PerFieldAnalyzerWrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAnalyzer
protected override Analyzer GetAnalyzer(Net.Util.Version version)
{
var analyzer = new PerFieldAnalyzerWrapper(base.GetAnalyzer(version));
analyzer.AddAnalyzer("Path", new CaseInsensitiveKeywordAnalyzer());
analyzer.AddAnalyzer("Key", new KeywordAnalyzer());
return analyzer;
}
示例2: InstancePerFieldAnalyzerWrapper
public InstancePerFieldAnalyzerWrapper()
{
var analyzer = new Lucene.Net.Analysis.PerFieldAnalyzerWrapper(new Synonyms.SynonymAnalyzer(new Synonyms.XmlSynonymEngine()));
analyzer.AddAnalyzer("cota", new Lucene.Net.Analysis.KeywordAnalyzer());
analyzer.AddAnalyzer("codigo", new Lucene.Net.Analysis.KeywordAnalyzer());
instancePerFieldAnalyzerWrapper = analyzer;
}
示例3: GetAnalyzer
protected override Analyzer GetAnalyzer(Net.Util.Version version)
{
analyzer = new PerFieldAnalyzerWrapper(base.GetAnalyzer(version));
analyzer.AddAnalyzer<SampleDocument>(t => t.Id, new KeywordAnalyzer());
analyzer.AddAnalyzer<SampleDocument>(t => t.Key, new CaseInsensitiveKeywordAnalyzer());
return analyzer;
}
示例4: SetAnalyzerType
void SetAnalyzerType(Type defaultType, IEnumerable<FieldDetails> fields)
{
if (defaultType == null) {
defaultType = typeof(StandardAnalyzer);
}
// create default analyzer
_defaultAnalyzer = Activator.CreateInstance(defaultType) as Analyzer;
if (_defaultAnalyzer == null) {
throw new ArgumentException("defaultType is not an Analyzer type");
}
var wrapper = new PerFieldAnalyzerWrapper(_defaultAnalyzer);
if (fields != null) {
foreach (var fd in fields) {
if (fd.Field.Analyzer!=null) {
var fieldAnalyzer = CreateAnalyzerFromType(fd.Field.Analyzer);
if (fieldAnalyzer != null) {
wrapper.AddAnalyzer(fd.Name, fieldAnalyzer);
}
}
}
}
Analyzer = wrapper;
}
示例5: InitSearchServiceAnalyzer
private void InitSearchServiceAnalyzer(Type indexingServiceSettingsType, Analyzer defaultAnalyzer, Analyzer textAnalyzer)
{
var perFieldAnalyzerWrapper = new PerFieldAnalyzerWrapper(defaultAnalyzer);
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_ID", new KeywordAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_CULTURE", new KeywordAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_REFERENCEID", new KeywordAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_AUTHORSTORAGE", new KeywordAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_CATEGORIES", new WhitespaceAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_ACL", new WhitespaceAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_VIRTUALPATH", new WhitespaceAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_TYPE", new WhitespaceAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_CREATED", new WhitespaceAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_MODIFIED", new WhitespaceAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_PUBLICATIONEND", new WhitespaceAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_PUBLICATIONSTART", new WhitespaceAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_ITEMSTATUS", new WhitespaceAnalyzer());
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_TITLE", textAnalyzer);
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_DISPLAYTEXT", textAnalyzer);
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_AUTHORS", textAnalyzer);
perFieldAnalyzerWrapper.AddAnalyzer("EPISERVER_SEARCH_DEFAULT", textAnalyzer);
indexingServiceSettingsType
.GetField("_analyzer", BindingFlags.Static | BindingFlags.NonPublic)
.SetValue(null, perFieldAnalyzerWrapper);
}
示例6: btnSearch_Click
private void btnSearch_Click(object sender, EventArgs e)
{
lstResults.Items.Clear();
searcher = new IndexSearcher(new RAMDirectory(_indexTarget));
PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new StandardAnalyzer());
analyzer.AddAnalyzer("ayat_arabic", new DiacriticAnalyzer(FilterData.stopWords));
//MyQueryParser parser = new MyQueryParser(new string[] { "ayat_desc", "ayat_urdu", "ayat_arabic" }, analyzer);
//parser.SetDefaultOperator(QueryParser.Operator.AND);
//Query q = parser.Parse(txtSearch.Text);
//Query q = new TermQuery(new Term("ayatno", NumberTools.LongToString(long.Parse(txtSearch.Text))));
BooleanQuery q = new BooleanQuery();
long l1 = 1; long l2 = 500; long l3 = 1; long l4 = 1;
//RangeQuery rq = new RangeQuery(new Term("ayatno", l1.ToString("00000")), new Term("ayatno", l2.ToString("00000")), true);
//q.Add(rq, true, false);
q.Add(new TermQuery(new Term("sid", l3.ToString("00000"))), true, false);
q.Add(new TermQuery(new Term("ayatno", l4.ToString("00000"))), true, false);
MessageBox.Show(q.ToString());
Sort sort = new Sort(new string[] { "pid", "sid", "ayatno" });
hits = searcher.Search(q, sort);
lblHits.Text = hits.Length() + " hit(s).";
Application.DoEvents();
for (int i = 0; i < hits.Length(); i++)
{
StringBuilder sb = new StringBuilder();
sb.Append("Para: ").Append(hits.Doc(i).Get("pid"));
sb.Append(", Surat: ").Append(hits.Doc(i).Get("sid"));
sb.Append(", Verse: ").Append(hits.Doc(i).Get("ayatno"));
lstResults.Items.Add(sb.ToString());
}
}
示例7: BuildQuery
public static Query BuildQuery(string query, IndexQuery indexQuery, PerFieldAnalyzerWrapper analyzer)
{
var originalQuery = query;
Analyzer keywordAnalyzer = new KeywordAnalyzer();
try
{
var queryParser = new RangeQueryParser(Version.LUCENE_29, indexQuery.DefaultField ?? string.Empty, analyzer)
{
DefaultOperator = indexQuery.DefaultOperator == QueryOperator.Or
? QueryParser.Operator.OR
: QueryParser.Operator.AND,
AllowLeadingWildcard = true
};
query = PreProcessUntokenizedTerms(query, queryParser);
query = PreProcessSearchTerms(query);
query = PreProcessDateTerms(query, queryParser);
var generatedQuery = queryParser.Parse(query);
generatedQuery = HandleMethods(generatedQuery);
return generatedQuery;
}
catch (ParseException pe)
{
if (originalQuery == query)
throw new ParseException("Could not parse: '" + query + "'", pe);
throw new ParseException("Could not parse modified query: '" + query + "' original was: '" + originalQuery + "'", pe);
}
finally
{
keywordAnalyzer.Close();
}
}
示例8: GetAnalyzer
protected override Analyzer GetAnalyzer(Net.Util.Version version)
{
var a = new PerFieldAnalyzerWrapper(base.GetAnalyzer(version));
a.AddAnalyzer("Version", new KeywordAnalyzer());
a.AddAnalyzer("Flag", new KeywordAnalyzer());
return a;
}
示例9: PreProcessUntokenizedTerms
/// <summary>
/// Detects untokenized fields and sets as NotAnalyzed in analyzer
/// </summary>
private static string PreProcessUntokenizedTerms(PerFieldAnalyzerWrapper analyzer, string query, Analyzer keywordAnlyzer)
{
var untokenizedMatches = untokenizedQuery.Matches(query);
if (untokenizedMatches.Count < 1)
{
return query;
}
var sb = new StringBuilder(query);
// KeywordAnalyzer will not tokenize the values
// process in reverse order to leverage match string indexes
for (int i=untokenizedMatches.Count; i>0; i--)
{
Match match = untokenizedMatches[i-1];
// specify that term for this field should not be tokenized
analyzer.AddAnalyzer(match.Groups[1].Value, keywordAnlyzer);
Group term = match.Groups[2];
// remove enclosing "[[" "]]" from term value (again in reverse order)
sb.Remove(term.Index+term.Length-2, 2);
sb.Remove(term.Index, 2);
}
return sb.ToString();
}
示例10: StartEmailIndexing
public void StartEmailIndexing()
{
if (!Directory.Exists(GlobalData.EmailIndexPath))
Directory.CreateDirectory(GlobalData.EmailIndexPath);
IndexWriter index;
PerFieldAnalyzerWrapper pfaw = new PerFieldAnalyzerWrapper(new KeywordAnalyzer());
pfaw.AddAnalyzer("body", new StopAnalyzer());
try
{
index = new IndexWriter(GlobalData.EmailIndexPath, pfaw, false);
}
catch
{
index = new IndexWriter(GlobalData.EmailIndexPath, pfaw, true);
}
const string PopServer = "pop.google.in";
const int PopPort = 995;
const string User = "extendable.search";
const string Pass = "vineelreddy";
using (Pop3Client client = new Pop3Client(PopServer, PopPort, true, User, Pass))
{
client.Trace += new Action<string>(Console.WriteLine);
//connects to Pop3 Server, Executes POP3 USER and PASS
client.Authenticate();
client.Stat();
foreach (Pop3ListItem item in client.List())
{
Document doc = new Document();
MailMessageEx message = client.RetrMailMessageEx(item);
doc.Add(new Field("subject", message.Subject.ToLower(), Field.Store.YES, Field.Index.NO_NORMS));
doc.Add(new Field("from", message.From.ToString().ToLower(), Field.Store.YES, Field.Index.NO_NORMS));
doc.Add(new Field("to", message.To.ToString().ToLower(), Field.Store.YES, Field.Index.NO_NORMS));
//doc.Add(new Field("date", message.DeliveryDate.ToLower(), Field.Store.YES, Field.Index.NO_NORMS));
string code = message.Body;
code = Regex.Replace(code, @"<\s*head\s*>(.|\n|\r)*?<\s*/\s*head\s*>", " ", RegexOptions.Compiled); //repalce <head> section with single whitespace
code = Regex.Replace(code, @"<\s*script (.|\n|\r)*?<\s*/\s*script\s*>", " ", RegexOptions.Compiled);//repalce remaining <script> tags from body with single whitespace
code = Regex.Replace(code, @"<!--(.|\n|\r)*?-->", " ", RegexOptions.Compiled); //repalce comments
code = Regex.Replace(code, @"<(.|\n|\r)*?>", " ", RegexOptions.Compiled); //repalce all tags with single whitespace
code = Regex.Replace(code, @"&.*?;", " ", RegexOptions.Compiled); //replace > e.t.c
code = Regex.Replace(code, @"\s+", " ", RegexOptions.Compiled); //replace multiple whitespaces characters by single whitespace
code = Regex.Replace(code, @"\ufffd", " ", RegexOptions.Compiled);
doc.Add(new Field("body", code.ToLower(), Field.Store.YES, Field.Index.NO_NORMS));
index.AddDocument(doc);
}
client.Noop();
client.Rset();
client.Quit();
index.Optimize();
index.Close();
}
}
示例11: TestPerFieldAnalyzer
public void TestPerFieldAnalyzer()
{
var analyzer = new PerFieldAnalyzerWrapper(new SimpleAnalyzer());
analyzer.AddAnalyzer("partnum", new KeywordAnalyzer());
var query =
new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "description", analyzer)
.Parse("partnum:Q36 AND SPACE");
Assert.AreEqual("+partnum:Q36 +space", query.ToString("description"), "Q36 kept as-is");
Assert.AreEqual(1, searcher.Search(query, searcher.MaxDoc()).ScoreDocs.Length, "docs found!!!");
}
示例12: TestPerFieldAnalyzer
public virtual void TestPerFieldAnalyzer()
{
PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new SimpleAnalyzer());
analyzer.AddAnalyzer("partnum", new KeywordAnalyzer());
QueryParser queryParser = new QueryParser("description", analyzer);
Query query = queryParser.Parse("partnum:Q36 AND SPACE");
ScoreDoc[] hits = searcher.Search(query, null, 1000).scoreDocs;
Assert.AreEqual("+partnum:Q36 +space", query.ToString("description"), "Q36 kept as-is");
Assert.AreEqual(1, hits.Length, "doc found!");
}
示例13: TestPerFieldAnalyzer
public virtual void TestPerFieldAnalyzer()
{
PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new SimpleAnalyzer());
analyzer.AddAnalyzer("partnum", new KeywordAnalyzer());
Lucene.Net.QueryParsers.QueryParser queryParser = new Lucene.Net.QueryParsers.QueryParser("description", analyzer);
Query query = queryParser.Parse("partnum:Q36 AND SPACE");
Hits hits = searcher.Search(query);
Assert.AreEqual("+partnum:Q36 +space", query.ToString("description"), "Q36 kept as-is");
Assert.AreEqual(1, hits.Length(), "doc found!");
}
示例14: TestPerField
public virtual void TestPerField()
{
System.String text = "Qwerty";
PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new WhitespaceAnalyzer());
analyzer.AddAnalyzer("special", new SimpleAnalyzer());
TokenStream tokenStream = analyzer.TokenStream("field", new System.IO.StringReader(text));
Token token = tokenStream.Next();
Assert.AreEqual("Qwerty", token.TermText(), "WhitespaceAnalyzer does not lowercase");
tokenStream = analyzer.TokenStream("special", new System.IO.StringReader(text));
token = tokenStream.Next();
Assert.AreEqual("qwerty", token.TermText(), "SimpleAnalyzer lowercases");
}
示例15: EDSIndexer
public EDSIndexer(string desIndexPath, Analyzer analyser, bool overwriteIndexDir)
{
keywordAnalyzer = analyser;
pfaw = new PerFieldAnalyzerWrapper(analyser);
pfaw.AddAnalyzer("content", stopAnalyzer); //generally for content v use stop analyser
try
{
index = new IndexWriter(desIndexPath, pfaw, overwriteIndexDir);
}
catch
{
index = new IndexWriter(desIndexPath, pfaw, true);
}
}