The LucidWorks Platform includes a simple Search UI, but if you are going to build your own user interface, or your own application to access the data stored in LucidWorks, you will need to access the underlying engine directly.
LucidWorks is built on Apache Solr, so the techniques necessary for performing a search against it are the same as those for performing a search against Solr. In other words, an HTTP call to a URL of:
{code:borderStyle=solid|borderColor=#666666}http://127.0.0.1:8888/solr/collection1/select/?q=NickChase{code}
Would return a result such as this:
{code:borderStyle=solid|borderColor=#666666}
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">99</int>
<lst name="params">
<str name="q">NickChase</str>
</lst>
</lst>
<result name="response" numFound="151" start="0">
<doc>
<str name="geo">none</str>
<str name="id">29059644164939776</str>
<int name="retweetCount">0</int>
<str name="source">web</str>
<str name="text">Working on a Twitter app; anybody got a preferred Java Twitter library?</str>
<arr name="text_medium">
<str>NickChase</str>
<str>en</str>
<str/>
<str>web</str>
<str>Working on a Twitter app; anybody got a preferred Java Twitter library?</str>
<str>2011-01-23T06:15:33.000Z</str>
<str>0</str>
</arr>
<date name="timestamp">2011-02-13T14:06:53.191Z</date>
<arr name="userId">
<str>99999999</str>
</arr>
<str name="userLang">en</str>
<str name="userName">Nicholas Chase</str>
<str name="userScreenName">NickChase</str>
</doc>
...
</result>
</response>{code}
You can then consume that XML from within your application.
While XML is the default output format, LucidWorks supports multiple formats, including JSON, CSV, and even object formats such as PHP, Java, and Python.
In general, to change the output format, use the {{wt}} parameter, as in:
{code:borderStyle=solid|borderColor=#666666}http://127.0.0.1:8888/solr/collection1/select/?q=NickChase&wt=json{code}
This provides a response of
{code:borderStyle=solid|borderColor=#666666}
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"wt":"json",
"q":"NickChase"
}
},
"response":{
"numFound":151,
"start":0,
"docs":[
{
"id":"29059644164939776",
"userName":"Nicholas Chase",
"userScreenName":"NickChase",
"userLang":"en",
"source":"web",
"text":"Working on a Twitter app; anybody got a preferred Java Twitter library?",
"retweetCount":0,
"timestamp":"2011-02-13T14:06:53.191Z",
"geo":"none",
"text_medium":["NickChase","en","","web","Working on a Twitter app; anybody got a preferred Java Twitter library?",
"2011-01-23T06:15:33.000Z","0"],
"userId":["99999999"]
}
...
]
}
}
{code}
The structure of the results depends on the options you choose in the request string. For example, you can specify faceting and highlighting;
{code:borderStyle=solid|borderColor=#666666}http://127.0.0.1:8888/solr/collection1/select/?q=twitter&facet=on&facet.field=userScreenName&hl=true&hl.fl=text{code}
Which gives a result such as this:
{code:borderStyle=solid|borderColor=#666666}
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">359</int>
<lst name="params">
<str name="facet">on</str>
<str name="facet.field">userScreenName</str>
<str name="hl.fl">text</str>
<str name="hl">true</str>
<str name="q">twitter</str>
</lst>
</lst>
<result name="response" numFound="2190" start="0">
<doc>
<str name="geo">none</str>
<str name="id">38402455221829632</str>
<arr name="objectType">
<str>twStatus</str>
</arr>
<int name="retweetCount">0</int>
<str name="source"><a href="http://twitter.com/" rel="nofollow">Twitter for iPhone</a></str>
<str name="text">RT @Onventive: Really useful Twitter Android code RT @enbake Developing an android twitter
client using twitter4j http://is.gd/1YUFyY #a ...</str>
<arr name="text_medium">
<str>t4j_news</str>
<str>en</str>
<str/>
<str><a href="http://twitter.com/" rel="nofollow">Twitter for iPhone</a></str>
<str>RT @Onventive: Really useful Twitter Android code RT @enbake Developing an android twitter
client using twitter4j http://is.gd/1YUFyY #a ...</str>
<str>2011-02-18T01:00:33.000Z</str>
<str>0</str>
</arr>
<date name="timestamp">2011-02-18T01:45:05.52Z</date>
<arr name="userId">
<str>88888888</str>
</arr>
<str name="userLang">en</str>
<str name="userName">t4j_news</str>
<str name="userScreenName">t4j_news</str>
</doc>
...
</result>
<lst name="facet_counts">
<lst name="facet_queries"/>
<lst name="facet_fields">
<lst name="userScreenName">
<int name="beaker">189</int>
<int name="cloudexpo">35</int>
<int name="randybias">35</int>
<int name="getjavajob">26</int>
...
</lst>
</lst>
<lst name="facet_dates"/>
<lst name="facet_ranges"/>
</lst>
<lst name="highlighting">
<lst name="38402455221829632">
<arr name="text">
<str>RT @Onventive: Really useful <span class="highlight">Twitter</span> Android code RT
@enbake Developing an android <span class="highlight">twitter</span> client</str>
</arr>
</lst>
...
</response>
{code}
Notice the structure of the search response: it starts with the {{responseHeader}} block, which provides information such as the query, whether you have specified highlighting, and so on.
Next is the {{result}} block, which shows the actual documents returned by the search, along with the {{numFound}} and {{start}} attributes, which specify the total number of results and the starting position for the results returned in this response. For each document, LucidWorks Enterprise returns all fields that are marked as {{stored=true}} in the field definition.
If you have specified faceting, next you will see facet counts for each field specified. You can then use that information to build links to your narrowed search. For example, we started with the query:
{code:borderStyle=solid|borderColor=#666666}http://127.0.0.1:8888/solr/collection1/select/?q=twitter&facet=on&facet.field=userScreenName&hl=true&hl.fl=text{code}
If you then wanted to build a link to results narrowed on the {{userScreenName cloudExpo}}, it would look like this:
{code:borderStyle=solid|borderColor=#666666}http://127.0.0.1:8888/solr/collection1/select/?q=twitter&facet=on&hl=true&hl.fl=text&fq=userScreenName:cloudExpo{code}
This way you have the same set of results, with the additional filter query of {{userScreenName:cloudExpo}}, which selects only the documents with a {{userScreenName}} field of {{cloudExpo}}.
After the facet information comes the {{highlighting}} block. Highlighting consists of snippets with the relevant information marked up appropriately. (By default, terms are marked up as a {{span}} with the class {{highlight}}, so you can use CSS to style them however you like.) Each snippet is contained in a block that refers back to the {{id}} value of the original document. So in this case, the {{name}} attribute of {{38402455221829632}} refers back to {{doc}} with an {{id}} of {{38402455221829632}}. You can then use this information to build your web application.
As far as how to actually use these responses, you can either work with them directly, or use the Solr API as provided for your programming language. For example, a SolrJ request looks something like this:
{code:borderStyle=solid|borderColor=#666666}
SolrServer server = new CommonsHttpSolrServer("http://localhost:8888/solr/collection1");
SolrQuery query = new SolrQuery();
query.setQuery( "twitter" );
query.addSortField( "timestamp", SolrQuery.ORDER.desc );
QueryResponse rsp = server.query( query );
SolrDocumentList docs = rsp.getResults();
for (SolrDocument doc : docs){
System.out.println((String)doc.getFieldValue("id")+": ");
System.out.println((String)doc.getFieldValue("userScreenName")+" -- "+(String)doc.getFieldValue("text"));
}
{code}
Here you are creating a connection to the server, then creating and executing the request. From there, you can manipulate documents as you see fit.
APIs exist for most programming languages. You can find a list of bindings on the [Solr Wiki|http://wiki.apache.org/solr/IntegratingSolr].
{scrollbar}
LucidWorks is built on Apache Solr, so the techniques necessary for performing a search against it are the same as those for performing a search against Solr. In other words, an HTTP call to a URL of:
{code:borderStyle=solid|borderColor=#666666}http://127.0.0.1:8888/solr/collection1/select/?q=NickChase{code}
Would return a result such as this:
{code:borderStyle=solid|borderColor=#666666}
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">99</int>
<lst name="params">
<str name="q">NickChase</str>
</lst>
</lst>
<result name="response" numFound="151" start="0">
<doc>
<str name="geo">none</str>
<str name="id">29059644164939776</str>
<int name="retweetCount">0</int>
<str name="source">web</str>
<str name="text">Working on a Twitter app; anybody got a preferred Java Twitter library?</str>
<arr name="text_medium">
<str>NickChase</str>
<str>en</str>
<str/>
<str>web</str>
<str>Working on a Twitter app; anybody got a preferred Java Twitter library?</str>
<str>2011-01-23T06:15:33.000Z</str>
<str>0</str>
</arr>
<date name="timestamp">2011-02-13T14:06:53.191Z</date>
<arr name="userId">
<str>99999999</str>
</arr>
<str name="userLang">en</str>
<str name="userName">Nicholas Chase</str>
<str name="userScreenName">NickChase</str>
</doc>
...
</result>
</response>{code}
You can then consume that XML from within your application.
While XML is the default output format, LucidWorks supports multiple formats, including JSON, CSV, and even object formats such as PHP, Java, and Python.
In general, to change the output format, use the {{wt}} parameter, as in:
{code:borderStyle=solid|borderColor=#666666}http://127.0.0.1:8888/solr/collection1/select/?q=NickChase&wt=json{code}
This provides a response of
{code:borderStyle=solid|borderColor=#666666}
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"wt":"json",
"q":"NickChase"
}
},
"response":{
"numFound":151,
"start":0,
"docs":[
{
"id":"29059644164939776",
"userName":"Nicholas Chase",
"userScreenName":"NickChase",
"userLang":"en",
"source":"web",
"text":"Working on a Twitter app; anybody got a preferred Java Twitter library?",
"retweetCount":0,
"timestamp":"2011-02-13T14:06:53.191Z",
"geo":"none",
"text_medium":["NickChase","en","","web","Working on a Twitter app; anybody got a preferred Java Twitter library?",
"2011-01-23T06:15:33.000Z","0"],
"userId":["99999999"]
}
...
]
}
}
{code}
The structure of the results depends on the options you choose in the request string. For example, you can specify faceting and highlighting;
{code:borderStyle=solid|borderColor=#666666}http://127.0.0.1:8888/solr/collection1/select/?q=twitter&facet=on&facet.field=userScreenName&hl=true&hl.fl=text{code}
Which gives a result such as this:
{code:borderStyle=solid|borderColor=#666666}
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">359</int>
<lst name="params">
<str name="facet">on</str>
<str name="facet.field">userScreenName</str>
<str name="hl.fl">text</str>
<str name="hl">true</str>
<str name="q">twitter</str>
</lst>
</lst>
<result name="response" numFound="2190" start="0">
<doc>
<str name="geo">none</str>
<str name="id">38402455221829632</str>
<arr name="objectType">
<str>twStatus</str>
</arr>
<int name="retweetCount">0</int>
<str name="source"><a href="http://twitter.com/" rel="nofollow">Twitter for iPhone</a></str>
<str name="text">RT @Onventive: Really useful Twitter Android code RT @enbake Developing an android twitter
client using twitter4j http://is.gd/1YUFyY #a ...</str>
<arr name="text_medium">
<str>t4j_news</str>
<str>en</str>
<str/>
<str><a href="http://twitter.com/" rel="nofollow">Twitter for iPhone</a></str>
<str>RT @Onventive: Really useful Twitter Android code RT @enbake Developing an android twitter
client using twitter4j http://is.gd/1YUFyY #a ...</str>
<str>2011-02-18T01:00:33.000Z</str>
<str>0</str>
</arr>
<date name="timestamp">2011-02-18T01:45:05.52Z</date>
<arr name="userId">
<str>88888888</str>
</arr>
<str name="userLang">en</str>
<str name="userName">t4j_news</str>
<str name="userScreenName">t4j_news</str>
</doc>
...
</result>
<lst name="facet_counts">
<lst name="facet_queries"/>
<lst name="facet_fields">
<lst name="userScreenName">
<int name="beaker">189</int>
<int name="cloudexpo">35</int>
<int name="randybias">35</int>
<int name="getjavajob">26</int>
...
</lst>
</lst>
<lst name="facet_dates"/>
<lst name="facet_ranges"/>
</lst>
<lst name="highlighting">
<lst name="38402455221829632">
<arr name="text">
<str>RT @Onventive: Really useful <span class="highlight">Twitter</span> Android code RT
@enbake Developing an android <span class="highlight">twitter</span> client</str>
</arr>
</lst>
...
</response>
{code}
Notice the structure of the search response: it starts with the {{responseHeader}} block, which provides information such as the query, whether you have specified highlighting, and so on.
Next is the {{result}} block, which shows the actual documents returned by the search, along with the {{numFound}} and {{start}} attributes, which specify the total number of results and the starting position for the results returned in this response. For each document, LucidWorks Enterprise returns all fields that are marked as {{stored=true}} in the field definition.
If you have specified faceting, next you will see facet counts for each field specified. You can then use that information to build links to your narrowed search. For example, we started with the query:
{code:borderStyle=solid|borderColor=#666666}http://127.0.0.1:8888/solr/collection1/select/?q=twitter&facet=on&facet.field=userScreenName&hl=true&hl.fl=text{code}
If you then wanted to build a link to results narrowed on the {{userScreenName cloudExpo}}, it would look like this:
{code:borderStyle=solid|borderColor=#666666}http://127.0.0.1:8888/solr/collection1/select/?q=twitter&facet=on&hl=true&hl.fl=text&fq=userScreenName:cloudExpo{code}
This way you have the same set of results, with the additional filter query of {{userScreenName:cloudExpo}}, which selects only the documents with a {{userScreenName}} field of {{cloudExpo}}.
After the facet information comes the {{highlighting}} block. Highlighting consists of snippets with the relevant information marked up appropriately. (By default, terms are marked up as a {{span}} with the class {{highlight}}, so you can use CSS to style them however you like.) Each snippet is contained in a block that refers back to the {{id}} value of the original document. So in this case, the {{name}} attribute of {{38402455221829632}} refers back to {{doc}} with an {{id}} of {{38402455221829632}}. You can then use this information to build your web application.
As far as how to actually use these responses, you can either work with them directly, or use the Solr API as provided for your programming language. For example, a SolrJ request looks something like this:
{code:borderStyle=solid|borderColor=#666666}
SolrServer server = new CommonsHttpSolrServer("http://localhost:8888/solr/collection1");
SolrQuery query = new SolrQuery();
query.setQuery( "twitter" );
query.addSortField( "timestamp", SolrQuery.ORDER.desc );
QueryResponse rsp = server.query( query );
SolrDocumentList docs = rsp.getResults();
for (SolrDocument doc : docs){
System.out.println((String)doc.getFieldValue("id")+": ");
System.out.println((String)doc.getFieldValue("userScreenName")+" -- "+(String)doc.getFieldValue("text"));
}
{code}
Here you are creating a connection to the server, then creating and executing the request. From there, you can manipulate documents as you see fit.
APIs exist for most programming languages. You can find a list of bindings on the [Solr Wiki|http://wiki.apache.org/solr/IntegratingSolr].
{scrollbar}