org.ow2.weblab.services.solr
Class SolrComponent

java.lang.Object
  extended by org.ow2.weblab.services.solr.SolrComponent

public class SolrComponent
extends java.lang.Object

Component used to :

This class implements singleton pattern in order to share index connection and improve performance (Solr server is thread-safe).
The index buffer is managed by Solr so we just use a counter to commit documents when buffer configured size is achieved.


Field Summary
static java.lang.String DEFAULT_CORE_PREFIX
          Default SolR prefix
static java.lang.String IDREF
          Service ID reference
static java.lang.String IDRES_HIT_PREFIX
          Service ID-res prefix for Hit
static java.lang.String IDRES_QUERY_PREFIX
          Service ID-res prefix for Query
static java.lang.String IDRES_RESULT_PREFIX
          Service ID-res prefix for resultSet
protected static java.lang.String SOLR_CONFIG_FILE
           
protected static java.lang.String SOLR_DATA_HOME
           
protected static java.lang.String SOLR_HOME
          These are the parameters for the remote Solr server used.
protected static java.lang.String SOLR_SCHEMA_FILE
           
 
Method Summary
 void addDocument(org.apache.solr.common.SolrInputDocument doc)
           
 void commit()
          Commit method only flush and optimize index.
 org.apache.solr.client.solrj.response.UpdateResponse deleteDocbyQuery(java.lang.String query)
          Ask for document deletion based on a query: all documents matching the query will be deleted.
 org.apache.solr.client.solrj.response.UpdateResponse deleteDocbyURI(java.lang.String docURI)
          Ask for document deletion based on document URI
static void deleteInstance(java.lang.String context)
           
static java.lang.String extractTextFromResource(org.ow2.weblab.core.model.MediaUnit res)
          Util method to concatenate text content dispatched in multiple Text units in a document.
 org.apache.solr.client.solrj.response.QueryResponse facetSuggest(java.lang.String queryString, int offset, int limit, java.lang.String sortField, org.apache.solr.client.solrj.SolrQuery.ORDER order)
           
 SolrConfig getConf()
           
 java.lang.String getCoreDataHome()
           
 java.lang.String getCoreName()
           
static SolrComponent getInstance(SolrConfig conf, java.lang.String context)
          Retrieve SolrComponent instance depending on context
 org.apache.solr.client.solrj.response.QueryResponse getMetaData(java.lang.String... uri)
          Query the solr server to get the metadata associated to a list of document URIs
 java.lang.String getStatus()
          Status of SolR core linked to that instance
 org.apache.solr.client.solrj.response.QueryResponse highlight(java.lang.String queryString, int offset, int limit, java.lang.String sortField, org.apache.solr.client.solrj.SolrQuery.ORDER order)
          Highlight method that enrich search results with text content where the matching terms have been emphased.
 org.apache.solr.client.solrj.response.QueryResponse moreLikeThis(java.lang.String queryString, int offset, int limit)
          MoreLikeThis is a specific Solr query used to retrieve similar documents from a document id or text.
 org.apache.solr.client.solrj.response.QueryResponse search(java.lang.String queryString, int offset, int limit)
          Search method query solr server with string of the query offset limit
 org.apache.solr.client.solrj.response.QueryResponse search(java.lang.String queryString, int offset, int limit, java.lang.String sortField, org.apache.solr.client.solrj.SolrQuery.ORDER order)
          Search method query solr server with string of the query offset limit
 void setConf(SolrConfig conf)
           
 void setCoreDataHome(java.lang.String coreDataHome)
           
 org.apache.solr.client.solrj.response.QueryResponse spellSuggest(java.lang.String queryString)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IDREF

public static final java.lang.String IDREF
Service ID reference

See Also:
Constant Field Values

IDRES_RESULT_PREFIX

public static final java.lang.String IDRES_RESULT_PREFIX
Service ID-res prefix for resultSet

See Also:
Constant Field Values

IDRES_QUERY_PREFIX

public static final java.lang.String IDRES_QUERY_PREFIX
Service ID-res prefix for Query

See Also:
Constant Field Values

IDRES_HIT_PREFIX

public static final java.lang.String IDRES_HIT_PREFIX
Service ID-res prefix for Hit

See Also:
Constant Field Values

DEFAULT_CORE_PREFIX

public static final java.lang.String DEFAULT_CORE_PREFIX
Default SolR prefix

See Also:
Constant Field Values

SOLR_HOME

protected static java.lang.String SOLR_HOME
These are the parameters for the remote Solr server used. As they are protected, one could change them by overriding the values. However this is not recommended and the client should use default values.


SOLR_DATA_HOME

protected static java.lang.String SOLR_DATA_HOME

SOLR_CONFIG_FILE

protected static java.lang.String SOLR_CONFIG_FILE

SOLR_SCHEMA_FILE

protected static java.lang.String SOLR_SCHEMA_FILE
Method Detail

getInstance

public static SolrComponent getInstance(SolrConfig conf,
                                        java.lang.String context)
                                 throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Retrieve SolrComponent instance depending on context

Parameters:
context -
Returns:
the SolrComponent associated to the context
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

deleteInstance

public static void deleteInstance(java.lang.String context)

extractTextFromResource

public static java.lang.String extractTextFromResource(org.ow2.weblab.core.model.MediaUnit res)
Util method to concatenate text content dispatched in multiple Text units in a document.

Parameters:
res -
Returns:

getStatus

public java.lang.String getStatus()
Status of SolR core linked to that instance

Returns:
some information in JSON-like

addDocument

public void addDocument(org.apache.solr.common.SolrInputDocument doc)
                 throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

commit

public void commit()
Commit method only flush and optimize index.


search

public org.apache.solr.client.solrj.response.QueryResponse search(java.lang.String queryString,
                                                                  int offset,
                                                                  int limit)
                                                           throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Search method query solr server with
  • string of the query
  • offset
  • limit

Parameters:
queryString - is the full-text query in Lucene syntax
offset - is the rank of the first result to be returned
limit - is the size of the results list to be returned
Returns:
the Solr QueryResponse containing scored hits each one being linked to the Document uri
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

search

public org.apache.solr.client.solrj.response.QueryResponse search(java.lang.String queryString,
                                                                  int offset,
                                                                  int limit,
                                                                  java.lang.String sortField,
                                                                  org.apache.solr.client.solrj.SolrQuery.ORDER order)
                                                           throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Search method query solr server with
  • string of the query
  • offset
  • limit

Parameters:
queryString - is the full-text query in Lucene syntax
offset - is the rank of the first result to be returned
limit - is the size of the results list to be returned
sortField - is a specific field to use for sorting results
order - is the ordering model to use for sorting: either ORDER.desc or ORDER.asc
Returns:
the Solr QueryResponse containing scored hits each one being linked to the Document uri
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

getMetaData

public org.apache.solr.client.solrj.response.QueryResponse getMetaData(java.lang.String... uri)
                                                                throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Query the solr server to get the metadata associated to a list of document URIs

Parameters:
uri - : the list of URI
Returns:
a solr queryResponse that contain the relevant metadata associated to the documents
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException - is thrown if the query is not correctly handled

highlight

public org.apache.solr.client.solrj.response.QueryResponse highlight(java.lang.String queryString,
                                                                     int offset,
                                                                     int limit,
                                                                     java.lang.String sortField,
                                                                     org.apache.solr.client.solrj.SolrQuery.ORDER order)
                                                              throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Highlight method that enrich search results with text content where the matching terms have been emphased.

Parameters:
queryString - is the full-text query in Lucene syntax
offset - is the rank of the first result to be returned
limit - is the size of the results list to be returned
Returns:
the Solr QueryResponse containing hits with highligted content
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

spellSuggest

public org.apache.solr.client.solrj.response.QueryResponse spellSuggest(java.lang.String queryString)

facetSuggest

public org.apache.solr.client.solrj.response.QueryResponse facetSuggest(java.lang.String queryString,
                                                                        int offset,
                                                                        int limit,
                                                                        java.lang.String sortField,
                                                                        org.apache.solr.client.solrj.SolrQuery.ORDER order)

moreLikeThis

public org.apache.solr.client.solrj.response.QueryResponse moreLikeThis(java.lang.String queryString,
                                                                        int offset,
                                                                        int limit)
                                                                 throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
MoreLikeThis is a specific Solr query used to retrieve similar documents from a document id or text. Source, title and text fields are used to find similar documents.

Parameters:
queryString - the reference text or document to find similar docs (id:"doc1" for example)
Returns:
the Solr QueryResponse with document list
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException

deleteDocbyURI

public org.apache.solr.client.solrj.response.UpdateResponse deleteDocbyURI(java.lang.String docURI)
                                                                    throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Ask for document deletion based on document URI

Parameters:
docURI - the URI of the document to delete.
Returns:
UpdateResponse : empty object just to check the deletion was done.
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException - in case of any problem.

deleteDocbyQuery

public org.apache.solr.client.solrj.response.UpdateResponse deleteDocbyQuery(java.lang.String query)
                                                                      throws org.ow2.weblab.core.extended.exception.WebLabCheckedException
Ask for document deletion based on a query: all documents matching the query will be deleted.

Parameters:
query - a query to select documents
Returns:
UpdateResponse : empty object just to check the deletion was done.
Throws:
org.ow2.weblab.core.extended.exception.WebLabCheckedException - in case of any problem.

getCoreName

public java.lang.String getCoreName()

getConf

public SolrConfig getConf()

setConf

public void setConf(SolrConfig conf)

getCoreDataHome

public java.lang.String getCoreDataHome()

setCoreDataHome

public void setCoreDataHome(java.lang.String coreDataHome)


Copyright © 2004-2012. All Rights Reserved.