如何在lucene.net中突出显示查询而不是突出显示搜索结果?

时间:2014-02-21 20:00:30

标签: lucene.net proximity lucene-highlighter

我正在寻找这个,但直到现在我找不到任何解决方案。我有一个大型查询与邻近搜索的组合。我需要找出查询中结果的确切位置。例如,查询的一部分是“hospital”~2“readmissio”~2 。现在Lucene检索到正确的文件,其中一个包含正确的值“医院重新入院”,但我如何在查询中突出显示文件中“重新入院”的“readmissio”。 有一些像levenshtein这样的解决方法但是由于大量的检索它是不切实际的,我希望lucene中有一些解决方案可以找出查询中检索数据的位置?请指教。

    string newQueryString = "";
    string querystring = "To determine whether high performing hospitals with low 30 day risk standardized hospital readmissio rates have a lower proportion of readmission";
    string[] tokens = NLP.Tokenize(querystring);
    for (int i = 0; i < tokens.Length; i++)
    {
        string token = tokens[i];
        token = "\"" + token + "\"" + "~" + 2;

        // add token to new string expression
        newQueryString = newQueryString + " " + token;
    }

    query = MultiFieldQueryParser.Parse(Lucene.Net.Util.Version.LUCENE_CURRENT,
    new string[] { newQueryString }
    , new string[] { "TERM" },
    selectedAnalyzer);



    TopDocs tp = indexSearcher.Search(query, 1);
    int max = tp.TotalHits;

    List<Lucene.Net.Documents.Document> ids = new List<Lucene.Net.Documents.Document>();
    TopScoreDocCollector collector = TopScoreDocCollector.Create(max+1, true);
    indexSearcher.Search(query, collector);
    ScoreDoc[] hits = collector.TopDocs().ScoreDocs;
    for (int i = 0; i < hits.Length; i++)
    {

        int docId = hits[i].Doc;
        Lucene.Net.Documents.Document doc = indexSearcher.Doc(docId);
        string concept = doc.GetFieldable("TERM").StringValue;


        string[] contentTerms = NLP.Tokenize(querystring);
        ITermFreqVector tfvector = reader.GetTermFreqVector(docId, "TERM");
        TermPositionVector tpvector = (TermPositionVector)tfvector;

        for (int k = 0; k < contentTerms.Length; k++)
        {
            string[] terms = tfvector.GetTerms();
            int termidx = tfvector.IndexOf(contentTerms[k].Trim()); /// How to have readmission/readmissions here????? 
            int[] termposx = tpvector.GetTermPositions(termidx);
            TermVectorOffsetInfo[] tvoffsetinfo = tpvector.GetOffsets(termidx);

            int offsetStart = 0;
            int offsetEnd = 0;
            List<Tokens> conceptList = new List<Tokens>();
            for (int j = 0; j < tvoffsetinfo.Length; j++)
            {
                offsetStart = tvoffsetinfo[j].StartOffset;
                offsetEnd = tvoffsetinfo[j].EndOffset;
                string key = concept.Substring(offsetStart, offsetEnd - offsetStart);
                //////////////// Code continue////////////////
            }

        }
    }

因为它显示了我如何突出我的查询字符串中的“redamissi”部分的“医院再入院”概念。 ???或者在另一个例子中,如果我在查询中有重新入院,我如何突出显示检索到的“重新录取”或“录取”的值?

0 个答案:

没有答案