chris-yoon90 / Automated-facets

0 stars 0 forks source link

Solr with Java Eclipse (SolrJ) #22

Closed chris-yoon90 closed 11 years ago

chris-yoon90 commented 11 years ago

General information can be found here

I wrote a simple JUnit Test that can connect to Solr Data base and get query results. It looks something like this:

@Test
public void testBasicSearch() throws SolrServerException {
    SolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("q", "cat:electronics");

    try {
        QueryResponse response = solr.query(params);
        SolrDocumentList results = response.getResults();
        for (int i = 0; i < results.size(); i++) {
            System.err.println(results.get(i));
        }

    } catch (SolrServerException e) {
        e.printStackTrace();
        throw e;
    }
}

Now, the only downside with this is that I need to start jetty using java -jar start.jar before I run this code. Not really a big problem but I think there is a way to start Jetty automatically as part of the application. I'll do more research on that and post it here.

chris-yoon90 commented 11 years ago

This is the response I get after running the code [main] INFO org.apache.solr.client.solrj.impl.HttpClientUtil - Creating new http client, config:maxConnections=128&maxConnectionsPerHost=32&followRedirects=false SolrDocument{id=SP2514N, name=Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133, manu=Samsung Electronics Co. Ltd., manu_id_s=samsung, cat=[electronics, hard drive], features=[7200RPM, 8MB cache, IDE Ultra ATA-133, NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor], price=92.0, price_c=92,USD, popularity=6, inStock=true, manufacturedate_dt=Mon Feb 13 07:26:37 PST 2006, store=35.0752,-97.032, _version_=1436881101616316416} SolrDocument{id=6H500F0, name=Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300, manu=Maxtor Corp., manu_id_s=maxtor, cat=[electronics, hard drive], features=[SATA 3.0Gb/s, NCQ, 8.5ms seek, 16MB cache], price=350.0, price_c=350,USD, popularity=6, inStock=true, store=45.17614,-93.87341, manufacturedate_dt=Mon Feb 13 07:26:37 PST 2006, _version_=1436881101619462144} SolrDocument{id=F8V7067-APL-KIT, name=Belkin Mobile Power Cord for iPod w/ Dock, manu=Belkin, manu_id_s=belkin, cat=[electronics, connector], features=[car power adapter, white], weight=4.0, price=19.95, price_c=19.95,USD, popularity=1, inStock=false, store=45.18014,-93.87741, manufacturedate_dt=Mon Aug 01 09:30:25 PDT 2005, _version_=1436881101623656448} SolrDocument{id=IW-02, name=iPod & iPod Mini USB 2.0 Cable, manu=Belkin, manu_id_s=belkin, cat=[electronics, connector], features=[car power adapter for iPod, white], weight=2.0, price=11.5, price_c=11.50,USD, popularity=1, inStock=false, store=37.7752,-122.4232, manufacturedate_dt=Tue Feb 14 15:55:59 PST 2006, _version_=1436881101627850752} SolrDocument{id=MA147LL/A, name=Apple 60 GB iPod with Video Playback Black, manu=Apple Computer Inc., manu_id_s=apple, cat=[electronics, music], features=[iTunes, Podcasts, Audiobooks, Stores up to 15,000 songs, 25,000 photos, or 150 hours of video, 2.5-inch, 320x240 color TFT LCD display with LED backlight, Up to 20 hours of battery life, Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video, Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication], includes=earbud headphones, USB cable, weight=5.5, price=399.0, price_c=399.00,USD, popularity=10, inStock=true, store=37.7752,-100.0232, manufacturedate_dt=Wed Oct 12 01:00:00 PDT 2005, _version_=1436881101632045056} SolrDocument{id=TWINX2048-3200PRO, name=CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail, manu=Corsair Microsystems Inc., manu_id_s=corsair, cat=[electronics, memory], features=[CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader], price=185.0, price_c=185,USD, popularity=5, inStock=true, store=37.7752,-122.4232, manufacturedate_dt=Mon Feb 13 07:26:37 PST 2006, payloads=electronics|6.0 memory|3.0, _version_=1436881101646725120} SolrDocument{id=VS1GB400C3, name=CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail, manu=Corsair Microsystems Inc., manu_id_s=corsair, cat=[electronics, memory], price=74.99, price_c=74.99,USD, popularity=7, inStock=true, store=37.7752,-100.0232, manufacturedate_dt=Mon Feb 13 07:26:37 PST 2006, payloads=electronics|4.0 memory|2.0, _version_=1436881101650919424} SolrDocument{id=VDBDB1A16, name=A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM, manu=A-DATA Technology Inc., manu_id_s=corsair, cat=[electronics, memory], features=[CAS latency 3, 2.7v], popularity=0, inStock=true, store=45.18414,-93.88141, manufacturedate_dt=Mon Feb 13 07:26:37 PST 2006, payloads=electronics|0.9 memory|0.1, _version_=1436881101653016576} SolrDocument{id=VA902B, name=ViewSonic VA902B - flat panel display - TFT - 19", manu=ViewSonic Corp., manu_id_s=viewsonic, cat=[electronics, monitor], features=[19" TFT active matrix LCD, 8ms response time, 1280 x 1024 native resolution], weight=190.4, price=279.95, price_c=279.95,USD, popularity=6, inStock=true, store=45.18814,-93.88541, _version_=1436881101665599488} SolrDocument{id=3007WFP, name=Dell Widescreen UltraSharp 3007WFP, manu=Dell, Inc., manu_id_s=dell, cat=[electronics, monitor], features=[30" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast], includes=USB cable, weight=401.6, price=2199.0, price_c=2199,USD, popularity=6, inStock=true, store=43.17614,-90.57341, _version_=1436881101669793792}

chris-yoon90 commented 11 years ago

Actually, never mind on my comment about starting Jetty automatically as part of the application. Now that I think about it, that's over-complicating things and I'm not sure if that can be done.

chris-yoon90 commented 11 years ago

github repo for SolrJ. Seems like it's part of the main Solr development.

https://github.com/apache/lucene-solr/tree/trunk/solr/solrj