当前位置: 首页>>代码示例>>Java>>正文


Java Sort.setSort方法代码示例

本文整理汇总了Java中org.apache.lucene.search.Sort.setSort方法的典型用法代码示例。如果您正苦于以下问题:Java Sort.setSort方法的具体用法?Java Sort.setSort怎么用?Java Sort.setSort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.search.Sort的用法示例。


在下文中一共展示了Sort.setSort方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testEmptyIndex

import org.apache.lucene.search.Sort; //导入方法依赖的package包/类
public void testEmptyIndex() throws Exception {
  IndexSearcher empty = newSearcher(new MultiReader());
  Query query = new TermQuery(new Term("contents", "foo"));

  Sort sort = new Sort();
  sort.setSort(new SortedSetSortField("sortedset", false));
  TopDocs td = empty.search(query, null, 10, sort, true, true);
  assertEquals(0, td.totalHits);
  
  // for an empty index, any selector should work
  for (SortedSetSortField.Selector v : SortedSetSortField.Selector.values()) {
    sort.setSort(new SortedSetSortField("sortedset", false, v));
    td = empty.search(query, null, 10, sort, true, true);
    assertEquals(0, td.totalHits);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TestSortedSetSortField.java

示例2: testEmptyIndex

import org.apache.lucene.search.Sort; //导入方法依赖的package包/类
public void testEmptyIndex() throws Exception {
  IndexSearcher empty = newSearcher(new MultiReader());
  Query query = new TermQuery(new Term("contents", "foo"));

  Sort sort = new Sort();
  sort.setSort(new SortedNumericSortField("sortednumeric", SortField.Type.LONG));
  TopDocs td = empty.search(query, null, 10, sort, true, true);
  assertEquals(0, td.totalHits);
  
  // for an empty index, any selector should work
  for (SortedNumericSelector.Type v : SortedNumericSelector.Type.values()) {
    sort.setSort(new SortedNumericSortField("sortednumeric", SortField.Type.LONG, false, v));
    td = empty.search(query, null, 10, sort, true, true);
    assertEquals(0, td.totalHits);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TestSortedNumericSortField.java

示例3: clearSorting

import org.apache.lucene.search.Sort; //导入方法依赖的package包/类
@SuppressWarnings( "unchecked" )
public F clearSorting( ) {
    this.sortFields = "";
    this.sortDirections = "";
    sortObj = new Sort( );
    sortObj.setSort( new SortField[0] );
    updateSorting = updateParamMap = true;

    return ( F )this;
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:11,代码来源:AbstractEntitySearcher.java

示例4: testSearchIndex

import org.apache.lucene.search.Sort; //导入方法依赖的package包/类
@Test
public void testSearchIndex() throws Exception {
  try (LuceneSearchIndex index = new LuceneSearchIndex("", "test", true)) {

    final Document doc1 = new Document();
    doc1.add(new StringField(IndexedStore.ID_FIELD_NAME, new BytesRef("1".getBytes()), Store.YES));
    doc1.add(new StringField("ds", "space1.ds1", Field.Store.NO));
    doc1.add(new StringField("job", "job1", Field.Store.YES));
    // since we want to sort on version add docvalues
    doc1.add(new StringField("version", "v1", Field.Store.NO));
    doc1.add(new SortedDocValuesField("version", new BytesRef("v1")));
    doc1.add(new StringField("foo", "bar1", Store.NO));
    doc1.add(new SortedDocValuesField("foo", new BytesRef("bar1")));

    final Document doc2 = new Document();
    doc2.add(new StringField(IndexedStore.ID_FIELD_NAME, new BytesRef("2".getBytes()), Store.YES));
    doc2.add(new StringField("ds", "space1.ds1", Field.Store.NO));
    doc2.add(new StringField("job", "job3", Field.Store.YES));
    doc2.add(new StringField("version", "v2", Field.Store.NO));
    doc2.add(new SortedDocValuesField("version", new BytesRef("v2")));
    doc2.add(new StringField("foo", "bar2", Store.NO));
    doc2.add(new SortedDocValuesField("foo", new BytesRef("bar2")));

    final Document doc3 = new Document();
    doc3.add(new StringField(IndexedStore.ID_FIELD_NAME, new BytesRef("3".getBytes()), Store.YES));
    doc3.add(new StringField("ds", "space2.ds2", Field.Store.NO));
    doc3.add(new StringField("job", "job2", Field.Store.YES));
    doc3.add(new StringField("version", "v1", Field.Store.NO));
    doc3.add(new SortedDocValuesField("version", new BytesRef("v1")));

    index.add(doc1);

    assertEquals(1, index.count(new TermQuery(new Term("ds", "space1.ds1"))));
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term("ds", "space1.ds1")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(new TermQuery(new Term("version", "v1")), BooleanClause.Occur.MUST));
    assertEquals(1, index.count(builder.build()));

    assertEquals(0, index.count(new TermQuery(new Term("ds", "space2.ds2"))));
    assertEquals(0, index.count(new TermQuery(new Term("version", "v2"))));

    builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term("ds", "space1.ds1")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(new TermQuery(new Term("version", "v2")), BooleanClause.Occur.MUST));
    assertEquals(0, index.count(builder.build()));
    assertEquals(1, index.count(new TermsQuery(new Term("ds", "space1.ds1"), new Term("version1", "v2"))));

    index.add(doc2);
    index.add(doc3);

    assertEquals(2, index.count(new TermQuery(new Term("ds", "space1.ds1"))));
    assertEquals(1, index.count(new TermQuery(new Term("ds", "space2.ds2"))));

    builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term("ds", "space2.ds2")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(new TermQuery(new Term("version", "v1")), BooleanClause.Occur.MUST));
    assertEquals(1, index.count(builder.build()));

    builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term("ds", "space1.ds1")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(new TermQuery(new Term("version", "v1")), BooleanClause.Occur.MUST));
    assertEquals(1, index.count(builder.build()));

    Sort sorter = new Sort();
    sorter.setSort(new SortField("version", SortField.Type.STRING));
    Collection<Document> documents = index.searchForDocuments(new TermQuery(new Term("ds", "space1.ds1")), 1000, sorter);
    assertEquals(2, documents.size());

    // exists queries
    assertEquals(2, index.count(LuceneQueryConverter.INSTANCE.toLuceneQuery(SearchQueryUtils.newExistsQuery("foo"))));
    assertEquals(1, index.count(LuceneQueryConverter.INSTANCE.toLuceneQuery(SearchQueryUtils.newDoesNotExistQuery("foo"))));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:74,代码来源:TestLuceneIndexer.java

示例5: testCollationKeySort

import org.apache.lucene.search.Sort; //导入方法依赖的package包/类
public void testCollationKeySort(Analyzer usAnalyzer,
                                 Analyzer franceAnalyzer,
                                 Analyzer swedenAnalyzer,
                                 Analyzer denmarkAnalyzer,
                                 String usResult,
                                 String frResult,
                                 String svResult,
                                 String dkResult) throws Exception {
  Directory indexStore = newDirectory();
  IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(
      TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));

  // document data:
  // the tracer field is used to determine which document was hit
  String[][] sortData = new String[][] {
    // tracer contents US                 France             Sweden (sv_SE)     Denmark (da_DK)
    {  "A",   "x",     "p\u00EAche",      "p\u00EAche",      "p\u00EAche",      "p\u00EAche"      },
    {  "B",   "y",     "HAT",             "HAT",             "HAT",             "HAT"             },
    {  "C",   "x",     "p\u00E9ch\u00E9", "p\u00E9ch\u00E9", "p\u00E9ch\u00E9", "p\u00E9ch\u00E9" },
    {  "D",   "y",     "HUT",             "HUT",             "HUT",             "HUT"             },
    {  "E",   "x",     "peach",           "peach",           "peach",           "peach"           },
    {  "F",   "y",     "H\u00C5T",        "H\u00C5T",        "H\u00C5T",        "H\u00C5T"        },
    {  "G",   "x",     "sin",             "sin",             "sin",             "sin"             },
    {  "H",   "y",     "H\u00D8T",        "H\u00D8T",        "H\u00D8T",        "H\u00D8T"        },
    {  "I",   "x",     "s\u00EDn",        "s\u00EDn",        "s\u00EDn",        "s\u00EDn"        },
    {  "J",   "y",     "HOT",             "HOT",             "HOT",             "HOT"             },
  };

  FieldType customType = new FieldType();
  customType.setStored(true);
  
  for (int i = 0 ; i < sortData.length ; ++i) {
    Document doc = new Document();
    doc.add(new Field("tracer", sortData[i][0], customType));
    doc.add(new TextField("contents", sortData[i][1], Field.Store.NO));
    if (sortData[i][2] != null) 
      doc.add(new TextField("US", usAnalyzer.tokenStream("US", sortData[i][2])));
    if (sortData[i][3] != null) 
      doc.add(new TextField("France", franceAnalyzer.tokenStream("France", sortData[i][3])));
    if (sortData[i][4] != null)
      doc.add(new TextField("Sweden", swedenAnalyzer.tokenStream("Sweden", sortData[i][4])));
    if (sortData[i][5] != null) 
      doc.add(new TextField("Denmark", denmarkAnalyzer.tokenStream("Denmark", sortData[i][5])));
    writer.addDocument(doc);
  }
  writer.forceMerge(1);
  writer.close();
  IndexReader reader = DirectoryReader.open(indexStore);
  IndexSearcher searcher = new IndexSearcher(reader);

  Sort sort = new Sort();
  Query queryX = new TermQuery(new Term ("contents", "x"));
  Query queryY = new TermQuery(new Term ("contents", "y"));
  
  sort.setSort(new SortField("US", SortField.Type.STRING));
  assertMatches(searcher, queryY, sort, usResult);

  sort.setSort(new SortField("France", SortField.Type.STRING));
  assertMatches(searcher, queryX, sort, frResult);

  sort.setSort(new SortField("Sweden", SortField.Type.STRING));
  assertMatches(searcher, queryY, sort, svResult);

  sort.setSort(new SortField("Denmark", SortField.Type.STRING));
  assertMatches(searcher, queryY, sort, dkResult);
  reader.close();
  indexStore.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:69,代码来源:CollationTestBase.java

示例6: defineOrder

import org.apache.lucene.search.Sort; //导入方法依赖的package包/类
public <T> void defineOrder(RestSearchKey key, FullTextQuery fullTextQuery) {

		String[] orderBy = key.getOrders();

		SortField[] sortFields = new SortField[orderBy.length];

		Sort sort = new Sort();

		for(int i = 0; i < orderBy.length; i++) {

			sortFields[i] = key.isDesc() ? new SortField(orderBy[i], SortField.STRING, false) : new SortField(orderBy[i], SortField.STRING, true);
		}		

		sort.setSort(sortFields);

		fullTextQuery.setSort(sort);
	}
 
开发者ID:mcraken,项目名称:spring-scaffy,代码行数:18,代码来源:HibernateSearchBuilder.java


注:本文中的org.apache.lucene.search.Sort.setSort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。