Tag: lucene

Lucene .NET搜索结果

我正在使用此代码进行索引: public void IndexEmployees(IEnumerable employees) { var indexPath = GetIndexPath(); var directory = FSDirectory.Open(indexPath); var indexWriter = new IndexWriter(directory, new StandardAnalyzer(Version.LUCENE_29), true, IndexWriter.MaxFieldLength.UNLIMITED); foreach (var employee in employees) { var document = new Document(); document.Add(new Field(“EmployeeId”, employee.EmployeeId.ToString(), Field.Store.YES, Field.Index.NO, Field.TermVector.NO)); document.Add(new Field(“Name”, employee.FirstName + ” ” + employee.LastName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO)); document.Add(new Field(“OfficeName”, employee.OfficeName, Field.Store.YES, […]

这个solr查询有什么问题

我想找到与solr中的特定文档类似的所有文档。 我已经安装了solr并提出了一些疑问。 我试图提出的查询给出了一个我无法在互联网上制作或研究的错误。 你能告诉我一些吗? 我正在使用solrnet客户端,但如果solrnet不适合这种类型的查询,我很乐意使用纯solr并读取XML。 这是我正在使用的查询: http://192.168.1.10:8080/solr/mlt?q=id:12&mlt.fl=content&mlt.mindf=1&mlt.mintf=1 这是我的架构xml 这是我收到的错误:

Lucene.net和部分“开头”短语搜索

我正在寻找在大量城市名称上构建一个自动完成的文本框。 搜索function如下:我希望在多词短语中搜索“开始”。 例如,如果用户输入“chicago he”,则只需返回“Chicago Heights”等位置。 我正在尝试使用Lucene。 我在理解如何实施这个问题时遇到了问题。 我已经尝试过我认为应该有效的方法: 我用KeywordAnalyzer索引了位置(我已尝试过TOKENIZED和UN_TOKENIZED): doc.Add(new Field(“Name”, data.ToLower(), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO)); 并通过以下方式搜索它们(我还尝试了各种其他查询/分析器/等): var luceneQuery = new BooleanQuery(); var wildcardQuery = new WildcardQuery(new Term(“Name”, “chicago hei*”)); luceneQuery.Add(wildcardQuery, BooleanClause.Occur.MUST); 我没有得到任何结果。 非常感谢任何建议。

为什么Lucene.Net索引器抛出System.IO.IOException未处理?

有时会抛出exception,说文件write.lock不能被使用,因为它被另一个进程使用,但这是一个非常简单的Lucene.Net测试应用程序,没有其他进程使用它,任何想法如何也许 例外情况如下: System.IO.IOException was unhandled HResult=-2147024864 Message=The process cannot access the file ‘c:\temp\luceneidx\write.lock’ because it is being used by another process. Source=mscorlib StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.InternalDelete(String path, Boolean checkHost) at System.IO.File.Delete(String path) at Lucene.Test.LuceneSearchInternal.get__directory() in C:\Lucene.Test\LuceneSearchResumes.cs:line 35 抛出exception的相关代码是, var lockFilePath = Path.Combine(_luceneDir, “write.lock”); if (File.Exists(lockFilePath)) File.Delete(lockFilePath); // THROWS exception sometimes 代码主要来自这篇文章 […]

如何自定义Lucene.NET以搜索带符号的单词而不区分大小写(例如“C#”或“.net”)?

标准分析仪不起作用。 根据我的理解,它将其更改为搜索c和net WhitespaceAnalyzer可以工作,但它区分大小写。 一般规则是搜索应该像谷歌一样工作,所以希望它是一个配置的东西,考虑.net , c#已经存在一段时间或者有一个解决方法。 根据下面的建议,我尝试了自定义的WhitespaceAnalyzer但是如果关键字用逗号分隔,并且没有正确处理空格,例如 java,.net,c#,oracle 搜索时不会返回不正确的内容。 我遇到了PatternAnalyzer ,它用于分割令牌,但无法弄清楚如何在这种情况下使用它。 我正在使用Lucene.Net 3.0.3和.NET 4.0

如何在Sitecore中配置Lucene以仅索引主数据库上项目的最新版本?

我认识到这是web数据库上的一个有争议的问题,所以这个问题适用于主数据库… 我在Sitecore 6.4.1中设置了自定义索引,如下所示: $(id) _search_content_US master /sitecore/content/usa home home content 我像这样查询索引(我从这个答案中使用了techphoria414的SortableIndexSearchContext : 如何使用新的Sitecore.Search API进行排序/过滤 ): private SearchHits GetSearchResults(SortableIndexSearchContext searchContext, string searchTerm) { CombinedQuery query = new CombinedQuery(); query.Add(new FullTextQuery(searchTerm), QueryOccurance.Must); return searchContext.Search(query, Sort.RELEVANCE); } … SearchHits hits = GetSearchResults(searchContext, searchTerm); hits是我索引中搜索命中的集合。 当我遍历hits我可以看到Sitecore中有相同项目的许多重复项,每个版本的项目有1个。 然后,我执行以下操作以获取SearchResultCollection : SearchResultCollection results = hits.FetchResults(0, hits.Length); 这将所有重复项组合到一个SearchResult对象中。 此对象表示特定项的1个版本,并且具有名为SubResults的属性,该属性是SearchResult的集合,表示所有其他项目版本。 这是我的问题: SearchResult表示的项目版本不是该项目的当前发布版本! 它似乎是一个随机选择的版本(无论搜索方法在索引中首先命中)。 但是,最新版本包含在SubResults集合中。 […]

Lucene – 搜索数值字段

好吧,我在过去的两个小时里搜索过这个结果只给出了提示,甚至没有一个完整的代码来帮助救援(如果他们看不到一些样品,小便会怎么学?) 我创建了一个像这样的索引: Directory directory = FSDirectory.Open(new System.IO.DirectoryInfo(Server.MapPath(“/data/channels/”))); Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29); IndexWriter writer = new IndexWriter(directory, analyzer, true, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED); Document doc = new Document(); doc.Add(new Field(“ID”, “0”, Field.Store.YES, Field.Index.NO)); doc.Add(new Field(“parentID”, “0”, Field.Store.YES, Field.Index.NO)); doc.Add(new Field(“Title”, “Root”, Field.Store.YES, Field.Index.ANALYZED)); writer.AddDocument(doc); writer.Optimize(); writer.Close(); 现在,我想搜索字段ID其中值等于0 (以获得我在那里的单个记录)…. 但是,这样的简单搜索: Directory directory = FSDirectory.Open(new System.IO.DirectoryInfo(Server.MapPath(“/data/channels”))); Analyzer analyzer = new […]

使用通配符搜索进行搜索时,在文档中匹配术语

我正在寻找一种方法,使用Lucene中的waldcard搜索找到文档中匹配的术语。 我使用解释器试图找到条款,但这失败了。 相关代码的一部分如下。 ScoreDoc[] myHits = myTopDocs.scoreDocs; int hitsCount = myHits.Length; for (int myCounter = 0; myCounter < hitsCount; myCounter++) { Document doc = searcher.Doc(myHits[myCounter].doc); Explanation explanation = searcher.Explain(myQuery, myCounter); string myExplanation = explanation.ToString(); … 当我对say *进行搜索时,会找到文档并进入循环,但myExplanation包含NON-MATCH而没有其他信息。 我如何获得本文档中的术语? 非常感激任何的帮助。 问候

更快地从Lucene Query获取不同值的方法

目前我喜欢这样: IndexSearcher searcher = new IndexSearcher(lucenePath); Hits hits = searcher.Search(query); Document doc; List companyNames = new List(); for (int i = 0; i < hits.Length(); i++) { doc = hits.Doc(i); companyNames.Add(doc.Get("companyName")); } searcher.Close(); companyNames = companyNames.Distinct().Skip(offSet ?? 0).ToList(); return companyNames.Take(count??companyNames.Count()).ToList(); 正如你所看到的,我首先收集所有字段(数千个),然后区分它们,可能会跳过一些并取出一些。 我觉得应该有更好的方法来做到这一点。

在ASP.NET MVC站点中使用Lucene.Net进行目录锁定错误

我正在构建一个ASP.NET MVC站点,我想使用Lucene.Net进行搜索。 我已经构建了一个SearchController及其所有方法,但是我在运行时遇到一个错误,这个错误是在首次初始化SearchController时发生的。 在SearchController中,这是我如何创建IndexWriter: public static string IndexLocation = HostingEnvironment.MapPath(“~/lucene”); public static Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(); public static IndexWriter writer = new IndexWriter(IndexLocation,analyzer); 错误发生在最后一行。 这是我得到的信息: Lucene.Net.Store.LockObtainFailedException: Lock获取超时 :SimpleFSLock @ C:\ Users \ Username \ Desktop \ SiteSolution \ Site \ lucene \ write.lock 此外,这是堆栈跟踪: [LockObtainFailedException: Lock obtain timed out: SimpleFSLock@C:\Users\Username\Desktop\SiteSolution\Site\lucene\write.lock] Lucene.Net.Store.Lock.Obtain(Int64 lockWaitTimeout) in C:\Users\Username\Desktop\Lucene.Net_2_9_2\src\Lucene.Net\Store\Lock.cs:107 […]