Return-Path: X-Original-To: apmail-lucene-java-user-archive@www.apache.org Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7D56A1843B for ; Tue, 22 Mar 2016 21:52:06 +0000 (UTC) Received: (qmail 20666 invoked by uid 500); 22 Mar 2016 21:52:05 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 20592 invoked by uid 500); 22 Mar 2016 21:52:05 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 20581 invoked by uid 99); 22 Mar 2016 21:52:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Mar 2016 21:52:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 3B206C7751 for ; Tue, 22 Mar 2016 21:52:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.509 X-Spam-Level: X-Spam-Status: No, score=-0.509 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 3WEEQRZRpwtR for ; Tue, 22 Mar 2016 21:52:02 +0000 (UTC) Received: from mail10.mayo.edu (mail10.mayo.edu [129.176.114.198]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id E9B425F560 for ; Tue, 22 Mar 2016 21:52:01 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.24,379,1454997600"; d="scan'208";a="90835742" Received: from roedlp004a.mayo.edu (HELO mail10.mayo.edu) ([10.146.65.139]) by ironport10-dlp.mayo.edu with ESMTP; 22 Mar 2016 16:51:54 -0500 Message-Id: <519743$2mk2ot@ironport10.mayo.edu> X-IronPort-AV: E=Sophos;i="5.24,379,1454997600"; d="scan'208";a="90835741" Received: from essexmb.mayo.edu (HELO msgoms03.mayo.edu) ([10.128.209.12]) by ironport10.mayo.edu with ESMTP; 22 Mar 2016 16:51:54 -0500 Date: Tue, 22 Mar 2016 21:51:54 +0000 From: "Bauer, Herbert S. (Scott)" Subject: Re: Serializing Queries In-reply-to: To: "java-user@lucene.apache.org" Content-id: <4DEF702B20E21A4885D015CA2A8F6758@exchange.mayo.edu> MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-language: en-US Content-transfer-encoding: quoted-printable Accept-Language: en-US Thread-topic: Serializing Queries Thread-index: AQHRgR7B4MzlSdfgbUaHVq7HuV5LCZ9fT3lfgAa4XQA= X-MS-Has-Attach: X-MS-TNEF-Correlator: x-esetresult: clean, is OK x-esetid: 19A47B3E9C6E31384CE125 References: <519743$2lopq3@ironport10.mayo.edu> User-Agent: Microsoft-MacOutlook/14.6.2.160219 X-CFilter-Loop: Reflected This seems to work for me. Unfortunately I had to stick with the 2.2.1 version myself. Thanks to our use of an old version of spring I had some asm version clashes. I did also make use of the custom serializers found here: https://github.com/magro/kryo-serializers.git writing: ByteArrayOutputStream baos =3D new ByteArrayOutputStream(); Output output =3D new Output(baos); Kryo kryo =3D new Kryo(); kryo.setRegistrationRequired(false); kryo.setInstantiatorStrategy(new StdInstantiatorStrategy()); UnmodifiableCollectionsSerializer.registerSerializers(kryo); kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer()); kryo.register(BooleanClause.class); kryo.register(Query.class); kryo.register(Occur.class); kryo.register(ToParentBlockJoinQuery.class); kryo.register(QueryBitSetProducer.class); SynchronizedCollectionsSerializer.registerSerializers(kryo); kryo.writeClassAndObject(output, (List) builder.build().clauses()); output.close(); String outputString =3D Base64.encodeBase64String(baos.toByteArray()); Reading: String inputString =3D (String) in.readObject(); ByteArrayInputStream bais =3D new ByteArrayInputStream(Base64.decodeBase64(inputString)); Input input =3D new Input(bais); Kryo kryo =3D new Kryo(); kryo.setRegistrationRequired(false); kryo.setInstantiatorStrategy(new StdInstantiatorStrategy()); UnmodifiableCollectionsSerializer.registerSerializers(kryo); kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer()); kryo.register(BooleanClause.class); kryo.register(Query.class); kryo.register(Occur.class); kryo.register(ToParentBlockJoinQuery.class); kryo.register(QueryBitSetProducer.class); SynchronizedCollectionsSerializer.registerSerializers(kryo); @SuppressWarnings("unchecked") List queryObject =3D (List) kryo.readClassAndObject(input); input.close(); builder =3D new BooleanQuery.Builder(); for (BooleanClause clause : queryObject) { builder.add(clause); } Base64 didn=B9t line up perfectly either, but I found an apache commons version that worked. Not sure all the class registration was necessary. I=B9m really grateful for the code sample and direction. This seems to be = a very effective tool for solving a lot of serialization problems that could have been tough to solve. On 3/18/16, 10:44 AM, "McKinley, James T" wrote: >We use Kryo to pass query objects between hosts: > >https://github.com/EsotericSoftware/kryo > >We initially had some trouble with it creating dynamic classes and >running out of PermGen space but we got around that using an ObjectPool: > >http://commons.apache.org/proper/commons-pool/api-1.6/org/apache/commons/p >ool/impl/StackObjectPool.html > >I've not looked at the project recently, we're using version 2.21 and >there's a 3.0.0 now, so they may have solved the issues we had and made >things nicer, but here's how we're doing it with 2.21: > >To serialize: > >static private ObjectPool pool =3D new StackObjectPool(new >KryoFactory(), 75, 75); > >ByteArrayOutputStream baos =3D new ByteArrayOutputStream(); >Output output =3D new Output(baos); >kryo =3D pool.borrowObject(); >kryo.writeClassAndObject(output, query); >pool.returnObject(kryo); >output.close(); >String base64EncodedSerializedObject =3D >Base64.encodeBytes(baos.toByteArray()); > >Where query is a Lucene Query object (I've left out the error handling >for brevity). > >To deserialize: > >ByteArrayInputStream bais =3D new >ByteArrayInputStream(Base64.decode(encodedQuery)); >Input input =3D new Input(bais); >kryo =3D pool.borrowObject(); >deserializedQueryObject =3D (Query) kryo.readClassAndObject(input); >pool.returnObject(kryo); >input.close(); > >Hope that might help. > >Jim > >________________________________________ >From: Bauer, Herbert S. (Scott) >Sent: 18 March 2016 10:02 >To: java-user@lucene.apache.org >Subject: Serializing Queries > >Has anyone in this group solved the problem of serializing complex >boolean queries (Some of our clauses have span and other query types)? >Our Java RMI depends upon being able to do so. I have seen posts that >say you can just parse the string representation but apparently that only >works on simple query representations. I=B9m looking at the CoreParser >and it=B9s supporting xml parsing capabilities with an eye toward >Marshalling the boolean query into a DOM object and unmarshalling it on >the server side using some of the support implied by the CoreParser and >related classes. -scott >--------------------------------------------------------------------- >To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org >For additional commands, e-mail: java-user-help@lucene.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org