public final class SolrMethods extends Object
This class provides one-liner methods for getting a configured SolrServer for a specific core.
Connects to the SolrServer to retrieve Search results based on the users query.
Modifier and Type | Method and Description |
---|---|
static io.toro.gloop.object.property.GloopModel |
deleteById(String coreName,
String packageName,
List<String> ids)
Delete a solr document by ID
|
static io.toro.gloop.object.property.GloopModel |
deleteByQuery(String coreName,
String packageName,
String query) |
static UpdateResponse |
deleteByQueryString(String coreName,
String packageName,
String query)
Delete a solr document by query
|
static void |
gloopModelToSolrSchema(String destination,
String packageName,
String modelNamespace)
Create a Solr schema in a specified directory based from a GloopModel
|
static io.toro.gloop.object.cursor.GloopCursor |
insertMany(String coreName,
String packageName,
String commitMode,
boolean closeClient,
io.toro.gloop.engine.GloopExecutionContext context)
Open a GloopCursor which accepts a GloopModel that is converted to a SolrInputDocument, allowing Gloop to write
records.
|
static io.toro.gloop.object.cursor.GloopCursor |
insertMany(String coreName,
String packageName,
String commitMode,
boolean closeClient,
int batchSize,
io.toro.gloop.engine.GloopExecutionContext context)
Open a GloopCursor which accepts a GloopModel that is converted to a SolrInputDocument, allowing Gloop to write
records.
|
static io.toro.gloop.object.property.GloopModel |
query(String coreName,
String packageName,
List<io.toro.gloop.object.property.GloopModel> solrParams)
Query a Martini Package Solr Core using solr query parameters.
|
static QueryResponse |
query(String coreName,
String packageName,
Map<String,String> solrParams)
Query a Martini Package Solr Core using solr query parameters.
|
static io.toro.martini.solr.MartiniSolrClient |
solr(String coreName)
Get configured SolrServer for specific core
|
static void |
solrSchemaToGloopModel(String name,
String schema,
String packageName,
String namespace,
List<io.toro.gloop.object.property.GloopModel> resources)
Create a GloopModel file in the selected Martini Package's model
folder based from a Solr schema.xml input string
and the provided resources
|
static void |
solrSchemaToGloopModel(String name,
String schema,
String packageName,
String namespace,
Map<String,String> resources)
Create a GloopModel file in the selected Martini Package's model
folder based from a Solr schema.xml input string
and the provided resources
|
static io.toro.gloop.object.property.GloopModel |
writeToIndex(String coreName,
String packageName,
io.toro.gloop.object.property.GloopModel gloopModel)
Index a bean object and store it to the selected Martini Package's Solr Core.
|
static UpdateResponse |
writeToIndex(String coreName,
String packageName,
Object bean)
Index or update a bean object and store it to the selected Martini Package's Solr Core.
|
@GloopObjectParameter(value="output{\nupdateResponse#io.toro.martini.solr.UpdateResponse{\n }\n}") @GloopComment(value="Delete a document by id") public static io.toro.gloop.object.property.GloopModel deleteById(@GloopParameter(value="Solr core name",allowNull=false) String coreName, @GloopParameter(value="Martini Package of the solr core. If empty the default package will be the current package where the service is invoked") String packageName, @GloopParameter(value="List of document id to delete") List<String> ids) throws SolrServerException, IOException
coreName
- The SolrServer namepackageName
- Martini Package where solr core resides If empty the default package will be the current
package where the service is invokedids
- List of ids to delete {@link
- SolrServerException}{@link
- IOException}SolrServerException
IOException
public static UpdateResponse deleteByQueryString(String coreName, String packageName, String query) throws SolrServerException, IOException
coreName
- The SolrServer namepackageName
- Martini Package where solr core resides If empty the default package will be the current
package where the service is invokedquery
- solr query parameters {@link
- SolrServerException}{@link
- IOException}SolrServerException
IOException
@GloopObjectParameter(value="output{\nupdateResponse#io.toro.martini.solr.UpdateResponse{\n }\n}") public static io.toro.gloop.object.property.GloopModel deleteByQuery(@GloopParameter(value="Solr core name",allowNull=false) String coreName, @GloopParameter(value="Martini Package of the solr core. If empty the default package will be the current package where the service is invoked") String packageName, @GloopParameter(value="Solr delete query parameter",allowExtraProperties=false,allowNull=false) String query) throws SolrServerException, IOException
SolrServerException
IOException
@GloopComment(value="Creates a solr schema in the provided destination directory from the supplied gloop model") public static void gloopModelToSolrSchema(@GloopParameter(value="The output directory of the generated schema",allowNull=false) String destination, @GloopParameter(value="The martini package name where the gloop model resides") String packageName, @GloopParameter(value="The gloop model to be converted to a solr schema") String modelNamespace) throws IOException
destination
- The destination directorypackageName
- he Martini Package name where the gloop model residesmodelNamespace
- The namespace of the GloopModelIOException
public static void solrSchemaToGloopModel(String name, String schema, String packageName, String namespace, Map<String,String> resources)
schema
- solr schema xmlpackageName
- Martini Package of where the generated GloopModel will reside.
If empty the default package will be the current package where the service is invokednamespace
- Package namespace of the GloopModelresources
- the required resources needed to properly parse the solr schema
such as specifying the enumConfig.xml.
For example:
if your schema xml looks like this
...
...
The fieldType enum requires external xml config resource enumConfig.xml to
know what are the choices for the priorityLevel field. To satisfy the requirement,
simply populate the resources map with key value of 'enumsConfig.xml' and its xml string@GloopComment(value="Create a GloopModel file in the selected Martini Package\'s model folder based from a Solr schema.xml string and the provided resources") public static void solrSchemaToGloopModel(@GloopParameter(value="Output model file name") String name, @GloopParameter(value="schema xml in string") String schema, @GloopParameter(value="Martini Package of where the generated GloopModel will reside. If empty the default package will be the current package where the service is invoked") String packageName, @GloopParameter(value="Package namespace of the GloopModel",allowNull=false,defaultValue="model") String namespace, @GloopParameter(value="Additional resources needed to properly parse the schema string",allowExtraProperties=false,allowNull=true) @GloopObjectParameter(value="resources[]{\n resourceName\n resourceContent\n}") List<io.toro.gloop.object.property.GloopModel> resources)
schema
- solr schema xmlpackageName
- Martini Package of where the generated GloopModel will reside.
If empty the default package will be the current package where the service is invokednamespace
- Package namespace of the GloopModelresources
- the required resources needed to properly parse the solr schema
such as specifying the enumConfig.xml.
For example:
if your schema xml looks like this
...
...
The fieldType enum requires external xml config resource enumConfig.xml to
know what are the choices for the priorityLevel field. To satisfy the requirement,
simply populate the resources map with key value of 'enumsConfig.xml' and its xml stringpublic static UpdateResponse writeToIndex(String coreName, String packageName, Object bean) throws IOException, SolrServerException
Field
for solr to know what field to index
If user wants to replace an entire document in solr, all you need is to create your
bean object with the id of the existing document in the bean object field. Calling this
method will replace the existing document with your new bean object document.
If however user wants to partially update a solr document, one must create a
SolrInputDocument
and populate the field with solr syntax for updating
a solr document.
For example if the following document exist in the index:
{"id":"mydoc",
"price":10,
"popularity":42,
"categories":["kids"],
"promo_ids":["a123x"],
"tags":["free_to_try","buy_now","clearance","on_sale"]
}
In order to update the price. User will need to create a solr document and use the
existing id field
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "mydoc") //the ID of the existing docs
Map modifier = new HashMap<>();
modifier.put( "set", 500 ); //set is one of solr's modifier.
doc.setField( "price", modifier );
SolrMethods.writeToIndex( "coreName", "packageName", doc )
packageName
- Martini Package where solr core resides If empty the default
package will be the current package where the service is invokedcoreName
- Solr core namebean
- bean object to indexIOException
SolrServerException
@GloopComment(value="Index or update a bean object and store it to selected Martini Package\'s Solr Core. The bean object fields must be annotated with @org.apache.solr.client.solrj.beans.Field for solr to know what field to indexbased from a Solr schema.xml string and the provided resources") @GloopObjectParameter(value="output{\nupdateResponse#io.toro.martini.solr.UpdateResponse{\n }\n}") public static io.toro.gloop.object.property.GloopModel writeToIndex(@GloopParameter(value="Solr core name",allowNull=false) String coreName, @GloopParameter(value="Martini Package of the solr core. If empty the default package will be the current package where the service is invoked") String packageName, @GloopParameter(value="the gloop model to index",allowNull=false,allowExtraProperties=true) io.toro.gloop.object.property.GloopModel gloopModel) throws IOException, SolrServerException
Field
for solr to know what field to index
packageName
- Martini Package of the solr core. If empty the default
package will be the current package where the service is invokedcoreName
- Solr core namegloopModel
- bean object to indexIOException
SolrServerException
public static QueryResponse query(String coreName, String packageName, Map<String,String> solrParams)
packageName
- Martini Package where solr core resides If
empty the default package will be the current
package where the service is invokedcoreName
- Solr core namesolrParams
- Solr query parameters@GloopComment(value="Query a Martini Package Solr Core using solr query parameters.") @GloopObjectParameter(value="output{\nqueryResponse#io.toro.martini.solr.QueryResponse{\n }\n}") public static io.toro.gloop.object.property.GloopModel query(@GloopParameter(value="Solr core name",allowNull=false) String coreName, @GloopParameter(value="Martini Package of the solr core. If empty the default package will be the current package where the service is invoked") String packageName, @GloopParameter(value="Solr query parameter",allowExtraProperties=false,allowNull=true) @GloopObjectParameter(value="solrParams[]{\n paramKey\n paramValue\n}") List<io.toro.gloop.object.property.GloopModel> solrParams)
packageName
- Martini Package where solr core resides If empty the
default package will be the current package where the service is invokedcoreName
- Solr core namesolrParams
- Solr query parameterspublic static io.toro.martini.solr.MartiniSolrClient solr(String coreName) throws ToroException
Get configured SolrServer for specific core
Example usage:
def solr = 'solrName'.solr() def query = new SolrQuery( 'q=video&sort=price desc' ) def queryResult = solr.query( query )
coreName
- The SolrServer nameToroException
public static io.toro.gloop.object.cursor.GloopCursor insertMany(@GloopParameter(allowNull=false) String coreName, String packageName, @GloopParameter(allowNull=false,defaultValue="On Close",choices={"Never","Batch","On Close"}) String commitMode, @GloopParameter(allowNull=false,defaultValue="false") boolean closeClient, io.toro.gloop.engine.GloopExecutionContext context)
coreName
- the SolrCore namepackageName
- Martini Package of where the SolrCore is located.
If empty the default package will be the current package where the service is invokedcommitMode
- tells the cursor when to commit the cached documents closeClient
- boolean stating whether the cursor will close the client after it has been exhaustedcontext
- the Gloop Execution Contextpublic static io.toro.gloop.object.cursor.GloopCursor insertMany(@GloopParameter(allowNull=false) String coreName, String packageName, @GloopParameter(allowNull=false,defaultValue="On Close",choices={"Never","Batch","On Close"}) String commitMode, @GloopParameter(allowNull=false,defaultValue="false") boolean closeClient, @GloopParameter(allowNull=false,defaultValue="1000") int batchSize, io.toro.gloop.engine.GloopExecutionContext context)
coreName
- the SolrCore namepackageName
- Martini Package of where the SolrCore is located.
If empty the default package will be the current package where the service is invokedcommitMode
- tells the cursor when to commit the cached documents closeClient
- boolean stating whether the cursor will close the client after it has been exhaustedbatchSize
- how many write models to cache before sending them to solrcontext
- the Gloop Execution ContextCopyright © 2019. All rights reserved.