@@ -398,6 +398,28 @@ public TermQuery term(double weight, String... terms) {
398398 public StructuredQueryDefinition value (TextIndex index , String ... values ) {
399399 return new ValueQuery (index , null , null , null , values );
400400 }
401+ /**
402+ * Matches an element, attribute, json key, or field
403+ * that has a value with the same boolean value as at least one
404+ * of the criteria values.
405+ * @param index the value container
406+ * @param value either true or false
407+ * @return the StructuredQueryDefinition for the value query
408+ */
409+ public StructuredQueryDefinition value (TextIndex index , Boolean value ) {
410+ return new ValueQuery (index , null , null , null , new Object [] {value });
411+ }
412+ /**
413+ * Matches an element, attribute, json key, or field
414+ * that has a value with the same numeric value as at least one
415+ * of the criteria values.
416+ * @param index the value container
417+ * @param values the possible values to match
418+ * @return the StructuredQueryDefinition for the value query
419+ */
420+ public StructuredQueryDefinition value (TextIndex index , Number ... values ) {
421+ return new ValueQuery (index , null , null , null , values );
422+ }
401423 /**
402424 * Matches an element, attribute, json key, or field
403425 * that has a value with the same string value as at least one
@@ -412,6 +434,34 @@ public StructuredQueryDefinition value(TextIndex index, String... values) {
412434 public StructuredQueryDefinition value (TextIndex index , FragmentScope scope , String [] options , double weight , String ... values ) {
413435 return new ValueQuery (index , scope , options , weight , values );
414436 }
437+ /**
438+ * Matches an element, attribute, json key, or field
439+ * that has a value with the same boolean value as at least one
440+ * of the criteria values.
441+ * @param index the value container
442+ * @param scope whether the query matches the document content or properties
443+ * @param options options for fine tuning the query
444+ * @param weight the multiplier for the match in the document ranking
445+ * @param value either true or false
446+ * @return the StructuredQueryDefinition for the value query
447+ */
448+ public StructuredQueryDefinition value (TextIndex index , FragmentScope scope , String [] options , double weight , Boolean value ) {
449+ return new ValueQuery (index , scope , options , weight , new Object [] {value });
450+ }
451+ /**
452+ * Matches an element, attribute, json key, or field
453+ * that has a value with the same numeric value as at least one
454+ * of the criteria values.
455+ * @param index the value container
456+ * @param scope whether the query matches the document content or properties
457+ * @param options options for fine tuning the query
458+ * @param weight the multiplier for the match in the document ranking
459+ * @param values the possible values to match
460+ * @return the StructuredQueryDefinition for the value query
461+ */
462+ public StructuredQueryDefinition value (TextIndex index , FragmentScope scope , String [] options , double weight , Number ... values ) {
463+ return new ValueQuery (index , scope , options , weight , values );
464+ }
415465
416466 /**
417467 * Matches an element, attribute, json key, or field
@@ -1636,16 +1686,48 @@ void innerSerialize(XMLStreamWriter serializer) throws Exception {
16361686 }
16371687
16381688 class ValueQuery
1639- extends TextQuery {
1640- ValueQuery (TextIndex index , FragmentScope scope ,
1641- String [] options , Double weight , String [] values ) {
1642- super (index , scope , options , weight , values );
1643- }
1644- @ Override
1645- void innerSerialize (XMLStreamWriter serializer ) throws Exception {
1646- serializer .writeStartElement ("value-query" );
1647- super .innerSerialize (serializer );
1648- serializer .writeEndElement ();
1689+ extends AbstractStructuredQuery {
1690+ TextIndex index ;
1691+ FragmentScope scope ;
1692+ String [] options ;
1693+ Double weight ;
1694+ Object [] values ;
1695+ ValueQuery (TextIndex index , FragmentScope scope ,
1696+ String [] options , Double weight , Object [] values ) {
1697+ this .index = index ;
1698+ this .scope = scope ;
1699+ this .options = options ;
1700+ this .weight = weight ;
1701+ this .values = values ;
1702+ }
1703+ void innerSerialize (XMLStreamWriter serializer ) throws Exception {
1704+ serializer .writeStartElement ("value-query" );
1705+ ((IndexImpl ) index ).innerSerialize (serializer );
1706+ if (scope != null ) {
1707+ if (scope == FragmentScope .DOCUMENT ) {
1708+ writeText (serializer , "fragment-scope" , "documents" );
1709+ }
1710+ else {
1711+ writeText (serializer , "fragment-scope" ,
1712+ scope .toString ().toLowerCase ());
1713+ }
1714+ }
1715+ if ( values != null ) {
1716+ for ( Object value : values ) {
1717+ if ( value == null ) {
1718+ serializer .writeEmptyElement ("null" );
1719+ } else if ( value instanceof String ) {
1720+ writeText (serializer , "text" , value );
1721+ } else if ( value instanceof Number ) {
1722+ writeText (serializer , "number" , value );
1723+ } else if ( value instanceof Boolean ) {
1724+ writeText (serializer , "boolean" , value );
1725+ }
1726+ }
1727+ }
1728+ writeTextList (serializer , "term-option" , options );
1729+ writeText (serializer , "weight" , weight );
1730+ serializer .writeEndElement ();
16491731 }
16501732 }
16511733
0 commit comments