Question

I have a document that is a list of 100 companies in a text file. It's indexed in lucene. It is not stored itself but the vectors are saved. One company in the list is called Apple Inc.

There is another Document with Title "Apple Inc" stored in lucene.

I am successfully able to do a more like this search using the code below. I can find the document in Lucene, and successfully execute a search on both title and content field to find similar documents.

My question is, how do I modify this code so that I can find other documents that have this content in its title. i.e How do I bring up a document with Title Apple.

I would like to search the Content of my selected document vs a specific field (e.g. Title);

 using (IndexSearcher searcher = new IndexSearcher(_Reader))
        {
            TermQuery tquery = new TermQuery(new Term("Oid", oid));
            TopDocs topdocs = searcher.Search(tquery, 1);
            int docId = topdocs.ScoreDocs[0].Doc;
            var moreLikeThis = new Lucene.Net.Search.Similar.MoreLikeThis(_Reader);
            moreLikeThis.Analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
            moreLikeThis.SetFieldNames(fields);
            moreLikeThis.MinWordLen = 2;
            var query = moreLikeThis.Like(docId);
            TopScoreDocCollector collector = TopScoreDocCollector.Create(topCount, true);
            searcher.Search(query, collector);
            ScoreDoc[] hits = collector.TopDocs().ScoreDocs;
            var result = new List<string>();
            for (int i = 0; i < hits.Length; i++)
            {
                docId = hits[i].Doc;
                float score = hits[i].Score;
                if (score > 0.5)
                {
                    Document doc = searcher.Doc(docId);
                    result.Add(doc.Get("Oid"));
                }
            }
            return result;
        }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top