You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@lucene.apache.org by and999 <pa...@rambler.ru> on 2008/04/04 15:00:23 UTC

Problem with Russian Language in Lucene 2.0.0.4

Hi all!
I am indexing Russian text with that code. I have a problem, when I try to
search for words in different cases.
Search is productive, only if the word is in the same form, as in the
initial (indexing) text. Help me please.
(Whether there can be it because Words in RussianStemmer.cs are stored in
the coding KOI8-r?)
versions: Lucene.Net 2.0.0.4, Snowball.Net 2.0.0.1 

using System;
using System.Collections.Generic;
using System.Text;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Analysis.Snowball;
using Lucene.Net.Search;
using Lucene.Net.QueryParsers;
using System.Text.RegularExpressions;
using Lucene.Net.Analysis;

class Program
    {
        static void Main(string[] args)
        {
            string index_path = @"D:\index\";
            System.IO.StreamReader reader;
            reader = new System.IO.StreamReader(new
System.IO.FileStream(@"d:\source\67165.html", System.IO.FileMode.Open,
System.IO.FileAccess.Read), System.Text.Encoding.Default);
            reader = new System.IO.StreamReader(reader.BaseStream,
reader.CurrentEncoding);
            String title = Regex.Replace(reader.ReadLine(), "<[^>]*>", "");
            String fullText = Regex.Replace(reader.ReadToEnd(), "<[^>]*>",
"");
            Document doc = new Document();
            doc.Add(new Field("message_title", title, Field.Store.YES,
Field.Index.TOKENIZED));
            doc.Add(new Field("message_text", fullText, Field.Store.NO,
Field.Index.TOKENIZED));
            Analyzer a = new SnowballAnalyzer("Russian");
            bool create_key = true;
            IndexWriter iw = new IndexWriter(index_path, a, create_key);
            iw.AddDocument(doc);
            iw.Optimize();
            iw.Close();
            
            String query_string = "Якутия";
            Search(query_string, index_path);
            query_string = "Якутии";
            Search(query_string, index_path);
            query_string = "туристы";
            Search(query_string, index_path);
            query_string = "туристов";
            Search(query_string, index_path);
            Console.ReadKey();
        }
        static void Search(string query_string, string index_path)
        {
            Searcher search = new IndexSearcher(index_path);
            Analyzer a = new SnowballAnalyzer("Russian");
            QueryParser parser = new QueryParser("message_text", a);
            Query q = parser.Parse(query_string);
            Hits hits = search.Search(q);
            string[] result = new string[0];
            if (hits.Length() > 0)
            {
                result = new string[hits.Length()];
                for (int i = 0; i < hits.Length(); i++)
                {
                    result[i] =
hits.Doc(i).GetField("message_title").StringValue();
                    Console.WriteLine("\n{0}. {1}\n", i + 1, result[i]);
                }
            }
            else
            {
                Console.WriteLine("\n Missing Search!!!\n");
            }
        }
    }


Russian text example (for indexing):
"Группе туристов в Якутии требуется срочная эвакуация 
radiomayak.ru 
ЧП в Якутии. Снежная лавина накрыла группу туристов. Двое погибли, один
пострадал. Об этом "Маяку" по телефону сообщил официальный представитель
регионального МЧС Алексей Хлыбов. 
ХЛЫБОВ: 25 марта группа туристов из восьми человек - это жители города
Казани и города Екатеринбурга, совершающие лыжный переход, попала под лавину
на перевале Агидель с западной стороны горы.
В 11:40 от группы поступило сообщение спасателям о том, что пострадавшие и
двое погибших были извлечены из-под снега. Группе требуется срочная
эвакуация. В 12:30 из города Якутска запланирован вылет группы спасателей
для эвакуации пострадавшей группы туристов."
-- 
View this message in context: http://www.nabble.com/Problem-with-Russian-Language-in-Lucene-2.0.0.4-tp16491424p16491424.html
Sent from the Lucene - General mailing list archive at Nabble.com.