Exemplo n.º 1
0
        private static LuceneQuery HandleFuzzyYngpingQuery(string queryText)
        {
            var queryParser = new MultiFieldQueryParser(LuceneUtils.AppLuceneVersion,
                                                        new string[] { LuceneUtils.Fields.Yngping },
                                                        LuceneUtils.GetAnalyzer(),
                                                        new Dictionary <string, float> {
                { LuceneUtils.Fields.Yngping, 100 },
            });

            return(queryParser.Parse(queryText));
        }
Exemplo n.º 2
0
        private void CreateLuceneIndex(YngdiengIndex index)
        {
            var dirInfo = Path.GetFullPath(Path.Join(outputFolder, "lucene"));

            Console.WriteLine($"Writing to {dirInfo}");
            using (var dir = FSDirectory.Open(new DirectoryInfo(dirInfo)))
            {
                var indexConfig = new IndexWriterConfig(LuceneUtils.AppLuceneVersion,
                                                        LuceneUtils.GetAnalyzer());
                using (var writer = new IndexWriter(dir, indexConfig))
                {
                    writer.DeleteAll();
                    foreach (var yDoc in index.YngdiengDocuments)
                    {
                        var doc = new Lucene.Net.Documents.Document {
                            new Int32Field(LuceneUtils.Fields.IsSourceless, yDoc.Sources.Count == 0?1:0, Field.Store.YES),
                            new StringField(LuceneUtils.Fields.DocId, yDoc.DocId, Field.Store.YES),
                            new TextField(LuceneUtils.Fields.Yngping, yDoc.YngpingSandhi, Field.Store.NO),
                            new TextField(LuceneUtils.Fields.Hanzi, yDoc.HanziCanonical.Regular, Field.Store.NO),
                            new StringField(LuceneUtils.Fields.YngpingSandhiTonePattern, GetTonePattern(yDoc.YngpingSandhi), Field.Store.NO)
                        };
                        foreach (var m in yDoc.IndexingExtension.MandarinWords)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.Mandarin, m, Field.Store.NO));
                            doc.Add(new TextField(LuceneUtils.Fields.Mandarin, openCcClient.SimplifyMandarinText(m), Field.Store.NO));
                        }
                        foreach (var a in yDoc.HanziAlternatives)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.HanziAlternative, a.Regular, Field.Store.NO));
                        }
                        // Simplify Hanzi for search
                        doc.Add(new TextField(LuceneUtils.Fields.Hanzi, openCcClient.SimplifyHukziuText(yDoc.HanziCanonical.Regular), Field.Store.NO));
                        foreach (var e in yDoc.IndexingExtension.ExplanationText)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.Explanation, e, Field.Store.NO));
                        }
                        // TODO: encapsulate this in a YngpingAnalyzer
                        foreach (var yp in yDoc.IndexingExtension.YngpingPermutations)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.Yngping, yp, Field.Store.NO));
                        }
                        writer.AddDocument(doc);
                    }
                    writer.Flush(triggerMerge: false, applyAllDeletes: false);
                }
            }
        }
Exemplo n.º 3
0
        private static LuceneQuery HandleHanziQuery(string queryText)
        {
            var queryParser = new MultiFieldQueryParser(
                LuceneUtils.AppLuceneVersion,
                new string[] {
                LuceneUtils.Fields.Mandarin,
                LuceneUtils.Fields.Hanzi,
                LuceneUtils.Fields.HanziAlternative,
                LuceneUtils.Fields.Explanation
            },
                LuceneUtils.GetAnalyzer(),
                new Dictionary <string, float> {
                { LuceneUtils.Fields.Mandarin, 200 },
                { LuceneUtils.Fields.Hanzi, 100 },
                { LuceneUtils.Fields.HanziAlternative, 50 },
                { LuceneUtils.Fields.Explanation, 1 }
            });

            return(queryParser.Parse(queryText));
        }