You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by Kieran Logan <ki...@roleconnect.com> on 2011/09/30 17:45:36 UTC
[Lucene.Net] Suggestions on indexing and searching an unusual requirement
Hi All
I have a series of documents to index and search and could do with some
pointers on how best to achieve the desired results.
The process flow is relatively straightforward, a queue of documents already
exists. The application will pick the next document is a folder queue,
initially index the single document in a RAMDirectory(), display the
document to the user for adjustment and once the user selects 'Save' the
amended document will be committed to a Lucene FSDirectory index. (I'm
glossing over a few details here and I'm aware of what needs to be done with
IndexWriter and various indexes, locks etc).
The document has various parts which will become fields, as follows:
Document ID
Title
Introduction
Paragraph1 .... ParagraphN. There may be anything from 1 paragraph to N
paragraphs, 40 paragraphs is generally towards the maximum. Each paragraph
has a specific purpose and will have its own field for search purposes i.e.
it may be required later to search paragraph 3 in all documents for a given
term. So, for example, legal precedents and cases which the document may
refer to will always be in paragraph 3 and only in paragraph 3.
Conclusion
Keyword(s) again keyword1 ... keyword
Once the initial indexing has been done to RAMDirectory(), I would like to
show the user how many instances of the keyword terms are contained in the
document in total (Title, Introduction, Paragraph(s), Conclusion) - for
example, C#(46), VB.Net(14), ASP(22), JQuery(11). Also, it would be really
useful if feasible, to show other terms from the total document which the
user could add to the Keywords or ignore e.g. Microsoft(88) Google(109) etc.
(I used developer terms rather than the actual application use case as
hopefully everyone would be familiar with the examples).
Bonus (great if anyone would like to answer but I'm reasonably ok with
this):
When search the entire document for keywords, I will also be using synonyms
so in the example above if the keyword is "Java" and the document (title,
introduction, para1...n, conclusion) mentions "Java" twice, JavaBeans once,
J2EE six times then the total count will show as Java(9). I have already
developed a technical synonym dictionary rather than using wordnet or
alternatives so covered for creating the synonym terms).
Many thanks in advance and hopefully the example above is reasonably self
explanatory
Kieran Logan
Newbie on Lucene with visualBasic
Posted by Ralf Jantschek <ra...@ntschek.de>.
Hello,
can anyone point me to a hands on tutorial or documentation on how to
implement Lucene with VB?
I found various things using C# but couldn't get them to work under VB.
Thanks in advance
Ralf
AW: Newbie on Lucene with visualBasic
Posted by Ralf Jantschek <ra...@ntschek.de>.
Hi Anders,
what am I trying to achieve?
Well, nothing more than to write an application where I can search
previously indexed documents.
Hope this helps.
Unfortunately your snippet did not.
Ralf
-----Ursprüngliche Nachricht-----
Von: Anders Lybecker [mailto:anders@lybecker.com]
Gesendet: Samstag, 7. April 2012 19:35
An: lucene-net-user@lucene.apache.org
Betreff: Re: Newbie on Lucene with visualBasic
Hi Ralf,
You are not giving us much to work with.... What are you trying to archive?
Here is a simple rewrite of a C# program (I'm not sure it compiles, as I
don't have the VB.Net compiler)
Imports Lucene.Net.Analysis;
Imports Lucene.Net.Analysis.Standard;
Imports Lucene.Net.Documents;
Imports Lucene.Net.Index;
Imports Lucene.Net.QueryParsers;
Imports Lucene.Net.Search;
Imports Lucene.Net.Store;
Dim version = Lucene.Net.Util.Version.LUCENE_29;
Dim dir = new RAMDirectory();
Dim analyzer = new StandardAnalyzer(version);
-- Add content to the index
Dim indexWriter = new IndexWriter(dir, analyzer,
IndexWriter.MaxFieldLength.UNLIMITED);
Dim docs = new Document[3];
docs[0] = new Document();
docs[0].Add(new Field("id", "0", Field.Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS));
docs[0].Add(new Field("name", "Anders Lybecker",
Field.Store.YES, Field.Index.ANALYZED));
indexWriter.Commit();
indexWriter.Close();
-- Search for the content
Dim parser = new MultiFieldQueryParser(version, new[] {
"biography" }, analyzer);
Dim q = parser.Parse("Anders");
Dim searcher = new IndexSearcher(dir, true);
Dim hits = searcher.Search(q, null, 5, Sort.RELEVANCE);
Console.WriteLine("Found {0} document(s) that matched query
'{1}':", hits.totalHits, q);
For Each match As ScoreDoc In hits.scoreDocs
Dim doc = searcher.Doc(match.doc);
Console.WriteLine("Matched id = {0}, Name = {1}",
doc.Get("id"), doc.Get("name"));
Next match
searcher.Close();
:-)
Anders Lybecker
On Fri, Apr 6, 2012 at 4:32 PM, Ralf Jantschek <ra...@ntschek.de> wrote:
> Hello,
>
> can anyone point me to a hands on tutorial or documentation on how to
> implement Lucene with VB?
> I found various things using C# but couldn't get them to work under VB.
>
> Thanks in advance
>
> Ralf
>
>
>
Re: AW: Newbie on Lucene with visualBasic
Posted by João Prado <jo...@gmail.com>.
Why don't you use a conversion tool like this
http://www.developerfusion.com/tools/convert/csharp-to-vb/ to convert
the c# examples to VB.Net.
The methods used in c# are the pretty same in VB, what changes is just
the sintax.
John
Em 08/04/2012 10:15, Ralf Jantschek escreveu:
> Hi Anders,
> what am I trying to achieve?
>
> Well, nothing more than to write an application where I can search
> previously indexed documents.
>
> Hope this helps.
> Unfortunately your snippet did not.
>
> Ralf
>
> -----Ursprüngliche Nachricht-----
> Von: Anders Lybecker [mailto:anders@lybecker.com]
> Gesendet: Samstag, 7. April 2012 19:35
> An: lucene-net-user@lucene.apache.org
> Betreff: Re: Newbie on Lucene with visualBasic
>
> Hi Ralf,
>
> You are not giving us much to work with.... What are you trying to archive?
>
> Here is a simple rewrite of a C# program (I'm not sure it compiles, as I
> don't have the VB.Net compiler)
>
> Imports Lucene.Net.Analysis;
> Imports Lucene.Net.Analysis.Standard;
> Imports Lucene.Net.Documents;
> Imports Lucene.Net.Index;
> Imports Lucene.Net.QueryParsers;
> Imports Lucene.Net.Search;
> Imports Lucene.Net.Store;
>
> Dim version = Lucene.Net.Util.Version.LUCENE_29;
>
> Dim dir = new RAMDirectory();
> Dim analyzer = new StandardAnalyzer(version);
>
> -- Add content to the index
> Dim indexWriter = new IndexWriter(dir, analyzer,
> IndexWriter.MaxFieldLength.UNLIMITED);
>
>
> Dim docs = new Document[3];
>
> docs[0] = new Document();
> docs[0].Add(new Field("id", "0", Field.Store.YES,
> Field.Index.NOT_ANALYZED_NO_NORMS));
> docs[0].Add(new Field("name", "Anders Lybecker",
> Field.Store.YES, Field.Index.ANALYZED));
>
> indexWriter.Commit();
> indexWriter.Close();
>
>
> -- Search for the content
> Dim parser = new MultiFieldQueryParser(version, new[] {
> "biography" }, analyzer);
> Dim q = parser.Parse("Anders");
>
>
> Dim searcher = new IndexSearcher(dir, true);
>
> Dim hits = searcher.Search(q, null, 5, Sort.RELEVANCE);
>
> Console.WriteLine("Found {0} document(s) that matched query
> '{1}':", hits.totalHits, q);
> For Each match As ScoreDoc In hits.scoreDocs
> Dim doc = searcher.Doc(match.doc);
>
> Console.WriteLine("Matched id = {0}, Name = {1}",
> doc.Get("id"), doc.Get("name"));
> Next match
>
> searcher.Close();
>
>
> :-)
> Anders Lybecker
>
> On Fri, Apr 6, 2012 at 4:32 PM, Ralf Jantschek<ra...@ntschek.de> wrote:
>
>> Hello,
>>
>> can anyone point me to a hands on tutorial or documentation on how to
>> implement Lucene with VB?
>> I found various things using C# but couldn't get them to work under VB.
>>
>> Thanks in advance
>>
>> Ralf
>>
>>
>>
>
Re: Newbie on Lucene with visualBasic
Posted by Anders Lybecker <an...@lybecker.com>.
Hi Ralf,
You are not giving us much to work with.... What are you trying to archive?
Here is a simple rewrite of a C# program (I'm not sure it compiles, as I
don't have the VB.Net compiler)
Imports Lucene.Net.Analysis;
Imports Lucene.Net.Analysis.Standard;
Imports Lucene.Net.Documents;
Imports Lucene.Net.Index;
Imports Lucene.Net.QueryParsers;
Imports Lucene.Net.Search;
Imports Lucene.Net.Store;
Dim version = Lucene.Net.Util.Version.LUCENE_29;
Dim dir = new RAMDirectory();
Dim analyzer = new StandardAnalyzer(version);
-- Add content to the index
Dim indexWriter = new IndexWriter(dir, analyzer,
IndexWriter.MaxFieldLength.UNLIMITED);
Dim docs = new Document[3];
docs[0] = new Document();
docs[0].Add(new Field("id", "0", Field.Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS));
docs[0].Add(new Field("name", "Anders Lybecker",
Field.Store.YES, Field.Index.ANALYZED));
indexWriter.Commit();
indexWriter.Close();
-- Search for the content
Dim parser = new MultiFieldQueryParser(version, new[] {
"biography" }, analyzer);
Dim q = parser.Parse("Anders");
Dim searcher = new IndexSearcher(dir, true);
Dim hits = searcher.Search(q, null, 5, Sort.RELEVANCE);
Console.WriteLine("Found {0} document(s) that matched query
'{1}':", hits.totalHits, q);
For Each match As ScoreDoc In hits.scoreDocs
Dim doc = searcher.Doc(match.doc);
Console.WriteLine("Matched id = {0}, Name = {1}",
doc.Get("id"), doc.Get("name"));
Next match
searcher.Close();
:-)
Anders Lybecker
On Fri, Apr 6, 2012 at 4:32 PM, Ralf Jantschek <ra...@ntschek.de> wrote:
> Hello,
>
> can anyone point me to a hands on tutorial or documentation on how to
> implement Lucene with VB?
> I found various things using C# but couldn't get them to work under VB.
>
> Thanks in advance
>
> Ralf
>
>
>