Lucene - Wildcards in phrases

前端 未结 7 929
小鲜肉
小鲜肉 2021-01-04 11:50

I am currently attempting to use Lucene to search data populated in an index.

I can match on exact phrases by enclosing it in brackets (i.e. \"Processing Documents\"

7条回答
  •  醉梦人生
    2021-01-04 12:05

    I was also looking for the same thing and what i found is PrefixQuery gives u a combination of some thing like this "Processing Document*".But the thing is your field which you are searching for should be untokenized and store it in lowercase (reason for so since it is untokenized indexer wont save your field values in lowercase) for this to work.Here is code for PrefixQuery which worked for me :-

    List results = new List();
    Lucene.Net.Store.Directory searchDir = FSDirectory.GetDirectory(this._indexLocation, false);
    IndexSearcher searcher = new IndexSearcher( searchDir );
    Hits hits;
    
    BooleanQuery query = new BooleanQuery();
    query.Add(new PrefixQuery(new Term(FILE_NAME_KEY, keyWords.ToLower())), BooleanClause.Occur.MUST);
    hits = searcher.Search(query);
    this.FillResults(hits, results);
    

提交回复
热议问题