List of usage examples for org.apache.lucene.search Sort Sort
public Sort(SortField... fields)
From source file:org.apache.solr.uninverting.TestFieldCacheSort.java
License:Apache License
/** Tests sorting on type long */ public void testLong() throws IOException { Directory dir = newDirectory();//from ww w . ja v a2 s . c o m RandomIndexWriter writer = new RandomIndexWriter(random(), dir); Document doc = new Document(); doc.add(new LongPoint("value", 3000000000L)); doc.add(new StoredField("value", 3000000000L)); writer.addDocument(doc); doc = new Document(); doc.add(new LongPoint("value", -1)); doc.add(new StoredField("value", -1)); writer.addDocument(doc); doc = new Document(); doc.add(new LongPoint("value", 4)); doc.add(new StoredField("value", 4)); writer.addDocument(doc); IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LONG_POINT)); writer.close(); IndexSearcher searcher = newSearcher(ir, false); Sort sort = new Sort(new SortField("value", SortField.Type.LONG)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); assertEquals(3, td.totalHits); // numeric order assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); assertEquals("3000000000", searcher.doc(td.scoreDocs[2].doc).get("value")); TestUtil.checkReader(ir); ir.close(); dir.close(); }
From source file:org.apache.solr.uninverting.TestFieldCacheSort.java
License:Apache License
/** Tests sorting on type long with a missing value */ public void testLongMissing() throws IOException { Directory dir = newDirectory();/* w ww. j a v a 2 s. com*/ RandomIndexWriter writer = new RandomIndexWriter(random(), dir); Document doc = new Document(); writer.addDocument(doc); doc = new Document(); doc.add(new LongPoint("value", -1)); doc.add(new StoredField("value", -1)); writer.addDocument(doc); doc = new Document(); doc.add(new LongPoint("value", 4)); doc.add(new StoredField("value", 4)); writer.addDocument(doc); IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LONG_POINT)); writer.close(); IndexSearcher searcher = newSearcher(ir, false); Sort sort = new Sort(new SortField("value", SortField.Type.LONG)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); assertEquals(3, td.totalHits); // null is treated as 0 assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[2].doc).get("value")); TestUtil.checkReader(ir); ir.close(); dir.close(); }
From source file:org.apache.solr.uninverting.TestFieldCacheSort.java
License:Apache License
/** Tests sorting on type long, specifying the missing value should be treated as Long.MAX_VALUE */ public void testLongMissingLast() throws IOException { Directory dir = newDirectory();/*from w ww . j a va 2 s. c om*/ RandomIndexWriter writer = new RandomIndexWriter(random(), dir); Document doc = new Document(); writer.addDocument(doc); doc = new Document(); doc.add(new LongPoint("value", -1)); doc.add(new StoredField("value", -1)); writer.addDocument(doc); doc = new Document(); doc.add(new LongPoint("value", 4)); doc.add(new StoredField("value", 4)); writer.addDocument(doc); IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LONG_POINT)); writer.close(); IndexSearcher searcher = newSearcher(ir, false); SortField sortField = new SortField("value", SortField.Type.LONG); sortField.setMissingValue(Long.MAX_VALUE); Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); assertEquals(3, td.totalHits); // null is treated as Long.MAX_VALUE assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[2].doc).get("value")); TestUtil.checkReader(ir); ir.close(); dir.close(); }
From source file:org.apache.solr.uninverting.TestFieldCacheSort.java
License:Apache License
/** Tests sorting on type long in reverse */ public void testLongReverse() throws IOException { Directory dir = newDirectory();//from w ww . j a v a 2s. co m RandomIndexWriter writer = new RandomIndexWriter(random(), dir); Document doc = new Document(); doc.add(new LongPoint("value", 3000000000L)); doc.add(new StoredField("value", 3000000000L)); writer.addDocument(doc); doc = new Document(); doc.add(new LongPoint("value", -1)); doc.add(new StoredField("value", -1)); writer.addDocument(doc); doc = new Document(); doc.add(new LongPoint("value", 4)); doc.add(new StoredField("value", 4)); writer.addDocument(doc); IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LONG_POINT)); writer.close(); IndexSearcher searcher = newSearcher(ir, false); Sort sort = new Sort(new SortField("value", SortField.Type.LONG, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); assertEquals(3, td.totalHits); // reverse numeric order assertEquals("3000000000", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); assertEquals("-1", searcher.doc(td.scoreDocs[2].doc).get("value")); TestUtil.checkReader(ir); ir.close(); dir.close(); }
From source file:org.apache.solr.uninverting.TestFieldCacheSort.java
License:Apache License
/** Tests sorting on type legacy long */ public void testLegacyLong() throws IOException { Directory dir = newDirectory();//from w w w .j a va 2 s.c om RandomIndexWriter writer = new RandomIndexWriter(random(), dir); Document doc = new Document(); doc.add(new LegacyLongField("value", 3000000000L, Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new LegacyLongField("value", -1, Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new LegacyLongField("value", 4, Field.Store.YES)); writer.addDocument(doc); IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LEGACY_LONG)); writer.close(); IndexSearcher searcher = newSearcher(ir); Sort sort = new Sort(new SortField("value", SortField.Type.LONG)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); assertEquals(3, td.totalHits); // numeric order assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); assertEquals("3000000000", searcher.doc(td.scoreDocs[2].doc).get("value")); TestUtil.checkReader(ir); ir.close(); dir.close(); }
From source file:org.apache.solr.uninverting.TestFieldCacheSort.java
License:Apache License
/** Tests sorting on type legacy long with a missing value */ public void testLegacyLongMissing() throws IOException { Directory dir = newDirectory();/*from www .jav a2s.co m*/ RandomIndexWriter writer = new RandomIndexWriter(random(), dir); Document doc = new Document(); writer.addDocument(doc); doc = new Document(); doc.add(new LegacyLongField("value", -1, Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new LegacyLongField("value", 4, Field.Store.YES)); writer.addDocument(doc); IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LEGACY_LONG)); writer.close(); IndexSearcher searcher = newSearcher(ir); Sort sort = new Sort(new SortField("value", SortField.Type.LONG)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); assertEquals(3, td.totalHits); // null is treated as 0 assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[2].doc).get("value")); TestUtil.checkReader(ir); ir.close(); dir.close(); }
From source file:org.apache.solr.uninverting.TestFieldCacheSort.java
License:Apache License
/** Tests sorting on type legacy long, specifying the missing value should be treated as Long.MAX_VALUE */ public void testLegacyLongMissingLast() throws IOException { Directory dir = newDirectory();//from www. j av a 2 s . c om RandomIndexWriter writer = new RandomIndexWriter(random(), dir); Document doc = new Document(); writer.addDocument(doc); doc = new Document(); doc.add(new LegacyLongField("value", -1, Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new LegacyLongField("value", 4, Field.Store.YES)); writer.addDocument(doc); IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LEGACY_LONG)); writer.close(); IndexSearcher searcher = newSearcher(ir); SortField sortField = new SortField("value", SortField.Type.LONG); sortField.setMissingValue(Long.MAX_VALUE); Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); assertEquals(3, td.totalHits); // null is treated as Long.MAX_VALUE assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[2].doc).get("value")); TestUtil.checkReader(ir); ir.close(); dir.close(); }
From source file:org.apache.solr.uninverting.TestFieldCacheSort.java
License:Apache License
/** Tests sorting on type legacy long in reverse */ public void testLegacyLongReverse() throws IOException { Directory dir = newDirectory();//w ww . jav a 2 s.c o m RandomIndexWriter writer = new RandomIndexWriter(random(), dir); Document doc = new Document(); doc.add(new LegacyLongField("value", 3000000000L, Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new LegacyLongField("value", -1, Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new LegacyLongField("value", 4, Field.Store.YES)); writer.addDocument(doc); IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.LEGACY_LONG)); writer.close(); IndexSearcher searcher = newSearcher(ir); Sort sort = new Sort(new SortField("value", SortField.Type.LONG, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); assertEquals(3, td.totalHits); // reverse numeric order assertEquals("3000000000", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); assertEquals("-1", searcher.doc(td.scoreDocs[2].doc).get("value")); TestUtil.checkReader(ir); ir.close(); dir.close(); }
From source file:org.apache.solr.uninverting.TestFieldCacheSort.java
License:Apache License
/** Tests sorting on type float */ public void testFloat() throws IOException { Directory dir = newDirectory();// w ww .j a v a2 s . c o m RandomIndexWriter writer = new RandomIndexWriter(random(), dir); Document doc = new Document(); doc.add(new FloatPoint("value", 30.1f)); doc.add(new StoredField("value", 30.1f)); writer.addDocument(doc); doc = new Document(); doc.add(new FloatPoint("value", -1.3f)); doc.add(new StoredField("value", -1.3f)); writer.addDocument(doc); doc = new Document(); doc.add(new FloatPoint("value", 4.2f)); doc.add(new StoredField("value", 4.2f)); writer.addDocument(doc); IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.FLOAT_POINT)); writer.close(); IndexSearcher searcher = newSearcher(ir, false); Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); assertEquals(3, td.totalHits); // numeric order assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value")); assertEquals("30.1", searcher.doc(td.scoreDocs[2].doc).get("value")); TestUtil.checkReader(ir); ir.close(); dir.close(); }
From source file:org.apache.solr.uninverting.TestFieldCacheSort.java
License:Apache License
/** Tests sorting on type float with a missing value */ public void testFloatMissing() throws IOException { Directory dir = newDirectory();//from w ww. j av a 2s. com RandomIndexWriter writer = new RandomIndexWriter(random(), dir); Document doc = new Document(); writer.addDocument(doc); doc = new Document(); doc.add(new FloatPoint("value", -1.3f)); doc.add(new StoredField("value", -1.3f)); writer.addDocument(doc); doc = new Document(); doc.add(new FloatPoint("value", 4.2f)); doc.add(new StoredField("value", 4.2f)); writer.addDocument(doc); IndexReader ir = UninvertingReader.wrap(writer.getReader(), Collections.singletonMap("value", Type.FLOAT_POINT)); writer.close(); IndexSearcher searcher = newSearcher(ir, false); Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); assertEquals(3, td.totalHits); // null is treated as 0 assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); assertEquals("4.2", searcher.doc(td.scoreDocs[2].doc).get("value")); TestUtil.checkReader(ir); ir.close(); dir.close(); }