org.apache.lucene.queryparser.classic.ParseException Java Examples

The following examples show how to use org.apache.lucene.queryparser.classic.ParseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RetrievalApp.java    From lucene4ir with Apache License 2.0 6 votes vote down vote up
public ScoreDoc[] runQuery(String qno, String queryTerms){
    ScoreDoc[] hits = null;

    System.out.println("Query No.: " + qno + " " + queryTerms);
    try {
        Query query = parser.parse(QueryParser.escape(queryTerms));

        try {
            TopDocs results = searcher.search(query, p.maxResults);
            hits = results.scoreDocs;
        }
        catch (IOException ioe){
            ioe.printStackTrace();
            System.exit(1);
        }
    } catch (ParseException pe){
        pe.printStackTrace();
        System.exit(1);
    }
    return hits;
}
 
Example #2
Source File: LuceneSearcher.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static Query buildQuery(String keyword) {
    try {

        Analyzer analyzer = createAnalyzer();
        //这里使用text,防止搜索出html的tag或者tag中属性
        QueryParser queryParser1 = new QueryParser("text", analyzer);
        Query termQuery1 = queryParser1.parse(keyword);
        BooleanClause booleanClause1 = new BooleanClause(termQuery1, BooleanClause.Occur.SHOULD);


        QueryParser queryParser2 = new QueryParser("title", analyzer);
        Query termQuery2 = queryParser2.parse(keyword);
        BooleanClause booleanClause2 = new BooleanClause(termQuery2, BooleanClause.Occur.SHOULD);

        BooleanQuery.Builder builder = new BooleanQuery.Builder();
        builder.add(booleanClause1).add(booleanClause2);

        return builder.build();
    } catch (ParseException e) {
        LOG.error(e.toString(), e);
    }
    return null;
}
 
Example #3
Source File: LuceneCondition.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public Query query(Schema schema) {

    if (query == null) {
        throw new IllegalArgumentException("Query statement required");
    }

    try {
        Analyzer analyzer = schema.getAnalyzer();
        QueryParser queryParser = new QueryParser(defaultField, analyzer);
        queryParser.setAllowLeadingWildcard(true);
        queryParser.setLowercaseExpandedTerms(false);
        Query luceneQuery = queryParser.parse(query);
        luceneQuery.setBoost(boost);
        return luceneQuery;
    } catch (ParseException e) {
        throw new RuntimeException("Error while parsing lucene syntax query", e);
    }
}
 
Example #4
Source File: UserInputQueryBuilder.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Query getQuery(Element e) throws ParserException {
  String text = DOMUtils.getText(e);
  try {
    Query q = null;
    if (unSafeParser != null) {
      //synchronize on unsafe parser
      synchronized (unSafeParser) {
        q = unSafeParser.parse(text);
      }
    } else {
      String fieldName = DOMUtils.getAttribute(e, "fieldName", defaultField);
      //Create new parser
      QueryParser parser = createQueryParser(fieldName, analyzer);
      q = parser.parse(text);
    }
    float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
    return new BoostQuery(q, boost);
  } catch (ParseException e1) {
    throw new ParserException(e1.getMessage());
  }
}
 
Example #5
Source File: ProductIndex.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public List<ProductCatalogEntry> search(String queryString) throws IOException, ParseException {
	List<ProductCatalogEntry> results = new ArrayList<ProductCatalogEntry>();
	
	IndexReader reader = DirectoryReader.open(dir);
	IndexSearcher searcher = new IndexSearcher(reader);
	Analyzer analyzer = new SimpleAnalyzer();
	
	QueryParser parser = new QueryParser(searchField, analyzer);
	Query query = parser.parse(queryString);
	
	TopDocs docs = searcher.search(query, 100);
	ScoreDoc[] hits = docs.scoreDocs;
	
	for (ScoreDoc sd: hits) {
		Document doc = searcher.doc(sd.doc);
		results.add(prodcat.getProductById(doc.get("id")));
	}
	reader.close();
	
	return results;
}
 
Example #6
Source File: SuperParserTest.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Test
public void test4() throws ParseException {
  Query query = parser.parse("<a.a:a a.d:e a.b:b>  -<b.c:c b.d:d>");

  BooleanQuery booleanQuery1 = new BooleanQuery();
  booleanQuery1.add(new TermQuery(new Term("a.a", "a")), Occur.SHOULD);
  booleanQuery1.add(new TermQuery(new Term("a.d", "e")), Occur.SHOULD);
  booleanQuery1.add(new TermQuery(new Term("a.b", "b")), Occur.SHOULD);

  BooleanQuery booleanQuery2 = new BooleanQuery();
  booleanQuery2.add(new TermQuery(new Term("b.c", "c")), Occur.SHOULD);
  booleanQuery2.add(new TermQuery(new Term("b.d", "d")), Occur.SHOULD);

  SuperQuery superQuery1 = new SuperQuery(booleanQuery1, ScoreType.SUPER, new Term("_primedoc_"));
  SuperQuery superQuery2 = new SuperQuery(booleanQuery2, ScoreType.SUPER, new Term("_primedoc_"));

  BooleanQuery booleanQuery = new BooleanQuery();
  booleanQuery.add(superQuery1, Occur.SHOULD);
  booleanQuery.add(superQuery2, Occur.MUST_NOT);

  assertQuery(booleanQuery, query);
}
 
Example #7
Source File: InMemoryLuceneIndex.java    From tutorials with MIT License 6 votes vote down vote up
public List<Document> searchIndex(String inField, String queryString) {
    try {
        Query query = new QueryParser(inField, analyzer).parse(queryString);

        IndexReader indexReader = DirectoryReader.open(memoryIndex);
        IndexSearcher searcher = new IndexSearcher(indexReader);
        TopDocs topDocs = searcher.search(query, 10);
        List<Document> documents = new ArrayList<>();
        for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
            documents.add(searcher.doc(scoreDoc.doc));
        }

        return documents;
    } catch (IOException | ParseException e) {
        e.printStackTrace();
    }
    return null;

}
 
Example #8
Source File: OLuceneIndexType.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
public static Query createFullQuery(OIndexDefinition index, Object key, Analyzer analyzer, Version version) throws ParseException {

    String query = "";
    if (key instanceof OCompositeKey) {
      Object params = ((OCompositeKey) key).getKeys().get(0);
      if (params instanceof Map) {
        Object q = ((Map) params).get("q");
        if (q != null) {
          query = q.toString();
        }
      } else {
        query = params.toString();

      }
    } else {
      query = key.toString();
    }

    return getQueryParser(index, query, analyzer, version);

  }
 
Example #9
Source File: GlobalSearchResultBuilderTest.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testVariants() throws ParseException {
	final String[] queries = {"carry", "bismillah", "me", "nothing else matters", "nothing AND matters"};
	final boolean[] bools = {Boolean.FALSE, Boolean.TRUE};
	final int maxMaxNumberOfResults = 10;
	ScoreDoc after = null;

	GlobalSearchCategory[] categories = null;
	for (String query : queries) {
		for (boolean highlightResult : bools) {
			for (int maxNumberOfResults = 1; maxNumberOfResults <= maxMaxNumberOfResults; maxNumberOfResults++) {
				for (boolean simpleMode : bools) {
					GlobalSearchResultBuilder gsr = new GlobalSearchResultBuilder(query).setHighlightResult(highlightResult).setMaxNumberOfResults(maxNumberOfResults).setSimpleMode(simpleMode).setSearchOffset(after).setSearchCategories(categories);
					GlobalSearchResult searchResult = gsr.runSearch();
					Assert.assertNotNull(searchResult);
					if (highlightResult) {
						Assert.assertEquals(searchResult.getNumberOfResults(), searchResult.getBestFragments().size());
					} else {
						Assert.assertNull(searchResult.getBestFragments());
					}
					Assert.assertTrue("Should not find more results than expected", searchResult.getNumberOfResults() <= maxMaxNumberOfResults);
				}
			}
		}
	}
}
 
Example #10
Source File: SuperParserTest.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Test
public void test28() throws ParseException {
  SpatialContext ctx = SpatialContext.GEO;
  ShapeReadWriter<SpatialContext> shapeReadWriter = new ShapeReadWriter<SpatialContext>(ctx);
  int maxLevels = 11;
  SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
  RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false);
  Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_KM));
  SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);

  String writeSpatialArgs = SpatialArgsParser.writeSpatialArgs(args, shapeReadWriter);

  // This has to be done because of rounding.
  SpatialArgs spatialArgs = SpatialArgsParser.parse(writeSpatialArgs, shapeReadWriter);
  Query q1 = sq(strategy.makeQuery(spatialArgs));
  Query q = parseSq("a.id_gis:\"" + writeSpatialArgs + "\"");
  boolean equals = q1.equals(q);
  assertTrue(equals);
}
 
Example #11
Source File: LuceneSearchQueryGenerator.java    From Stargraph with MIT License 6 votes vote down vote up
private static Query fuzzyPhraseSearch(String field, String searchTerm, int maxEdits) {
    StringBuilder queryStr = new StringBuilder();
    queryStr.append(field).append(":(");

    String words[] = searchTerm.split("\\s+");
    for (int i = 0; i < words.length; i++) {
        if (i > 0) {
            queryStr.append(" AND ");
        }
        queryStr.append(ComplexPhraseQueryParser.escape(words[i])).append("~").append(maxEdits);
    }
    queryStr.append(")");

    try {
        return new ComplexPhraseQueryParser("value", new StandardAnalyzer()).parse(queryStr.toString());
    } catch (ParseException e) {
        throw new StarGraphException(e);
    }
}
 
Example #12
Source File: SORecommender.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
public TopDocs executeQuery(org.apache.lucene.search.Query query) throws IOException, ParseException {
	Directory indexDir = FSDirectory.open(Paths.get(INDEX_DIRECTORY));
	try {
		IndexReader reader = DirectoryReader.open(indexDir);
		IndexSearcher searcher = new IndexSearcher(reader);
		if (isBm25 == false) {
			ClassicSimilarity CS = new ClassicSimilarity();
			searcher.setSimilarity(CS);
		}
		TopDocs docs = searcher.search(query, hitsPerPage);
		return docs;
	} catch (Exception e) {
		logger.error(e.getMessage());
		return null;
	}
}
 
Example #13
Source File: AlfrescoSolrDataModel.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Query getCMISQuery(CMISQueryMode mode, Pair<SearchParameters, Boolean> searchParametersAndFilter, SolrQueryRequest req, org.alfresco.repo.search.impl.querymodel.Query queryModelQuery, CmisVersion cmisVersion, String alternativeDictionary) throws ParseException
{
    SearchParameters searchParameters = searchParametersAndFilter.getFirst();
    Boolean isFilter = searchParametersAndFilter.getSecond();

    CmisFunctionEvaluationContext functionContext = getCMISFunctionEvaluationContext(mode, cmisVersion, alternativeDictionary);

    Set<String> selectorGroup = queryModelQuery.getSource().getSelectorGroups(functionContext).get(0);

    LuceneQueryBuilderContext<Query, Sort, ParseException> luceneContext = getLuceneQueryBuilderContext(searchParameters, req, alternativeDictionary, FTSQueryParser.RerankPhase.SINGLE_PASS);
    @SuppressWarnings("unchecked")
    LuceneQueryBuilder<Query, Sort, ParseException> builder = (LuceneQueryBuilder<Query, Sort, ParseException>) queryModelQuery;
    org.apache.lucene.search.Query luceneQuery = builder.buildQuery(selectorGroup, luceneContext, functionContext);

    return new ContextAwareQuery(luceneQuery, Boolean.TRUE.equals(isFilter) ? null : searchParameters);
}
 
Example #14
Source File: ComplexPhraseQueryParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void parsePhraseElements(ComplexPhraseQueryParser qp) throws ParseException {
  // TODO ensure that field-sensitivity is preserved ie the query
  // string below is parsed as
  // field+":("+phrasedQueryStringContents+")"
  // but this will need code in rewrite to unwrap the first layer of
  // boolean query

  String oldDefaultParserField = qp.field;
  try {
    //temporarily set the QueryParser to be parsing the default field for this phrase e.g author:"fred* smith"
    qp.field = this.field;
    contents[0] = qp.parse(phrasedQueryStringContents);
  }
  finally {
    qp.field = oldDefaultParserField;
  }
}
 
Example #15
Source File: ComplexPhraseQueryParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void checkPhraseClauseIsForSameField(String field)
    throws ParseException {
  if (!field.equals(currentPhraseQuery.field)) {
    throw new ParseException("Cannot have clause for field \"" + field
        + "\" nested in phrase " + " for field \"" + currentPhraseQuery.field
        + "\"");
  }
}
 
Example #16
Source File: TestExtendableQueryParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testUnescapedExtDelimiter() throws Exception {
  Extensions ext = newExtensions(':');
  ext.add("testExt", new ExtensionStub());
  ExtendableQueryParser parser = (ExtendableQueryParser) getParser(null, ext);
  expectThrows(ParseException.class, () -> {
    parser.parse("aField:testExt:\"foo \\& bar\"");
  });
}
 
Example #17
Source File: ComplexPhraseQueryParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected Query newTermQuery(Term term, float boost) {
  if (isPass2ResolvingPhrases) {
    try {
      checkPhraseClauseIsForSameField(term.field());
    } catch (ParseException pe) {
      throw new RuntimeException("Error parsing complex phrase", pe);
    }
  }
  return super.newTermQuery(term, boost);
}
 
Example #18
Source File: SuperParserTest.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Test
public void test45() throws ParseException {
  SpatialContext ctx = SpatialContext.GEO;
  int maxLevels = 11;
  SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
  RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false);
  Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_MI));
  SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);

  Query q1 = sq(bq(bc_m(strategy.makeQuery(args))));
  Query q = parseSq("<+a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0m))\">");
  boolean equals = q1.equals(q);
  assertTrue(equals);
}
 
Example #19
Source File: SecureAtomicReaderTestBase.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Test
public void testTermWalk() throws IOException, ParseException {
  SecureAtomicReader secureReader = getSecureReader();
  Fields fields = secureReader.fields();

  assertEquals(0, getTermCount(fields, "termmask")); // read mask
  assertEquals(0, getTermWithSeekCount(fields, "termmask")); // read mask
  assertEquals(0, getTermCount(fields, "shouldnotsee")); // discover
  assertEquals(0, getTermWithSeekCount(fields, "shouldnotsee")); // discover
  assertEquals(1, getTermCount(fields, "test"));
  assertEquals(1, getTermWithSeekCount(fields, "test"));

  secureReader.close();
}
 
Example #20
Source File: LuceneIndex.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private Pair<Document, Map<String, Shape>> retrieveOrCreate(String docID, IndexSearcher searcher) throws IOException {
    Document doc;
    TopDocs hits = searcher.search(new TermQuery(new Term(DOCID, docID)), 10);
    Map<String, Shape> geofields = Maps.newHashMap();

    if (hits.scoreDocs.length > 1)
        throw new IllegalArgumentException("More than one document found for document id: " + docID);

    if (hits.scoreDocs.length == 0) {
        if (log.isTraceEnabled())
            log.trace("Creating new document for [{}]", docID);

        doc = new Document();
        doc.add(new StringField(DOCID, docID, Field.Store.YES));
    } else {
        if (log.isTraceEnabled())
            log.trace("Updating existing document for [{}]", docID);

        int docId = hits.scoreDocs[0].doc;
        //retrieve the old document
        doc = searcher.doc(docId);
        for (IndexableField field : doc.getFields()) {
            if (field.stringValue().startsWith(GEOID)) {
                try {
                    geofields.put(field.name(), ctx.readShapeFromWkt(field.stringValue().substring(GEOID.length())));
                } catch (java.text.ParseException e) {
                    throw new IllegalArgumentException("Geoshape was unparsable");
                }
            }
        }
    }

    return new ImmutablePair<Document, Map<String, Shape>>(doc, geofields);
}
 
Example #21
Source File: ElasticsearchIndexer.java    From datashare with GNU Affero General Public License v3.0 5 votes vote down vote up
static boolean hasLuceneOperators(String query) throws ParseException {
    String sanitizedQueryForLucene = query.replaceAll("\\^(?!\\d)", "\\^1");
    org.apache.lucene.queryparser.classic.QueryParser parser =
            new org.apache.lucene.queryparser.classic.QueryParser("",
                    new StandardAnalyzer(new CharArraySet(0, false)));
    parser.setAllowLeadingWildcard(true);

    return hasOperator(parser.parse(sanitizedQueryForLucene));
}
 
Example #22
Source File: ITestPersistentProvenanceRepository.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompressOnRollover() throws IOException, InterruptedException, ParseException {
    assumeFalse(isWindowsEnvironment());
    final RepositoryConfiguration config = createConfiguration();
    config.setMaxEventFileLife(500, TimeUnit.MILLISECONDS);
    config.setCompressOnRollover(true);
    repo = new PersistentProvenanceRepository(config, DEFAULT_ROLLOVER_MILLIS);
    repo.initialize(getEventReporter(), null, null, IdentifierLookup.EMPTY);

    final String uuid = "00000000-0000-0000-0000-000000000000";
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("abc", "xyz");
    attributes.put("xyz", "abc");
    attributes.put("filename", "file-" + uuid);

    final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder();
    builder.setEventTime(System.currentTimeMillis());
    builder.setEventType(ProvenanceEventType.RECEIVE);
    builder.setTransitUri("nifi://unit-test");
    attributes.put("uuid", uuid);
    builder.fromFlowFile(createFlowFile(3L, 3000L, attributes));
    builder.setComponentId("1234");
    builder.setComponentType("dummy processor");

    for (int i = 0; i < 10; i++) {
        builder.fromFlowFile(createFlowFile(i, 3000L, attributes));
        repo.registerEvent(builder.build());
    }

    repo.waitForRollover();
    final File storageDir = config.getStorageDirectories().values().iterator().next();
    final File compressedLogFile = new File(storageDir, "0.prov.gz");
    assertTrue(compressedLogFile.exists());
}
 
Example #23
Source File: HelpManagerImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * @see org.sakaiproject.api.app.help.HelpManager#searchResources(java.lang.String)
 */
public Set<Resource> searchResources(String queryStr)
{
	initialize();

	try
	{
		return searchResources(queryStr, "content");
	}
	catch (ParseException e)
	{
		log.debug("ParseException parsing Help search query  " + queryStr, e);
		return null;
	}
}
 
Example #24
Source File: CurriculoService.java    From Easy-Cassandra-samples with Apache License 2.0 5 votes vote down vote up
public List<Resume> procurarCV(String texto) {
	try {
		List<String> ids = search.findByBio(texto);
		return (List<Resume>) repository.findAll(ids);
	} catch (ParseException | IOException e) {
		e.printStackTrace();
	}
	return Collections.emptyList();
}
 
Example #25
Source File: CatalogSearch.java    From oodt with Apache License 2.0 5 votes vote down vote up
public static Query ParseQuery(String query) {
    // note that "__FREE__" is a control work for free text searching
    QueryParser parser = new QueryParser(freeTextBlock, new CASAnalyzer());
    Query luceneQ = null;
    try {
        luceneQ = (Query) parser.parse(query);
    } catch (ParseException e) {
        System.out.println("Error parsing query text.");
        System.exit(-1);
    }
    return luceneQ;
}
 
Example #26
Source File: ComplexPhraseQueryParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected Query getRangeQuery(String field, String part1, String part2,
    boolean startInclusive, boolean endInclusive) throws ParseException {
  if (isPass2ResolvingPhrases) {
    checkPhraseClauseIsForSameField(field);
  }
  return super.getRangeQuery(field, part1, part2, startInclusive, endInclusive);
}
 
Example #27
Source File: SearchController.java    From bookshop with MIT License 5 votes vote down vote up
@RequestMapping("searchBook.do")
public ModelAndView searchBook(Book book) throws IOException, ParseException {

    ModelAndView mav = new ModelAndView("searchBook");

    // 关键字
    String keyword = book.getName();
    System.out.println(keyword);
    // 准备中文分词器
    IKAnalyzer analyzer = new IKAnalyzer();
    // 索引
    Directory index = createIndex(analyzer);
    // 查询器
    Query query = new QueryParser("name",analyzer).parse(keyword);
    // 搜索
    IndexReader reader = DirectoryReader.open(index);
    IndexSearcher searcher = new IndexSearcher(reader);
    int numberPerPage = 10;
    ScoreDoc[] hits = searcher.search(query,numberPerPage).scoreDocs;
    List<Book> books = new ArrayList<>();
    for (int i = 0; i < hits.length; i++) {
        ScoreDoc scoreDoc = hits[i];
        int docId = scoreDoc.doc;
        Document document = searcher.doc(docId);
        Book tmpBook = bookService.get(Integer.parseInt(document.get("id")));
        books.add(tmpBook);
    }

    mav.addObject("books",books);
    return mav;
}
 
Example #28
Source File: SuperParserTest.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Test
public void test47() throws ParseException {
  SpatialContext ctx = SpatialContext.GEO;
  int maxLevels = 11;
  SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
  RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false);
  Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_MI));
  SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);

  Query q1 = sq(strategy.makeQuery(args));
  Query q = parseSq("<a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0m))\">");
  boolean equals = q1.equals(q);
  assertTrue(equals);
}
 
Example #29
Source File: SuperParserTest.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Test
public void test2() throws ParseException {
  Query query = parser.parse("<a.c:c a.d:d>");

  BooleanQuery booleanQuery = new BooleanQuery();
  booleanQuery.add(new TermQuery(new Term("a.c", "c")), Occur.SHOULD);
  booleanQuery.add(new TermQuery(new Term("a.d", "d")), Occur.SHOULD);
  SuperQuery superQuery = new SuperQuery(booleanQuery, ScoreType.SUPER, new Term("_primedoc_"));

  assertQuery(superQuery, query);
}
 
Example #30
Source File: CaseSensitiveQueryParser.java    From vxquery with Apache License 2.0 5 votes vote down vote up
@Override
protected Query getPrefixQuery(String field, String termStr) throws ParseException {
    if (!getAllowLeadingWildcard() && termStr.startsWith("*"))
        throw new ParseException("'*' not allowed as first character in PrefixQuery");
    Term t = new Term(field, termStr);
    return newPrefixQuery(t);
}