This thread is getting big... Franklin, I totally agree this approach can result in a problem, but I don't know yet how to do this search with TermEnum. What is the basic documentation to learn (I mean really learn, with all different query types) about queries?
Thank's "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo: És verdadeiramente o Filho de Deus." (Mateus 14:33) On Tue, Nov 3, 2009 at 13:33, Franklin Simmons <fsimm...@sccmediaserver.com>wrote: > André, > > You can pass null for the filter parameter. TopDocCollector and > TopFieldDocCollector lets you limit hits. I have to say that while this > approach may seem OK with a very small index it will become a major problem > for you as index size grows, because MatchAllDocsQuery results in a sorting > of all documents in the index having the sort field. You should heed the > advice offered by Digy earlier in this discussion to use TermEnum. > > > -----Original Message----- > From: André Maldonado [mailto:andre.maldon...@gmail.com] > Sent: Tuesday, November 03, 2009 8:50 AM > To: lucene-net-user@incubator.apache.org > Subject: Re: Simple question > > When I do: > > Hits hits = searcher.Search(new *MatchAllDocsQuery()*, sort); > > The searcher return all documents. Can I return only the first 5 documents? > Like a TOP 5 in SQL Server? > > Probably using searcher.Search(Query query, Filter filter, int n, Sort > sort) > I can do it, but I don't have a filter.. > > How can I do it? > > Thank's > > > "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo: És > verdadeiramente o Filho de Deus." (Mateus 14:33) > > > 2009/11/3 André Maldonado <andre.maldon...@gmail.com> > > > Franklin, the error was exactly that. > > > > Some documents had a string where only an int can be. After made some > code > > adjustment, reindexing everything made it work. > > > > > > Thank's > > > > "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo: És > > verdadeiramente o Filho de Deus." (Mateus 14:33) > > > > > > On Fri, Oct 30, 2009 at 18:19, Franklin Simmons < > > fsimm...@sccmediaserver.com> wrote: > > > >> What type of data is represented by your field? > >> > >> There are any number of reasons why this could happen, such as using > >> SortField.INT on a field with terms having non-digit characters. > >> > >> Without knowing specifics, I can only offer that you try > SortField.STRING. > >> > >> -----Original Message----- > >> From: André Maldonado [mailto:andre.maldon...@gmail.com] > >> Sent: Friday, October 30, 2009 3:47 PM > >> To: lucene-net-user@incubator.apache.org > >> Subject: Re: Simple question > >> > >> Hi again Franklin. > >> > >> Sorry, but didn't work. I'm using Lucene.net 2.3 and doing exactly what > >> you > >> said, I'm getting this error: > >> > >> System.FormatException: Input string was not in correct format. > >> em System.Number.StringToNumber(String str, NumberStyles options, > >> NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) > >> em System.Number.ParseInt32(String s, NumberStyles style, > >> NumberFormatInfo info) > >> em > >> Lucene.Net.Search.FieldCacheImpl.AnonymousClassIntParser.ParseInt(String > >> value_Renamed) > >> em > >> > >> > Lucene.Net.Search.FieldCacheImpl.AnonymousClassCache2.CreateValue(IndexReader > >> reader, Object entryKey) > >> em Lucene.Net.Search.FieldCacheImpl.Cache.Get(IndexReader reader, > Object > >> key) > >> em Lucene.Net.Search.FieldCacheImpl.GetInts(IndexReader reader, String > >> field, IntParser parser) > >> em Lucene.Net.Search.FieldCacheImpl.GetInts(IndexReader reader, String > >> field) > >> em Lucene.Net.Search.FieldSortedHitQueue.ComparatorInt(IndexReader > >> reader, String fieldname) > >> em > >> > >> > Lucene.Net.Search.FieldSortedHitQueue.AnonymousClassCache.CreateValue(IndexReader > >> reader, Object entryKey) > >> em Lucene.Net.Search.FieldCacheImpl.Cache.Get(IndexReader reader, > Object > >> key) > >> em > Lucene.Net.Search.FieldSortedHitQueue.GetCachedComparator(IndexReader > >> reader, String field, Int32 type, CultureInfo locale, > SortComparatorSource > >> factory) > >> em Lucene.Net.Search.FieldSortedHitQueue..ctor(IndexReader reader, > >> SortField[] fields, Int32 size) > >> em Lucene.Net.Search.IndexSearcher.Search(Weight weight, Filter > filter, > >> Int32 nDocs, Sort sort) > >> em Lucene.Net.Search.Hits.GetMoreDocs(Int32 min) > >> em Lucene.Net.Search.Hits..ctor(Searcher s, Query q, Filter f, Sort o) > >> em Lucene.Net.Search.Searcher.Search(Query query, Sort sort) > >> em SearcherLibrary.Searcher.Search(String[] fields, String orderBy, > >> Int32 > >> type, Object analyzer) na > >> > c:\Maldonado\projetos\BuscaBlog\Indexer\SearcherLibrary\Searcher.cs:linha > >> 252 > >> em SearcherLibrary.Searcher.Search(String orderBy, sortType type, > Int32 > >> hitCount) na > >> > c:\Maldonado\projetos\BuscaBlog\Indexer\SearcherLibrary\Searcher.cs:linha > >> 313 > >> em IndexerConsole.Program.Main(String[] args) na > >> c:\Maldonado\projetos\BuscaBlog\Indexer\IndexerConsole\Program.cs:linha > 21 > >> > >> Any idea? > >> > >> Thank's > >> > >> "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo: > És > >> verdadeiramente o Filho de Deus." (Mateus 14:33) > >> > >> > >> On Fri, Oct 30, 2009 at 16:06, Franklin Simmons < > >> fsimm...@sccmediaserver.com > >> > wrote: > >> > >> > I did it again, think I'll hang it up for the day. The correct query > >> class > >> > name is 'MatchAllDocsQuery'. > >> > > >> > -----Original Message----- > >> > From: Franklin Simmons [mailto:fsimm...@sccmediaserver.com] > >> > Sent: Friday, October 30, 2009 2:06 PM > >> > To: lucene-net-user@incubator.apache.org > >> > Subject: RE: Simple question > >> > > >> > Oops, I'm not being very helpful. > >> > > >> > Use the MatchAllDocumentsQuery class: > >> > > >> > Searcher searcher = new IndexSearcher(directory); > >> > > >> > Sort = new Sort(new SortField("another_field", SortField.AUTO, > false)); > >> > > >> > Hits hits = searcher.search(new MatchAllDocumentsQuery(),sort); > >> > > >> > > >> > However, that may be a lot of processing. You may want to tune the > >> query > >> > in a way to minimize overhead; someone else in the list may suggest a > >> better > >> > strategy. > >> > > >> > > >> > -----Original Message----- > >> > From: Franklin Simmons [mailto:fsimm...@sccmediaserver.com] > >> > Sent: Friday, October 30, 2009 2:01 PM > >> > To: lucene-net-user@incubator.apache.org > >> > Subject: RE: Simple question > >> > > >> > Hi André, > >> > > >> > In this case you simply sort on the field. This may suffice: > >> > > >> > Searcher searcher = new IndexSearcher(directory); > >> > > >> > Sort = new Sort(new SortField("another_field", SortField.AUTO, > false)); > >> > > >> > Hits hits = searcher.search(query,sort); > >> > > >> > > >> > You can limit the number of hits (e.g. to 5), but I won't get into > that > >> > here. > >> > > >> > > >> > Beyond SortField.AUTO, take a look at the SortField class to see > >> specific > >> > field types - the most interesting being SortField.CUSTOM. > >> > > >> > > >> > -----Original Message----- > >> > From: André Maldonado [mailto:andre.maldon...@gmail.com] > >> > Sent: Friday, October 30, 2009 1:46 PM > >> > To: lucene-net-user@incubator.apache.org > >> > Subject: Re: Simple question > >> > > >> > Hi Franklin. > >> > > >> > Wich query I use for this search (variable: query)? I don't want any > >> query, > >> > I just want the TOP 5 documents ordered by a field. > >> > > >> > Thank's > >> > > >> > "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo: > >> És > >> > verdadeiramente o Filho de Deus." (Mateus 14:33) > >> > > >> > > >> > On Fri, Oct 30, 2009 at 15:03, Franklin Simmons < > >> > fsimm...@sccmediaserver.com > >> > > wrote: > >> > > >> > > You can sort a search by multiple fields. I think you could try > >> > something > >> > > like this: > >> > > > >> > > Searcher searcher = new IndexSearcher(directory); > >> > > Sort = new Sort(new SortField[] { SortField.FIELD_SCORE, new > >> > > SortField("another_field") }; > >> > > Hits hits = searcher.search(query,sort); > >> > > > >> > > > >> > > -----Original Message----- > >> > > From: André Maldonado [mailto:andre.maldon...@gmail.com] > >> > > Sent: Friday, October 30, 2009 12:57 PM > >> > > To: lucene-net-user@incubator.apache.org > >> > > Subject: Simple question > >> > > > >> > > Hi. > >> > > > >> > > This can be a simple question, but I can't figure out the solution. > >> > > > >> > > I need to search my index in something like "SELECT TOP 5 ... ORDER > BY > >> > > another_field". But this is an empty query because I want to search > in > >> > all > >> > > documents. > >> > > > >> > > How can I do it? > >> > > > >> > > Thank's > >> > > > >> > > >> > > > > >