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 int BUFFER_DEFAULT_SIZE
           
static java.lang.String DEFAULT_HOME
           
static int MINI_TEXT_SIZE
           
static java.lang.String SPRING_INDEX_CONF
           
 
Method Summary
 void addDocument(org.weblab_project.core.model.Resource toBeIndexed)
          Add a Weblab Resource to Solr index
 void close()
          Close method only flush and optimize index.
static java.lang.String extractTextFromResource(org.weblab_project.core.model.Resource res)
           
 void flushIndexBuffer()
          Commit documents in Solr Index
 int getBufferSize()
          Return buffer size
static SolrComponent getInstance()
          Retrieve default singleton (using default bean configuration)
static SolrComponent getInstance(java.lang.String springConfFile, java.lang.String beanName)
          Retrive singleton depending on spring configuration file and bean name
 org.apache.solr.client.solrj.response.QueryResponse moreLikeThis(java.lang.String queryString)
          MoreLikeThis is a specific Solr query used to retrieve similar documents from a document id or text.
 void open(java.lang.String appPath)
           
 void open(java.lang.String appPath, java.lang.String core)
          Open method is synchronized in order to open only one embedded Solr server instance
 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 request handler 2 request handlers are used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPRING_INDEX_CONF

public static final java.lang.String SPRING_INDEX_CONF
See Also:
Constant Field Values

DEFAULT_HOME

public static final java.lang.String DEFAULT_HOME
See Also:
Constant Field Values

MINI_TEXT_SIZE

public static final int MINI_TEXT_SIZE
See Also:
Constant Field Values

BUFFER_DEFAULT_SIZE

public static final int BUFFER_DEFAULT_SIZE
See Also:
Constant Field Values
Method Detail

getInstance

public static SolrComponent getInstance(java.lang.String springConfFile,
                                        java.lang.String beanName)
Retrive singleton depending on spring configuration file and bean name

Parameters:
springConfFile -
beanName -
Returns:
the SolrComponent singleton

getInstance

public static SolrComponent getInstance()
Retrieve default singleton (using default bean configuration)

Returns:
the SolrComponent singleton

open

public void open(java.lang.String appPath)

open

public void open(java.lang.String appPath,
                 java.lang.String core)
Open method is synchronized in order to open only one embedded Solr server instance


addDocument

public void addDocument(org.weblab_project.core.model.Resource toBeIndexed)
                 throws org.weblab_project.core.exception.WebLabCheckedException
Add a Weblab Resource to Solr index

Parameters:
toBeIndexed -
Throws:
org.weblab_project.core.exception.WebLabCheckedException

extractTextFromResource

public static java.lang.String extractTextFromResource(org.weblab_project.core.model.Resource res)

close

public void close()
Close method only flush and optimize index.


flushIndexBuffer

public void flushIndexBuffer()
                      throws org.weblab_project.core.exception.WebLabCheckedException
Commit documents in Solr Index

Throws:
org.weblab_project.core.exception.WebLabCheckedException

getBufferSize

public int getBufferSize()
Return buffer size

Returns:
the buffer size

search

public org.apache.solr.client.solrj.response.QueryResponse search(java.lang.String queryString,
                                                                  int offset,
                                                                  int limit)
                                                           throws org.weblab_project.core.exception.WebLabCheckedException
Search method query solr server with
  • string of the query
  • offset
  • limit
  • request handler
2 request handlers are used. The first ("weblab_with_meta") retrieve all fields indexed and the second ("weblab") retrieve only doc id and score.

Parameters:
queryString -
offset -
limit -
Returns:
the Solr QueryResponse
Throws:
org.weblab_project.core.exception.WebLabCheckedException

moreLikeThis

public org.apache.solr.client.solrj.response.QueryResponse moreLikeThis(java.lang.String queryString)
                                                                 throws org.weblab_project.core.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.weblab_project.core.exception.WebLabCheckedException


Copyright © 2004-2010. All Rights Reserved.