Terms are stored sorted in the index. So you cannot avoid this sort. You cannot also use any other criteria to sort since they are not search results, just unique terms of your documents stored in the index.
DIGY. -----Original Message----- From: Eric Svensson [mailto:[email protected]] Sent: Thursday, July 30, 2009 2:23 PM To: [email protected] Subject: Re: Search autocomplete/suggestion List<string> items = new List<string>(); Lucene.Net.Store.RAMDirectory ramDir = new Lucene.Net.Store. RAMDirectory(LUCENE_INDEX_PATH); Lucene.Net.Index.IndexReader reader = IndexReader.Open(ramDir); Lucene.Net.Index.TermEnum tEnum = reader.Terms(new Lucene.Net.Index.Term( "title", prefix)); int k = 0; while (tEnum.Next()) { if (!tEnum.Term().Text().StartsWith(prefix)) break; if(k++ >= count) break; items.Add(tEnum.Term().Text()); } The above code give me correct results, but unfortunately, it sorts the results by field. Is it possible to avoid this sort or is it possible to order by an other field? On Wed, Jul 29, 2009 at 5:33 PM, Digy <[email protected]> wrote: > Assuming that you store the URLs untokenized you can use TermEnum like > below: > > > > Lucene.Net.Index.IndexReader rdr = > Lucene.Net.Index.IndexReader.Open(INDEX); > > > > string field = "URL"; > > string prefix = "go"; > > > > Lucene.Net.Index.TermEnum tEnum = rdr.Terms( new > Lucene.Net.Index.Term(field,prefix) ); > > while(tEnum.Next()) > > { > > if(! tEnum.Term().Text().StartsWith(prefix) ) break; > > Console.WriteLine( tEnum.Term().Text() ); > > } > > > > > > DIGY > > > > -----Original Message----- > From: Eric Svensson [mailto:[email protected]] > Sent: Wednesday, July 29, 2009 3:16 PM > To: [email protected] > Subject: Search autocomplete/suggestion > > > > I would like to implement automatic phrase suggestion as one type in the > > searchfield. I have tried different Lucene.net quries without any luck. > > The functionality I would like is simialr to the SQL Like % method. > > > > For instance, if one types "g", "go", "goo", "goog"... I would like " > > google.com" in the search result, but I don't want "docs.google.com". > > My main problem is that Lucene.net is searching by terms and I can't figure > > out how to force it to exclude "docs.google.com" from the results. > >
