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


Java QueryUtils类代码示例

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


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

示例1: testBasics

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
public void testBasics() {
    final int iters = scaledRandomIntBetween(5, 25);
    for (int j = 0; j < iters; j++) {
        String[] fields = new String[1 + random().nextInt(10)];
        for (int i = 0; i < fields.length; i++) {
            fields[i] = TestUtil.randomRealisticUnicodeString(random(), 1, 10);
        }
        String term = TestUtil.randomRealisticUnicodeString(random(), 1, 10);
        Term[] terms = toTerms(fields, term);
        boolean disableCoord = random().nextBoolean();
        boolean useBoolean = random().nextBoolean();
        float tieBreaker = random().nextFloat();
        BlendedTermQuery query = useBoolean ? BlendedTermQuery.booleanBlendedQuery(terms, disableCoord) : BlendedTermQuery.dismaxBlendedQuery(terms, tieBreaker);
        QueryUtils.check(query);
        terms = toTerms(fields, term);
        BlendedTermQuery query2 = useBoolean ? BlendedTermQuery.booleanBlendedQuery(terms, disableCoord) : BlendedTermQuery.dismaxBlendedQuery(terms, tieBreaker);
        assertEquals(query, query2);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:BlendedTermQueryTests.java

示例2: doTestRank

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
private void doTestRank (ValueSource valueSource) throws Exception {
  FunctionQuery functionQuery = new FunctionQuery(valueSource);
  IndexReader r = DirectoryReader.open(dir);
  IndexSearcher s = newSearcher(r);
  log("test: "+ functionQuery);
  QueryUtils.check(random(), functionQuery,s);
  ScoreDoc[] h = s.search(functionQuery, null, 1000).scoreDocs;
  assertEquals("All docs should be matched!",N_DOCS,h.length);
  String prevID = "ID"+(N_DOCS+1); // greater than all ids of docs in this test
  for (int i=0; i<h.length; i++) {
    String resID = s.doc(h[i].doc).get(ID_FIELD);
    log(i+".   score="+h[i].score+"  -  "+resID);
    log(s.explain(functionQuery,h[i].doc));
    assertTrue("res id "+resID+" should be < prev res id "+prevID, resID.compareTo(prevID)<0);
    prevID = resID;
  }
  r.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TestFieldScoreQuery.java

示例3: testSpanNearExact

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
@Test
public void testSpanNearExact() throws Exception {
  SpanTermQuery term1 = new SpanTermQuery(new Term("field", "seventy"));
  SpanTermQuery term2 = new SpanTermQuery(new Term("field", "seven"));
  SpanNearQuery query = new SpanNearQuery(new SpanQuery[] {term1, term2},
                                          0, true);
  checkHits(query, new int[]
    {77, 177, 277, 377, 477, 577, 677, 777, 877, 977, 1077, 1177, 1277, 1377, 1477, 1577, 1677, 1777, 1877, 1977});

  assertTrue(searcher.explain(query, 77).getValue() > 0.0f);
  assertTrue(searcher.explain(query, 977).getValue() > 0.0f);

  QueryUtils.check(term1);
  QueryUtils.check(term2);
  QueryUtils.checkUnequal(term1,term2);
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TestBasics.java

示例4: testRewrite1

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
public void testRewrite1() throws Exception {
  // mask an anon SpanQuery class that rewrites to something else.
  SpanQuery q = new FieldMaskingSpanQuery
    (new SpanTermQuery(new Term("last", "sally")) {
        @Override
        public Query rewrite(IndexReader reader) {
          return new SpanOrQuery(new SpanTermQuery(new Term("first", "sally")),
              new SpanTermQuery(new Term("first", "james")));
        }
      }, "first");

  SpanQuery qr = (SpanQuery) searcher.rewrite(q);

  QueryUtils.checkUnequal(q, qr);

  Set<Term> terms = new HashSet<>();
  qr.extractTerms(terms);
  assertEquals(2, terms.size());
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestFieldMaskingSpanQuery.java

示例5: testEquality1

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
public void testEquality1() {
  SpanQuery q1 = new FieldMaskingSpanQuery
    (new SpanTermQuery(new Term("last", "sally")) , "first");
  SpanQuery q2 = new FieldMaskingSpanQuery
    (new SpanTermQuery(new Term("last", "sally")) , "first");
  SpanQuery q3 = new FieldMaskingSpanQuery
    (new SpanTermQuery(new Term("last", "sally")) , "XXXXX");
  SpanQuery q4 = new FieldMaskingSpanQuery
    (new SpanTermQuery(new Term("last", "XXXXX")) , "first");
  SpanQuery q5 = new FieldMaskingSpanQuery
    (new SpanTermQuery(new Term("xXXX", "sally")) , "first");
  QueryUtils.checkEqual(q1, q2);
  QueryUtils.checkUnequal(q1, q3);
  QueryUtils.checkUnequal(q1, q4);
  QueryUtils.checkUnequal(q1, q5);
  
  SpanQuery qA = new FieldMaskingSpanQuery
    (new SpanTermQuery(new Term("last", "sally")) , "first");
  qA.setBoost(9f);
  SpanQuery qB = new FieldMaskingSpanQuery
    (new SpanTermQuery(new Term("last", "sally")) , "first");
  QueryUtils.checkUnequal(qA, qB);
  qB.setBoost(9f);
  QueryUtils.checkEqual(qA, qB);
  
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:TestFieldMaskingSpanQuery.java

示例6: testAverageFunction

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
public void testAverageFunction() throws IOException {
  PayloadNearQuery query;
  TopDocs hits;

  query = newPhraseQuery("field", "twenty two", true, new AveragePayloadFunction());
  QueryUtils.check(query);
  // all 10 hits should have score = 3 because adjacent terms have payloads of 2,4
  // and all the similarity factors are set to 1
  hits = searcher.search(query, null, 100);
  assertTrue("hits is null and it shouldn't be", hits != null);
  assertTrue("should be 10 hits", hits.totalHits == 10);
  for (int j = 0; j < hits.scoreDocs.length; j++) {
    ScoreDoc doc = hits.scoreDocs[j];
    assertTrue(doc.score + " does not equal: " + 3, doc.score == 3);
    Explanation explain = searcher.explain(query, hits.scoreDocs[j].doc);
    String exp = explain.toString();
    assertTrue(exp, exp.indexOf("AveragePayloadFunction") > -1);
    assertTrue(hits.scoreDocs[j].score + " explain value does not equal: " + 3, explain.getValue() == 3f);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:TestPayloadNearQuery.java

示例7: testMaxFunction

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
public void testMaxFunction() throws IOException {
  PayloadNearQuery query;
  TopDocs hits;

  query = newPhraseQuery("field", "twenty two", true, new MaxPayloadFunction());
  QueryUtils.check(query);
  // all 10 hits should have score = 4 (max payload value)
  hits = searcher.search(query, null, 100);
  assertTrue("hits is null and it shouldn't be", hits != null);
  assertTrue("should be 10 hits", hits.totalHits == 10);
  for (int j = 0; j < hits.scoreDocs.length; j++) {
    ScoreDoc doc = hits.scoreDocs[j];
    assertTrue(doc.score + " does not equal: " + 4, doc.score == 4);
    Explanation explain = searcher.explain(query, hits.scoreDocs[j].doc);
    String exp = explain.toString();
    assertTrue(exp, exp.indexOf("MaxPayloadFunction") > -1);
    assertTrue(hits.scoreDocs[j].score + " explain value does not equal: " + 4, explain.getValue() == 4f);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestPayloadNearQuery.java

示例8: testMinFunction

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
public void testMinFunction() throws IOException {
  PayloadNearQuery query;
  TopDocs hits;

  query = newPhraseQuery("field", "twenty two", true, new MinPayloadFunction());
  QueryUtils.check(query);
  // all 10 hits should have score = 2 (min payload value)
  hits = searcher.search(query, null, 100);
  assertTrue("hits is null and it shouldn't be", hits != null);
  assertTrue("should be 10 hits", hits.totalHits == 10);
  for (int j = 0; j < hits.scoreDocs.length; j++) {
    ScoreDoc doc = hits.scoreDocs[j];
    assertTrue(doc.score + " does not equal: " + 2, doc.score == 2);
    Explanation explain = searcher.explain(query, hits.scoreDocs[j].doc);
    String exp = explain.toString();
    assertTrue(exp, exp.indexOf("MinPayloadFunction") > -1);
    assertTrue(hits.scoreDocs[j].score + " explain value does not equal: " + 2, explain.getValue() == 2f);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestPayloadNearQuery.java

示例9: tryQuerySameTypes

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
void tryQuerySameTypes(String template, String numbers, String type) throws SyntaxError {
  String s1 = template;
  String s2 = template;
  String s3 = template;

  String[] numParts = numbers.split(",");
  String type2 = type.replace("val1", "val2");
  for (int idx = 0; s1.contains("#"); ++idx) {
    String patV = "#v" + Integer.toString(idx);
    String patN = "#n" + Integer.toString(idx);
    s1 = s1.replace(patV, type).replace(patN, numParts[idx]);
    s2 = s2.replace(patV, type).replace(patN, numParts[idx]);
    s3 = s3.replace(patV, type2).replace(patN, numParts[idx]);
  }

  //SolrQueryRequest req1 = req( "q","*:*", "fq", s1);

  Query q1 = getQuery(s1);
  Query q2 = getQuery(s2);
  Query q3 = getQuery(s3);
  QueryUtils.checkEqual(q1, q2);
  QueryUtils.checkUnequal(q1, q3);
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:TestValueSourceCache.java

示例10: doTestRank

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
private void doTestRank (ValueSource valueSource) throws Exception {
  FunctionQuery functionQuery = new FunctionQuery(valueSource);
  IndexReader r = DirectoryReader.open(dir);
  IndexSearcher s = new IndexSearcher(r);
  log("test: "+ functionQuery);
  QueryUtils.check(random(), functionQuery,s);
  ScoreDoc[] h = s.search(functionQuery, null, 1000).scoreDocs;
  assertEquals("All docs should be matched!",N_DOCS,h.length);
  String prevID = "ID"+(N_DOCS+1); // greater than all ids of docs in this test
  for (int i=0; i<h.length; i++) {
    String resID = s.doc(h[i].doc).get(ID_FIELD);
    log(i+".   score="+h[i].score+"  -  "+resID);
    log(s.explain(functionQuery,h[i].doc));
    assertTrue("res id "+resID+" should be < prev res id "+prevID, resID.compareTo(prevID)<0);
    prevID = resID;
  }
  r.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:19,代码来源:TestFieldScoreQuery.java

示例11: testRewrite1

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
public void testRewrite1() throws Exception {
  // mask an anon SpanQuery class that rewrites to something else.
  SpanQuery q = new FieldMaskingSpanQuery
    (new SpanTermQuery(new Term("last", "sally")) {
        @Override
        public Query rewrite(IndexReader reader) {
          return new SpanOrQuery(new SpanTermQuery(new Term("first", "sally")),
              new SpanTermQuery(new Term("first", "james")));
        }
      }, "first");

  SpanQuery qr = (SpanQuery) searcher.rewrite(q);

  QueryUtils.checkUnequal(q, qr);

  Set<Term> terms = new HashSet<Term>();
  qr.extractTerms(terms);
  assertEquals(2, terms.size());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:20,代码来源:TestFieldMaskingSpanQuery.java

示例12: testBasics

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
public void testBasics() {
    MinDocQuery query1 = new MinDocQuery(42);
    MinDocQuery query2 = new MinDocQuery(42);
    MinDocQuery query3 = new MinDocQuery(43);
    QueryUtils.check(query1);
    QueryUtils.checkEqual(query1, query2);
    QueryUtils.checkUnequal(query1, query3);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:MinDocQueryTests.java

示例13: testBasics

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
public void testBasics() {
    TermsSliceQuery query1 =
        new TermsSliceQuery("field1", 1, 10);
    TermsSliceQuery query2 =
        new TermsSliceQuery("field1", 1, 10);
    TermsSliceQuery query3 =
        new TermsSliceQuery("field2", 1, 10);
    TermsSliceQuery query4 =
        new TermsSliceQuery("field1", 2, 10);
    QueryUtils.check(query1);
    QueryUtils.checkEqual(query1, query2);
    QueryUtils.checkUnequal(query1, query3);
    QueryUtils.checkUnequal(query1, query4);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:TermsSliceQueryTests.java

示例14: testBasics

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
public void testBasics() {
    DocValuesSliceQuery query1 =
        new DocValuesSliceQuery("field1", 1, 10);
    DocValuesSliceQuery query2 =
        new DocValuesSliceQuery("field1", 1, 10);
    DocValuesSliceQuery query3 =
        new DocValuesSliceQuery("field2", 1, 10);
    DocValuesSliceQuery query4 =
        new DocValuesSliceQuery("field1", 2, 10);
    QueryUtils.check(query1);
    QueryUtils.checkEqual(query1, query2);
    QueryUtils.checkUnequal(query1, query3);
    QueryUtils.checkUnequal(query1, query4);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:DocValuesSliceQueryTests.java

示例15: testBoostingQueryEquals

import org.apache.lucene.search.QueryUtils; //导入依赖的package包/类
public void testBoostingQueryEquals() {
  TermQuery q1 = new TermQuery(new Term("subject:", "java"));
  TermQuery q2 = new TermQuery(new Term("subject:", "java"));
  assertEquals("Two TermQueries with same attributes should be equal", q1, q2);
  BoostingQuery bq1 = new BoostingQuery(q1, q2, 0.1f);
  QueryUtils.check(bq1);
  BoostingQuery bq2 = new BoostingQuery(q1, q2, 0.1f);
  assertEquals("BoostingQuery with same attributes is not equal", bq1, bq2);
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:BoostingQueryTest.java


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