[ 
https://issues.apache.org/jira/browse/LUCENE-916?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12502398
 ] 

Ben Dotte commented on LUCENE-916:
----------------------------------

I'm also having this problem. I'm trying to use Compass and originally reported 
the problem in their forum: 
http://forums.opensymphony.com/thread.jspa?threadID=87305&tstart=0

But I agree this seems more like a problem with Lucene itself. I have written a 
junit testcase that only uses Lucene objects that generates the same exception 
I was getting in Compass:

public class CompassSortTest extends TestCase
{
        public void testLuceneMultiSearcherSort() throws Exception
        {
                RAMDirectory dir1 = new RAMDirectory();
                RAMDirectory dir2 = new RAMDirectory();
                
                Analyzer analyzer = new StandardAnalyzer();
                IndexWriter writer1 = new IndexWriter(dir1, analyzer, true);
                writer1.optimize();
                writer1.close();
                
                IndexWriter writer2 = new IndexWriter(dir2, analyzer, true);
                Document doc = new Document();
                doc.add(new Field("displayName", "obj1", Store.YES, 
Index.TOKENIZED));
                doc.add(new Field("id", "1", Store.YES, Index.UN_TOKENIZED));
                doc.add(new Field("sortField", "3", Store.NO, 
Index.UN_TOKENIZED));
                writer2.addDocument(doc);
                writer2.optimize();
                writer2.close();
                
                IndexSearcher searcher1 = new IndexSearcher(dir1);
                IndexSearcher searcher2 = new IndexSearcher(dir2);
                MultiSearcher multiSearcher = new MultiSearcher(new 
Searchable[] {searcher1, searcher2});
                QueryParser parser = new QueryParser("displayName", analyzer);
                Query query = parser.parse("o*");
                Sort sort = new Sort("sortField");
                Hits hits = multiSearcher.search(query, sort);
                
                assertEquals("2", hits.doc(0).get("id"));
                assertEquals("3", hits.doc(1).get("id"));
                assertEquals("1", hits.doc(2).get("id"));
        }
}

The problem occurs when using a MultiSearcher that has at least one 
IndexSearcher tied to a Directory with no documents in it. If I have 2 
IndexSearchers, each with 1 document the test passes. It is only when one of 
the IndexSearchers has no documents that the test fails. The exception I get is 
"no terms in field sortField - cannot determine sort type" on 
FieldCacheImpl.java line 331.

> It is not possible to sort with sorttype auto on a field that does not exist
> ----------------------------------------------------------------------------
>
>                 Key: LUCENE-916
>                 URL: https://issues.apache.org/jira/browse/LUCENE-916
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: Search
>    Affects Versions: 1.9, 2.0.0, 2.0.1, 2.1, 2.2
>            Reporter: Daan de Wit
>
> When sorting with type auto on a field that does not exist, a 
> RuntimeException is thrown from FieldCacheImpl.java line 346. This is 
> especially a problem when using MultiSearcher. This issue is related to: 
> http://issues.apache.org/jira/browse/LUCENE-374

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to