/**
  * Perform searching for word by word content.
  *
  * @param content the content used to search.
  * @return a list of found documents.
  * @throws java.io.IOException if the path to the lucene index is incorrect.
  */
 public static List<Document> performSearchByContent(String content) throws IOException {
   List<Document> foundDocs =
       performSearch(QueryUtils.buildPhraseQuery(content), LuceneUtils.getLuceneSearcher());
   if (CollectionUtils.isEmpty(foundDocs)) {
     foundDocs =
         performSearch(QueryUtils.buildFuzzyQuery(content), LuceneUtils.getLuceneSearcher());
   }
   return foundDocs;
 }
  public void testHashcodeEquals() {
    SpanTermQuery q1 = new SpanTermQuery(new Term("field", "foo"));
    SpanTermQuery q2 = new SpanTermQuery(new Term("field", "bar"));
    SpanTermQuery q3 = new SpanTermQuery(new Term("field", "baz"));

    SpanNearQuery near1 = new SpanNearQuery(new SpanQuery[] {q1, q2}, 10, true);
    SpanNearQuery near2 = new SpanNearQuery(new SpanQuery[] {q2, q3}, 10, true);
    QueryUtils.check(near1);
    QueryUtils.check(near2);
    QueryUtils.checkUnequal(near1, near2);
  }
 @Test
 public void testBasicQuerySanities() {
   Query childQuery = new TermQuery(new Term("field", "value"));
   ScoreType scoreType = ScoreType.values()[random().nextInt(ScoreType.values().length)];
   ParentFieldMapper parentFieldMapper =
       SearchContext.current().mapperService().documentMapper("child").parentFieldMapper();
   ParentChildIndexFieldData parentChildIndexFieldData =
       SearchContext.current().fieldData().getForField(parentFieldMapper);
   BitDocIdSetFilter parentFilter =
       wrapWithBitSetFilter(new TermFilter(new Term(TypeFieldMapper.NAME, "parent")));
   int minChildren = random().nextInt(10);
   int maxChildren = scaledRandomIntBetween(minChildren, 10);
   Query query =
       new ChildrenQuery(
           parentChildIndexFieldData,
           "parent",
           "child",
           parentFilter,
           childQuery,
           scoreType,
           minChildren,
           maxChildren,
           12,
           wrapWithBitSetFilter(NonNestedDocsFilter.INSTANCE));
   QueryUtils.check(query);
 }
  public void testQuery() throws IOException {
    IndexSearcher searcher = newSearcher(reader);

    // Making sure the query yields 25 documents with the facet "a"
    DrillDownQuery q = new DrillDownQuery(config);
    q.add("a");
    System.out.println("q=" + q);
    QueryUtils.check(q);
    TopDocs docs = searcher.search(q, 100);
    assertEquals(25, docs.totalHits);

    // Making sure the query yields 5 documents with the facet "b" and the
    // previous (facet "a") query as a base query
    DrillDownQuery q2 = new DrillDownQuery(config, q);
    q2.add("b");
    docs = searcher.search(q2, 100);
    assertEquals(5, docs.totalHits);

    // Making sure that a query of both facet "a" and facet "b" yields 5 results
    DrillDownQuery q3 = new DrillDownQuery(config);
    q3.add("a");
    q3.add("b");
    docs = searcher.search(q3, 100);

    assertEquals(5, docs.totalHits);
    // Check that content:foo (which yields 50% results) and facet/b (which yields 20%)
    // would gather together 10 results (10%..)
    Query fooQuery = new TermQuery(new Term("content", "foo"));
    DrillDownQuery q4 = new DrillDownQuery(config, fooQuery);
    q4.add("b");
    docs = searcher.search(q4, 100);
    assertEquals(10, docs.totalHits);
  }
 @Test
 public void testBasicQuerySanities() {
   Query childQuery = new TermQuery(new Term("field", "value"));
   ScoreType scoreType = ScoreType.values()[random().nextInt(ScoreType.values().length)];
   ParentFieldMapper parentFieldMapper =
       SearchContext.current().mapperService().documentMapper("child").parentFieldMapper();
   ParentChildIndexFieldData parentChildIndexFieldData =
       SearchContext.current().fieldData().getForField(parentFieldMapper);
   Query query =
       new TopChildrenQuery(
           parentChildIndexFieldData,
           childQuery,
           "child",
           "parent",
           scoreType,
           1,
           1,
           wrapWithBitSetFilter(NonNestedDocsFilter.INSTANCE));
   QueryUtils.check(query);
 }
 @Test
 public void testBasicQuerySanities() {
   Query childQuery = new TermQuery(new Term("field", "value"));
   ParentFieldMapper parentFieldMapper =
       SearchContext.current().mapperService().documentMapper("child").parentFieldMapper();
   ParentChildIndexFieldData parentChildIndexFieldData =
       SearchContext.current().fieldData().getForField(parentFieldMapper);
   BitDocIdSetFilter parentFilter =
       wrapWithBitSetFilter(new TermFilter(new Term(TypeFieldMapper.NAME, "parent")));
   Query query =
       new ChildrenConstantScoreQuery(
           parentChildIndexFieldData,
           childQuery,
           "parent",
           "child",
           parentFilter,
           12,
           wrapWithBitSetFilter(NonNestedDocsFilter.INSTANCE));
   QueryUtils.check(query);
 }
Example #7
0
 // just basic equals/hashcode etc
 public void testMoreLikeThisQuery() throws Exception {
   Analyzer analyzer = new MockAnalyzer(random());
   Query query = new MoreLikeThisQuery("this is a test", new String[] {"text"}, analyzer, "text");
   QueryUtils.check(random(), query, searcher);
   analyzer.close();
 }
 /**
  * Perform searching for word by word content.
  *
  * @param content the content used to search.
  * @param luceneDirPath the lucene index path.
  * @return a list of found documents.
  * @throws java.io.IOException if the path to the lucene index is incorrect.
  */
 public static List<Document> performSearchByContent(String content, String luceneDirPath)
     throws IOException {
   String indexDirPath = luceneDirPath + PACKAGE_PATH;
   return performSearch(
       QueryUtils.buildPhraseQuery(content), LuceneUtils.getLuceneSearcher(indexDirPath));
 }