lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pamela Foxcroft" <pamelafoxcr...@gmail.com>
Subject how do I get the multisearcher to work.
Date Wed, 24 May 2006 16:16:03 GMT
I keep on getting this message. We are using 1.9 RC2. Item has already been
added. Key in dictionary: 'text:horse' Key being added: 'text:horse'

Here is my code - this is based on the lucene in action book.


using System;
using System.Collections.Generic;
using System.Text;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Search;
using Lucene.Net.QueryParsers;
using Lucene.Net.Store;
using Lucene.Net.Index;
using Lucene.Net.Documents;

namespace MultiSearcher
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] animals ={
"aardvark","beaver","coati","dog","elephant","frog","gila
monster","horse","iguana",

"javelina","kangaroo","lemur","moose","nematode","orca","python","quokka","rat","scorpian","trrantula",
                "uramstyx","vicuna","walrus","Xuphias","yak","zebra"};

            Analyzer analyzer = new WhitespaceAnalyzer();

            Directory aTOmDirectory = new RAMDirectory();
            Directory nTOzDirectory = new RAMDirectory();

            IndexWriter aToMWriter = new IndexWriter(aTOmDirectory,
analyzer, true);
            IndexWriter nToZWriter = new IndexWriter(nTOzDirectory,
analyzer, true);

            for (int i = 0; i < animals.Length; i++)
            {
                Document doc = new Document();
                String animal = animals[i];

                doc.Add(Field.Text("text",animal.ToString()));
            if (i<10)
            {
                aToMWriter.AddDocument(doc);
            }
            else
            {

                nToZWriter.AddDocument(doc);
            }

            }
            aToMWriter.Close();
            nToZWriter.Close();

            IndexSearcher[] searchers = new IndexSearcher[2];
            searchers[0] = new IndexSearcher(aTOmDirectory);
            searchers[1] = new IndexSearcher(nTOzDirectory);

            MultiSearcher searcher = new MultiSearcher(searchers);

            Query query = QueryParser.Parse("horse","text" , new
StandardAnalyzer());
           Console.WriteLine("Query: " + query.ToString());
            Hits hits = searcher.Search(query);
 Console.Write("end");
        }
    }
}



thanks



Pam

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message