Organizational Research By

Surprising Reserch Topic

Question:hwo to make query in solr for search the data from solr database?


Querying Data

Searches are done via HTTP GET on the select URL with the query string in the q parameter. You can pass a number of optional request parameters to the request handler to control what information is returned. For example, you can use the "fl" parameter to control what stored fields are returned, and if the relevancy score is returned:

    q=video&fl=name,id (return only name and id fields)
    q=video&fl=name,id,score (return relevancy score as well)
    q=video&fl=*,score (return all stored fields, as well as relevancy score)
    q=video&sort=price desc&fl=name,id,price (add sort specification: sort by price descending)
    q=video&wt=json (return response in JSON format)

The query form provided in the web admin interface allows setting various request parameters and is useful when testing or debugging queries.

asked Sep 13, 2013 in SOLR by rajesh
edited Sep 12, 2013
0 votes
73 views



Related Hot Questions

2 Answers

0 votes

Searching

Let's see if we can retrieve the document we just added.

Since Solr accepts HTTP requests, you can use your web browser to communicate with Solr: http://localhost:8983/solr/select?q=*:*&wt=json

This returns the following JSON result:

{
    "responseHeader": {
        "status": 0,
        "QTime": 0,
        "params": {
            "wt": "json",
            "q": "*:*"
        }
    },
    "response": {
        "numFound": 1,
        "start": 0,
        "docs": [
            {
                "id": "3007WFP",
                "name": "Dell Widescreen UltraSharp 3007WFP",
                "manu": "Dell, Inc.",
                "includes": "USB cable",
                "weight": 401.6,
                "price": 2199,
                "popularity": 6,
                "inStock": true,
                "store": "43.17614,-90.57341",
                "cat": [
                    "electronics",
                    "monitor"
                ],
                "features": [
                    "30\" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast"
                ]
            }
        ]
    }
}

Nice! A quick verification with monitor.xml should confirm that all is in order.

Note that the previous search query used the special *:* syntax to retrieve all documents.

Let's now add all the XML documents, and do some real searching.

./post.sh *.xml

Here's a demonstration of retrieving the name and id of all documents with inStock = false: http://localhost:8983/solr/select?q=inStock:false&wt=json&fl=id,name

{
    "responseHeader": {
        "status": 0,
        "QTime": 2,
        "params": {
            "wt": "json",
            "q": "inStock:false",
            "fl": "id,name"
        }
    },
    "response": {
        "numFound": 4,
        "start": 0,
        "docs": [
            {
                "id": "F8V7067-APL-KIT",
                "name": "Belkin Mobile Power Cord for iPod w/ Dock"
            },
            {
                "id": "IW-02",
                "name": "iPod & iPod Mini USB 2.0 Cable"
            },
            {
                "id": "EN7800GTX/2DHTV/256M",
                "name": "ASUS Extreme N7800GTX/2DHTV (256 MB)"
            },
            {
                "id": "100-435805",
                "name": "ATI Radeon X1900 XTX 512 MB PCIE Video Card"
            }
        ]
    }
}

You'll learn more about the various URL query parameters in a separate tutorial.

Shutdown

To shutdown Solr, from the terminal where you launched Solr, hit Ctrl+C. This will shutdown Solr cleanly.

Solr is fairly robust, so even in situations of OS or disk crashes, it is unlikely that Solr's index will become corrupted.

 

answered Sep 13, 2013 by rajesh
edited Sep 12, 2013
0 votes

Searching

Let's see if we can retrieve the document we just added.

Since Solr accepts HTTP requests, you can use your web browser to communicate with Solr: http://localhost:8983/solr/select?q=*:*&wt=json

This returns the following JSON result:

{
    "responseHeader": {
        "status": 0,
        "QTime": 0,
        "params": {
            "wt": "json",
            "q": "*:*"
        }
    },
    "response": {
        "numFound": 1,
        "start": 0,
        "docs": [
            {
                "id": "3007WFP",
                "name": "Dell Widescreen UltraSharp 3007WFP",
                "manu": "Dell, Inc.",
                "includes": "USB cable",
                "weight": 401.6,
                "price": 2199,
                "popularity": 6,
                "inStock": true,
                "store": "43.17614,-90.57341",
                "cat": [
                    "electronics",
                    "monitor"
                ],
                "features": [
                    "30\" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast"
                ]
            }
        ]
    }
}

Nice! A quick verification with monitor.xml should confirm that all is in order.

Note that the previous search query used the special *:* syntax to retrieve all documents.

Let's now add all the XML documents, and do some real searching.

./post.sh *.xml

Here's a demonstration of retrieving the name and id of all documents with inStock = false: http://localhost:8983/solr/select?q=inStock:false&wt=json&fl=id,name

{
    "responseHeader": {
        "status": 0,
        "QTime": 2,
        "params": {
            "wt": "json",
            "q": "inStock:false",
            "fl": "id,name"
        }
    },
    "response": {
        "numFound": 4,
        "start": 0,
        "docs": [
            {
                "id": "F8V7067-APL-KIT",
                "name": "Belkin Mobile Power Cord for iPod w/ Dock"
            },
            {
                "id": "IW-02",
                "name": "iPod & iPod Mini USB 2.0 Cable"
            },
            {
                "id": "EN7800GTX/2DHTV/256M",
                "name": "ASUS Extreme N7800GTX/2DHTV (256 MB)"
            },
            {
                "id": "100-435805",
                "name": "ATI Radeon X1900 XTX 512 MB PCIE Video Card"
            }
        ]
    }
}

You'll learn more about the various URL query parameters in a separate tutorial.

Shutdown

To shutdown Solr, from the terminal where you launched Solr, hit Ctrl+C. This will shutdown Solr cleanly.

Solr is fairly robust, so even in situations of OS or disk crashes, it is unlikely that Solr's index will become corrupted.

 

answered Sep 13, 2013 by rajesh
edited Sep 12, 2013

...