List of usage examples for org.apache.lucene.search Sort INDEXORDER
Sort INDEXORDER
To view the source code for org.apache.lucene.search Sort INDEXORDER.
Click Source Link
From source file:com.sindicetech.siren.search.node.TestNodeNumericRangeQuery64.java
License:Open Source License
private void testRightOpenRange(final int precisionStep) throws Exception { final String field = "field" + precisionStep; final int count = 3000; final long lower = (count - 1) * distance + (distance / 3) + startOffset; Query dq = twq(1).with(child(must(nmqLong(field, precisionStep, lower, null, true, true).bound(2, 2)))) .getLuceneProxyQuery();//from w w w . j a v a 2 s . co m TopDocs topDocs = index.searcher.search(dq, null, noDocs, Sort.INDEXORDER); ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", noDocs - count, sd.length); Document doc = index.searcher.doc(sd[0].doc); assertEquals("First doc", count * distance + startOffset, Long.parseLong(getLiteralValue(doc.get(field)))); doc = index.searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc", (noDocs - 1) * distance + startOffset, Long.parseLong(getLiteralValue(doc.get(field)))); dq = twq(1).with(child(must(nmqLong(field, precisionStep, lower, null, true, false).bound(2, 2)))) .getLuceneProxyQuery(); topDocs = index.searcher.search(dq, null, noDocs, Sort.INDEXORDER); sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", noDocs - count, sd.length); doc = index.searcher.doc(sd[0].doc); assertEquals("First doc", count * distance + startOffset, Long.parseLong(getLiteralValue(doc.get(field)))); doc = index.searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc", (noDocs - 1) * distance + startOffset, Long.parseLong(getLiteralValue(doc.get(field)))); }
From source file:com.sindicetech.siren.util.BasicSirenTestCase.java
License:Open Source License
protected void checkHits(Query query, int... results) throws IOException { if (query instanceof NodeQuery) { query = new LuceneProxyNodeQuery((NodeQuery) query); }/*from w w w . j a va 2 s.c om*/ // Use index order to ensure that the scoring does not influence the order TopDocs hits = searcher.search(query, 1000, Sort.INDEXORDER); assertEquals(results.length, hits.totalHits); for (int i = 0; i < results.length; i++) { assertEquals(results[i], hits.scoreDocs[i].doc); } }
From source file:lia.chapter5.SortingExample.java
License:Apache License
public static void main(String[] args) throws Exception { Query allBooks = new MatchAllDocsQuery(); QueryParser parser = new QueryParser("contents", // #1 new StandardAnalyzer( // #1 )); // #1 BooleanQuery.Builder query = new BooleanQuery.Builder(); query.add(allBooks, BooleanClause.Occur.SHOULD); // #1 query.add(parser.parse("java OR action"), BooleanClause.Occur.SHOULD); // #1 SortingExample example = new SortingExample(); // #2 example.displayResults(query.build(), Sort.RELEVANCE); example.displayResults(query.build(), Sort.INDEXORDER); example.displayResults(query.build(), new Sort(new SortField("category", SortField.Type.STRING))); example.displayResults(query.build(), new Sort(new SortField("pubmonth", SortField.Type.INT, true))); example.displayResults(query.build(), new Sort(new SortField("category", SortField.Type.STRING), SortField.FIELD_SCORE, new SortField("pubmonth", SortField.Type.INT, true))); example.displayResults(query.build(), new Sort( new SortField[] { SortField.FIELD_SCORE, new SortField("category", SortField.Type.STRING) })); }
From source file:net.sf.zekr.ui.QuranForm.java
private void advancedFind() { String str;// w ww . j a v a 2 s . c om if (advancedToggleMultiLine.getSelection()) { str = advancedSearchBox.getText(); } else { str = advancedSearchCombo.getText(); } if ("".equals(str.trim())) { return; // do nothing } LuceneIndexManager lim = config.getLuceneIndexManager(); try { if (advancedQuranTargetBut.getSelection()) { qts = new QuranTextSearcher(lim, searchScope); } else { qts = new QuranTextSearcher(lim, searchScope, config.getTranslation().getDefault()); } } catch (IndexingException e) { logger.implicitLog(e); MessageBoxUtils.showError("Indexing Error: " + e); return; // search failed } if (!qts.isIndexReaderOpen()) { return; // indexing probably interrupted } str = str.trim(); if (!"".equals(str)) { if (advancedSearchCombo.getItemCount() <= 0 || !str.equals(advancedSearchCombo.getItem(0))) { advancedSearchCombo.add(str, 0); } if (advancedSearchCombo.getItemCount() > 40) { advancedSearchCombo.remove(40, advancedSearchCombo.getItemCount() - 1); } logger.info("Search started: " + str); Date date1 = new Date(); int sortBy = advancedSearchOrderCombo.getSelectionIndex(); boolean relevance = sortBy == 0 ? true : false; try { qts.setSortResultOrder(relevance ? Sort.RELEVANCE : Sort.INDEXORDER); qts.setAscending(advancedSortOrderButton.getData().equals("asc")); qts.setSearchResultComparator(SearchResultComparatorFactory .getComparator((String) advancedSearchOrderCombo.getData(String.valueOf(sortBy)))); asr = qts.search(str); } catch (Exception e) { logger.implicitLog(e); MessageBoxUtils.showError("Advanced Search Error: " + e); searchNav.setVisible(false); return; // search failed } Date date2 = new Date(); logger.info("Search for " + str + " finished; took " + (date2.getTime() - date1.getTime()) + " ms."); int pageCount = asr.getResultPageCount(); logger.debug("Search result has " + pageCount + " pages."); if (pageCount > 1) { advSearchNav.setVisible(true); } else { advSearchNav.setVisible(false); advSearchNav.nextPageBut.setEnabled(true); } advSearchNav.resetSearch(pageCount); } }
From source file:org.apache.solr.legacy.TestNumericRangeQuery32.java
License:Apache License
/** test for both constant score and boolean query, the other tests only use the constant score mode */ private void testRange(int precisionStep) throws Exception { String field = "field" + precisionStep; int count = 3000; int lower = (distance * 3 / 2) + startOffset, upper = lower + count * distance + (distance / 3); LegacyNumericRangeQuery<Integer> q = LegacyNumericRangeQuery.newIntRange(field, precisionStep, lower, upper, true, true);//from www. ja v a2 s . com for (byte i = 0; i < 2; i++) { TopDocs topDocs; String type; switch (i) { case 0: type = " (constant score filter rewrite)"; q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE); topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); break; case 1: type = " (constant score boolean rewrite)"; q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE); topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); break; default: return; } ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count" + type, count, sd.length); Document doc = searcher.doc(sd[0].doc); assertEquals("First doc" + type, 2 * distance + startOffset, doc.getField(field).numericValue().intValue()); doc = searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc" + type, (1 + count) * distance + startOffset, doc.getField(field).numericValue().intValue()); } }
From source file:org.apache.solr.legacy.TestNumericRangeQuery32.java
License:Apache License
private void testLeftOpenRange(int precisionStep) throws Exception { String field = "field" + precisionStep; int count = 3000; int upper = (count - 1) * distance + (distance / 3) + startOffset; LegacyNumericRangeQuery<Integer> q = LegacyNumericRangeQuery.newIntRange(field, precisionStep, null, upper, true, true);//from w w w .j a v a 2 s . c o m TopDocs topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", count, sd.length); Document doc = searcher.doc(sd[0].doc); assertEquals("First doc", startOffset, doc.getField(field).numericValue().intValue()); doc = searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc", (count - 1) * distance + startOffset, doc.getField(field).numericValue().intValue()); q = LegacyNumericRangeQuery.newIntRange(field, precisionStep, null, upper, false, true); topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", count, sd.length); doc = searcher.doc(sd[0].doc); assertEquals("First doc", startOffset, doc.getField(field).numericValue().intValue()); doc = searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc", (count - 1) * distance + startOffset, doc.getField(field).numericValue().intValue()); }
From source file:org.apache.solr.legacy.TestNumericRangeQuery32.java
License:Apache License
private void testRightOpenRange(int precisionStep) throws Exception { String field = "field" + precisionStep; int count = 3000; int lower = (count - 1) * distance + (distance / 3) + startOffset; LegacyNumericRangeQuery<Integer> q = LegacyNumericRangeQuery.newIntRange(field, precisionStep, lower, null, true, true);//from w ww . ja v a 2 s.com TopDocs topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", noDocs - count, sd.length); Document doc = searcher.doc(sd[0].doc); assertEquals("First doc", count * distance + startOffset, doc.getField(field).numericValue().intValue()); doc = searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc", (noDocs - 1) * distance + startOffset, doc.getField(field).numericValue().intValue()); q = LegacyNumericRangeQuery.newIntRange(field, precisionStep, lower, null, true, false); topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", noDocs - count, sd.length); doc = searcher.doc(sd[0].doc); assertEquals("First doc", count * distance + startOffset, doc.getField(field).numericValue().intValue()); doc = searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc", (noDocs - 1) * distance + startOffset, doc.getField(field).numericValue().intValue()); }
From source file:org.apache.solr.legacy.TestNumericRangeQuery64.java
License:Apache License
/** test for constant score + boolean query + filter, the other tests only use the constant score mode */ private void testRange(int precisionStep) throws Exception { String field = "field" + precisionStep; int count = 3000; long lower = (distance * 3 / 2) + startOffset, upper = lower + count * distance + (distance / 3); LegacyNumericRangeQuery<Long> q = LegacyNumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, true);//from www . jav a 2s .c o m for (byte i = 0; i < 2; i++) { TopDocs topDocs; String type; switch (i) { case 0: type = " (constant score filter rewrite)"; q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE); topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); break; case 1: type = " (constant score boolean rewrite)"; q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE); topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); break; default: return; } ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count" + type, count, sd.length); Document doc = searcher.doc(sd[0].doc); assertEquals("First doc" + type, 2 * distance + startOffset, doc.getField(field).numericValue().longValue()); doc = searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc" + type, (1 + count) * distance + startOffset, doc.getField(field).numericValue().longValue()); } }
From source file:org.apache.solr.legacy.TestNumericRangeQuery64.java
License:Apache License
private void testLeftOpenRange(int precisionStep) throws Exception { String field = "field" + precisionStep; int count = 3000; long upper = (count - 1) * distance + (distance / 3) + startOffset; LegacyNumericRangeQuery<Long> q = LegacyNumericRangeQuery.newLongRange(field, precisionStep, null, upper, true, true);//from w ww .j a v a2 s.c o m TopDocs topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", count, sd.length); Document doc = searcher.doc(sd[0].doc); assertEquals("First doc", startOffset, doc.getField(field).numericValue().longValue()); doc = searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc", (count - 1) * distance + startOffset, doc.getField(field).numericValue().longValue()); q = LegacyNumericRangeQuery.newLongRange(field, precisionStep, null, upper, false, true); topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", count, sd.length); doc = searcher.doc(sd[0].doc); assertEquals("First doc", startOffset, doc.getField(field).numericValue().longValue()); doc = searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc", (count - 1) * distance + startOffset, doc.getField(field).numericValue().longValue()); }
From source file:org.apache.solr.legacy.TestNumericRangeQuery64.java
License:Apache License
private void testRightOpenRange(int precisionStep) throws Exception { String field = "field" + precisionStep; int count = 3000; long lower = (count - 1) * distance + (distance / 3) + startOffset; LegacyNumericRangeQuery<Long> q = LegacyNumericRangeQuery.newLongRange(field, precisionStep, lower, null, true, true);/* w w w .j a v a 2 s .c om*/ TopDocs topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", noDocs - count, sd.length); Document doc = searcher.doc(sd[0].doc); assertEquals("First doc", count * distance + startOffset, doc.getField(field).numericValue().longValue()); doc = searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc", (noDocs - 1) * distance + startOffset, doc.getField(field).numericValue().longValue()); q = LegacyNumericRangeQuery.newLongRange(field, precisionStep, lower, null, true, false); topDocs = searcher.search(q, noDocs, Sort.INDEXORDER); sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", noDocs - count, sd.length); doc = searcher.doc(sd[0].doc); assertEquals("First doc", count * distance + startOffset, doc.getField(field).numericValue().longValue()); doc = searcher.doc(sd[sd.length - 1].doc); assertEquals("Last doc", (noDocs - 1) * distance + startOffset, doc.getField(field).numericValue().longValue()); }