lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Solr Wiki] Update of "SolJSON" by CassandraTargett
Date Wed, 02 Nov 2016 19:13:26 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.

The "SolJSON" page has been changed by CassandraTargett:
https://wiki.apache.org/solr/SolJSON?action=diff&rev1=20&rev2=21

Comment:
migrate most content to Ref Guide

+ {{{#!wiki important
+ This page exists for the Solr Community to share Tips, Tricks, and Advice about the
+ [[https://cwiki.apache.org/solr/Response+Writers#ResponseWriters-JSONResponseWriter|JSON
Response Writer]].
+ 
+ Reference material previously located on this page has been migrated to the
+ [[https://cwiki.apache.org/solr/|Official Solr Reference Guide]].
+ If you need help, please consult the Reference Guide for the version of Solr you are using
+ for the specific details about using [[https://cwiki.apache.org/solr/Response+Writers#ResponseWriters-JSONResponseWriter|this
feature]].
+ 
+ If you'd like to share information about how you use this feature, please [[FrontPage#How_to_edit_this_Wiki|add
it to this page]].
+ /* cwikimigrated */
+ }}}
+ 
  ## page was renamed from SolAjax
  
  = JSON Response Writer =
@@ -10, +23 @@

  See [[UpdateJSON]]
  
  == JSON Query Response Format ==
- Solr can return the result of a query in [[http://www.json.org/|JSON]] rather than the default
XML format.  This is enabled via the request parameter {{{wt=json}}}
  
- Variations of the JSON format are supported for [[SolPython|Python]] and [[Ruby Response
Format|Ruby]].
- 
- Example JSON output:
- http://localhost:8983/solr/select/?q=video&indent=on&hl=true&hl.fl=name,features&facet=true&facet.field=cat&facet.mincount=1&wt=json
- {{{
- {
-  "responseHeader":{
-   "status":0,
-   "QTime":10,
-   "params":{
- 	"wt":"json",
- 	"facet":"true",
- 	"hl.fl":"name,features",
- 	"facet.mincount":"1",
- 	"facet.field":"cat",
- 	"indent":"on",
- 	"hl":"true",
- 	"q":"video"}},
-  "response":{"numFound":3,"start":0,"docs":[
- 	{
- 	 "id":"MA147LL/A",
- 	 "sku":"MA147LL/A",
- 	 "name":"Apple 60 GB iPod with Video Playback Black",
- 	 "manu":"Apple Computer Inc.",
- 	 "includes":"earbud headphones, USB cable",
- 	 "weight":5.5,
- 	 "price":399.0,
- 	 "popularity":10,
- 	 "inStock":true,
- 	 "timestamp":"2007-01-31T05:12:44.562Z",
- 	 "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"]},
- 	{
- 	 "id":"EN7800GTX/2DHTV/256M",
- 	 "sku":"EN7800GTX/2DHTV/256M",
- 	 "name":"ASUS Extreme N7800GTX/2DHTV (256 MB)",
- 	 "manu":"ASUS Computer Inc.",
- 	 "weight":16.0,
- 	 "price":479.95,
- 	 "popularity":7,
- 	 "inStock":false,
- 	 "timestamp":"2007-01-31T05:12:45.187Z",
- 	 "cat":[
- 	  "electronics",
- 	  "graphics card"],
- 	 "features":[
- 	  "NVIDIA GeForce 7800 GTX GPU/VPU clocked at 486MHz",
- 	  "256MB GDDR3 Memory clocked at 1.35GHz",
- 	  "PCI Express x16",
- 	  "Dual DVI connectors, HDTV out, video input",
- 	  "OpenGL 2.0, DirectX 9.0"]},
- 	{
- 	 "id":"100-435805",
- 	 "sku":"100-435805",
- 	 "name":"ATI Radeon X1900 XTX 512 MB PCIE Video Card",
- 	 "manu":"ATI Technologies",
- 	 "weight":48.0,
- 	 "price":649.99,
- 	 "popularity":7,
- 	 "inStock":false,
- 	 "timestamp":"2007-01-31T05:12:45.203Z",
- 	 "cat":[
- 	  "electronics",
- 	  "graphics card"],
- 	 "features":[
- 	  "ATI RADEON X1900 GPU/VPU clocked at 650MHz",
- 	  "512MB GDDR3 SDRAM clocked at 1.55GHz",
- 	  "PCI Express x16",
- 	  "dual DVI, HDTV, svideo, composite out",
- 	  "OpenGL 2.0, DirectX 9.0"]}]
-  },
-  "facet_counts":{
-   "facet_queries":{},
-   "facet_fields":{
- 	"cat":[
- 	 "electronics",3,
- 	 "card",2,
- 	 "graphics",2,
- 	 "music",1]}},
-  "highlighting":{
-   "MA147LL/A":{
- 	"name":["Apple 60 GB iPod with <em>Video</em> Playback Black"],
- 	"features":["Stores up to 15,000 songs, 25,000 photos, or 150 hours of <em>video</em>"]},
-   "EN7800GTX/2DHTV/256M":{
- 	"features":["Dual DVI connectors, HDTV out, <em>video</em> input"]},
-   "100-435805":{
- 	"name":["ATI Radeon X1900 XTX 512 MB PCIE <em>Video</em> Card"]}}
- }
- 
- }}}
  
  == JSON specific parameters ==
+ 
-  * wt=json - choose JSON output for the response
-  * json.nl - This parameter controls the output format of !NamedLists, where order is more
important than access by name.  !NamedList is currently used for field faceting data.
-   * json.nl=flat - the default.  !NamedList is represented as a flat array, alternating
names and values: {{{[name1,val1, name2,val2]}}} 
-   * json.nl=map - !NamedList is represented as a JSON object.  Although this is the simplest
mapping, a !NamedList can have optional keys, repeated keys, and preserves order.  Using a
JSON object (essentially a map or hash) for a !NamedList results in the loss of some information.
-   * json.nl=arrarr - represent a !NamedList as an array of two element arrays {{{[[name1,val1],
[name2, val2], [name3,val3]]}}}
-   * Note: json.nl also works for the [[SolPython|Python]] and [[SolRuby|Ruby]] output formats.
-  * json.wrf=function - adds a wrapper-function around the JSON response, useful in AJAX
with dynamic script tags for specifying a !JavaScript callback function.
-    * http://www.xml.com/pub/a/2005/12/21/json-dynamic-script-tag.html
-    * http://www.theurer.cc/blog/2005/12/15/web-services-json-dump-your-proxy/
  
  == Using Solr's JSON output for AJAX ==
  Note: also see [[http://wiki.apache.org/solr/IntegratingSolr|Solr Client Libraries]] for
higher level !JavaScript clients for Solr.
@@ -130, +36 @@

  
  {{{ var rsp = eval("("+jsonResponseString+")"); }}}
  
- Here is a simple functional example.  
+ Here is a simple functional example.
  
- To install it, place in somewhere accessible in the same server running Solr. 
+ To install it, place in somewhere accessible in the same server running Solr.
  
  For example jetty server, save the text below to ''webapps/ajax/ajax.html'' and browse to
http://localhost:8983/ajax/ajax.html
  
@@ -146, +52 @@

      var xmlHttpReq = false;
      var self = this;
      if (window.XMLHttpRequest) { // Mozilla/Safari
-         self.xmlHttpReq = new XMLHttpRequest(); 
+         self.xmlHttpReq = new XMLHttpRequest();
      }
      else if (window.ActiveXObject) { // IE
          self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
@@ -198, +104 @@

  <body>
  
  <form name="f1" onsubmit='xmlhttpPost("/solr/select"); return false;'>
-   <p>query: <input name="query" type="text">  
+   <p>query: <input name="query" type="text">
    <input value="Go" type="submit"></p>
-   
+ 
  <div id="result"></div>
  <p/><pre>Raw JSON String: <div id="raw"></div></pre>
  </form>
@@ -210, +116 @@

  
  <!> '''Potential UTF-8 encoding issue'''
  
- This is a small note: In some environment, the default javascript ''escape()''  may fail
to encoded non-ASCII character into the utf-8 encoded string, which will make the search failed.

+ This is a small note: In some environment, the default javascript ''escape()''  may fail
to encoded non-ASCII character into the utf-8 encoded string, which will make the search failed.
  
  To solve the problem universally, please refer the utf-8 encoding package by webtoolkit.info
to write your own encoding function:
  http://www.webtoolkit.info/javascript-url-decode-encode.html

Mime
View raw message