@@ -2115,29 +2115,37 @@ void init() {
21152115 addEncodedParam (params , "q" , text );
21162116 }
21172117 }
2118- if (queryDef instanceof RawQueryDefinition ) {
2118+ if (queryDef instanceof StructuredQueryDefinition ) {
2119+ structure = ((StructuredQueryDefinition ) queryDef ).serialize ();
2120+
2121+ if (logger .isDebugEnabled ()) {
2122+ String text = ((StringQueryDefinition ) queryDef ).getCriteria ();
2123+ String qtextMessage = text == null ? "" : " and string query \" " + text + "\" " ;
2124+ logger .debug ("Searching for structure {}{}" , structure , qtextMessage );
2125+ }
2126+
2127+ String payloadMimetype = "application/xml" ;
2128+ if (queryDef instanceof RawQueryDefinition ) {
2129+ StructureWriteHandle handle = ((RawQueryDefinition ) queryDef ).getHandle ();
2130+ baseHandle = HandleAccessor .checkHandle (handle , "search" );
2131+
2132+ Format payloadFormat = getStructuredQueryFormat (baseHandle );
2133+ payloadMimetype = getMimetypeWithDefaultXML (payloadFormat , baseHandle );
2134+ }
2135+
2136+ webResource = getConnection ().path ("search" ).queryParams (params );
2137+ builder = (payloadMimetype != null ) ?
2138+ webResource .type (payloadMimetype ).accept (mimetype ) :
2139+ webResource .accept (mimetype );
2140+ } else if (queryDef instanceof RawQueryDefinition ) {
21192141 if (logger .isDebugEnabled ())
21202142 logger .debug ("Raw search" );
21212143
2122- StructureWriteHandle handle =
2123- ((RawQueryDefinition ) queryDef ).getHandle ();
2124-
2144+ StructureWriteHandle handle = ((RawQueryDefinition ) queryDef ).getHandle ();
21252145 baseHandle = HandleAccessor .checkHandle (handle , "search" );
21262146
2127- Format payloadFormat = baseHandle .getFormat ();
2128- if (payloadFormat == Format .UNKNOWN )
2129- payloadFormat = null ;
2130- else if (payloadFormat != Format .XML && payloadFormat != Format .JSON )
2131- throw new IllegalArgumentException (
2132- "Cannot perform raw search for " +payloadFormat .name ());
2133-
2134- String payloadMimetype = baseHandle .getMimetype ();
2135- if (payloadFormat != null ) {
2136- if (payloadMimetype == null )
2137- payloadMimetype = payloadFormat .getDefaultMimetype ();
2138- } else if (payloadMimetype == null ) {
2139- payloadMimetype = "application/xml" ;
2140- }
2147+ Format payloadFormat = getStructuredQueryFormat (baseHandle );
2148+ String payloadMimetype = getMimetypeWithDefaultXML (payloadFormat , baseHandle );
21412149
21422150 String path = (queryDef instanceof RawQueryByExampleDefinition ) ?
21432151 "qbe" : "search" ;
@@ -2167,14 +2175,6 @@ else if (payloadFormat != Format.XML && payloadFormat != Format.JSON)
21672175
21682176 webResource = getConnection ().path ("keyvalue" ).queryParams (params );
21692177 builder = webResource .accept (mimetype );
2170- } else if (queryDef instanceof StructuredQueryDefinition ) {
2171- structure = ((StructuredQueryDefinition ) queryDef ).serialize ();
2172-
2173- if (logger .isDebugEnabled ())
2174- logger .debug ("Searching for structure {}" , structure );
2175-
2176- webResource = getConnection ().path ("search" ).queryParams (params );
2177- builder = webResource .type ("application/xml" ).accept (mimetype );
21782178 } else if (queryDef instanceof CombinedQueryDefinition ) {
21792179 structure = ((CombinedQueryDefinition ) queryDef ).serialize ();
21802180
@@ -2275,6 +2275,28 @@ ClientResponse getResponse() {
22752275 }
22762276 }
22772277
2278+ private Format getStructuredQueryFormat (HandleImplementation baseHandle ) {
2279+ Format payloadFormat = baseHandle .getFormat ();
2280+ if (payloadFormat == Format .UNKNOWN ) {
2281+ payloadFormat = null ;
2282+ } else if (payloadFormat != Format .XML && payloadFormat != Format .JSON ) {
2283+ throw new IllegalArgumentException (
2284+ "Cannot perform raw search for format " +payloadFormat .name ());
2285+ }
2286+ return payloadFormat ;
2287+ }
2288+
2289+ private String getMimetypeWithDefaultXML (Format payloadFormat , HandleImplementation baseHandle ) {
2290+ String payloadMimetype = baseHandle .getMimetype ();
2291+ if (payloadFormat != null ) {
2292+ if (payloadMimetype == null )
2293+ payloadMimetype = payloadFormat .getDefaultMimetype ();
2294+ } else if (payloadMimetype == null ) {
2295+ payloadMimetype = "application/xml" ;
2296+ }
2297+ return payloadMimetype ;
2298+ }
2299+
22782300 @ Override
22792301 public void deleteSearch (RequestLogger reqlog , DeleteQueryDefinition queryDef ,
22802302 Transaction transaction ) throws ForbiddenUserException ,
@@ -2908,7 +2930,9 @@ public <R extends UrisReadHandle> R uris(RequestLogger reqlog, Transaction trans
29082930 if (qdef instanceof StructuredQueryDefinition ) {
29092931 String structure = ((StructuredQueryDefinition ) qdef ).serialize ();
29102932
2911- logger .debug ("Query uris with structured query {}" , structure );
2933+ String text = ((StringQueryDefinition ) qdef ).getCriteria ();
2934+ String qtextMessage = text == null ? "" : " and string query \" " + text + "\" " ;
2935+ logger .debug ("Query uris with structured query {}{}" , structure , qtextMessage );
29122936 if (structure != null ) {
29132937 params .add ("structuredQuery" , structure );
29142938 }
@@ -4794,20 +4818,20 @@ public InputStream match(QueryDefinition queryDef,
47944818 addEncodedParam (params , "q" , text );
47954819 }
47964820 }
4797- if (queryDef instanceof RawQueryDefinition ) {
4798- StructureWriteHandle handle = ((RawQueryDefinition ) queryDef ).getHandle ();
4799- baseHandle = HandleAccessor .checkHandle (handle , "match" );
4821+ if (queryDef instanceof StructuredQueryDefinition ) {
4822+ structure = ((StructuredQueryDefinition ) queryDef ).serialize ();
48004823
48014824 if (logger .isDebugEnabled ())
4802- logger .debug ("Searching for structure {}" , structure );
4825+ logger .debug ("Searching for structure {}" ,
4826+ structure );
48034827
48044828 builder = makeBuilder ("alert/match" , params , "application/xml" , "application/xml" );
4805- } else if (queryDef instanceof StructuredQueryDefinition ) {
4806- structure = ((StructuredQueryDefinition ) queryDef ).serialize ();
4829+ } else if (queryDef instanceof RawQueryDefinition ) {
4830+ StructureWriteHandle handle = ((RawQueryDefinition ) queryDef ).getHandle ();
4831+ baseHandle = HandleAccessor .checkHandle (handle , "match" );
48074832
48084833 if (logger .isDebugEnabled ())
4809- logger .debug ("Searching for structure {}" ,
4810- structure );
4834+ logger .debug ("Searching for structure {}" , structure );
48114835
48124836 builder = makeBuilder ("alert/match" , params , "application/xml" , "application/xml" );
48134837 } else if (queryDef instanceof StringQueryDefinition ) {
0 commit comments