Permalink
Browse files

[monkeydoc] Use Lucene.Net via a submodule set on their 3.0.3 release

  • Loading branch information...
1 parent 2f278f2 commit 9b093e08b3dabdb7dbe7ffdc69cd814473b72b0d @garuma garuma committed Nov 28, 2012
@@ -6,7 +6,7 @@
using System.Collections.Generic;
using Mono.Utilities;
-using Mono.Lucene.Net.Index;
+using Lucene.Net.Index;
namespace MonkeyDoc
{
@@ -10,8 +10,8 @@
using System.Xml;
using MonkeyDoc.Providers;
-using Mono.Lucene.Net.Analysis.Standard;
-using Mono.Lucene.Net.Index;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.Index;
namespace MonkeyDoc
{
@@ -448,16 +448,19 @@ public void GenerateSearchIndex ()
Console.WriteLine ("Loading the monodoc tree...");
string text = Path.Combine (this.basedir, "search_index");
IndexWriter indexWriter;
+ var analyzer = new StandardAnalyzer (Lucene.Net.Util.Version.LUCENE_CURRENT);
+ var directory = Lucene.Net.Store.FSDirectory.Open (text);
+
try {
if (!Directory.Exists (text))
Directory.CreateDirectory (text);
- indexWriter = new IndexWriter (Mono.Lucene.Net.Store.FSDirectory.GetDirectory (text, true), new StandardAnalyzer (), true);
+ indexWriter = new IndexWriter (directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
} catch (UnauthorizedAccessException) {
try {
text = Path.Combine (ConfigurationManager.AppSettings["docDir"], "search_index");
if (!Directory.Exists (text))
Directory.CreateDirectory (text);
- indexWriter = new IndexWriter (Mono.Lucene.Net.Store.FSDirectory.GetDirectory (text, true), new StandardAnalyzer (), true);
+ indexWriter = new IndexWriter (directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
} catch (UnauthorizedAccessException) {
Console.WriteLine ("You don't have permissions to write on " + text);
return;
@@ -4,7 +4,7 @@
//
// Author: Mario Sopena
//
-using Mono.Lucene.Net.Documents;
+using Lucene.Net.Documents;
namespace MonkeyDoc
{
@@ -9,12 +9,13 @@
using System.IO;
using System.Collections;
// Lucene imports
-using Mono.Lucene.Net.Index;
-using Mono.Lucene.Net.Documents;
-using Mono.Lucene.Net.Analysis;
-using Mono.Lucene.Net.Analysis.Standard;
-using Mono.Lucene.Net.Search;
-using Mono.Lucene.Net.QueryParsers;
+using Lucene.Net.Index;
+using Lucene.Net.Documents;
+using Lucene.Net.Analysis;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.Search;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Store;
namespace MonkeyDoc
{
@@ -38,7 +39,9 @@ public class SearchableIndex
s.dir = dir;
s.Results = new ArrayList (20);
try {
- s.searcher = new IndexSearcher (dir);
+ //s.searcher = new IndexSearcher (dir);
+ // TODO: parametrize that depending if we run on the desktop (low footprint) or the server (use RAMDirectory for instance)
+ s.searcher = new IndexSearcher (FSDirectory.Open (dir));
} catch (IOException) {
Console.WriteLine ("Index nonexistent or in bad format");
return null;
@@ -66,17 +69,17 @@ public Result Search (string term, int count)
Term htTerm = new Term ("hottext", term);
Query qq1 = new FuzzyQuery (htTerm);
Query qq2 = new TermQuery (htTerm);
- qq2.SetBoost (10f);
+ qq2.Boost = 10f;
Query qq3 = new PrefixQuery (htTerm);
- qq3.SetBoost (10f);
+ qq3.Boost = 10f;
DisjunctionMaxQuery q1 = new DisjunctionMaxQuery (0f);
q1.Add (qq1);
q1.Add (qq2);
q1.Add (qq3);
Query q2 = new TermQuery (new Term ("text", term));
- q2.SetBoost (3f);
+ q2.Boost = 3f;
Query q3 = new TermQuery (new Term ("examples", term));
- q3.SetBoost (3f);
+ q3.Boost = 3f;
DisjunctionMaxQuery q = new DisjunctionMaxQuery (0f);
q.Add (q1);
@@ -101,7 +104,7 @@ TopDocs SearchInternal (Query q, int count, int start)
return searcher.Search (q, count);
var weight = searcher.CreateWeight (q); // TODO: reuse weight instead of query
- var collector = TopScoreDocCollector.create (start + count + 1, weight.ScoresDocsOutOfOrder());
+ var collector = TopScoreDocCollector.Create (start + count + 1, false);
searcher.Search (q, collector);
return collector.TopDocs (start, count);
@@ -113,7 +116,7 @@ public Result FastSearch (string term, int number)
term = term.ToLower ();
Query q1 = new TermQuery (new Term ("hottext", term));
Query q2 = new PrefixQuery (new Term ("hottext", term));
- q2.SetBoost (0.5f);
+ q2.Boost = 0.5f;
DisjunctionMaxQuery q = new DisjunctionMaxQuery (0f);
q.Add (q1);
q.Add (q2);
@@ -127,9 +130,9 @@ public Result FastSearch (string term, int number)
Query Parse (string term, string field, bool fuzzy)
{
- QueryParser parser = new QueryParser (Mono.Lucene.Net.Util.Version.LUCENE_CURRENT,
+ QueryParser parser = new QueryParser (Lucene.Net.Util.Version.LUCENE_CURRENT,
field,
- new StandardAnalyzer (Mono.Lucene.Net.Util.Version.LUCENE_CURRENT));
+ new StandardAnalyzer (Lucene.Net.Util.Version.LUCENE_CURRENT));
return parser.Parse (term);
}
}
@@ -150,7 +153,7 @@ public class Result {
}
public Document this [int i] {
- get { return searcher.Doc (docs[i].doc); }
+ get { return searcher.Doc (docs[i].Doc); }
}
public string GetTitle (int i)
@@ -173,7 +176,7 @@ public string GetFullTitle (int i)
public float Score (int i)
{
- return docs[i].score;
+ return docs[i].Score;
}
public Result (string Term, Searcher searcher, ScoreDoc[] docs)
@@ -17,8 +17,8 @@
using System.Xml.Linq;
using System.Collections.Generic;
-using Mono.Lucene.Net.Index;
-using Mono.Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Documents;
using Monkeydoc.Ecma;
using Mono.Utilities;
@@ -17,8 +17,8 @@
using System.Xml.Xsl;
using System.Xml;
using System.Collections.Generic;
-using Mono.Lucene.Net.Index;
-using Mono.Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Documents;
namespace MonkeyDoc.Providers
{
@@ -16,8 +16,8 @@
using System.Xml;
using System.Xml.Serialization;
using System.Linq;
-using Mono.Lucene.Net.Index;
-using Mono.Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Documents;
namespace MonkeyDoc.Providers
{
Oops, something went wrong.

0 comments on commit 9b093e0

Please sign in to comment.