Search in sources :

Example 1 with TextIndexConfig

use of org.apache.jena.query.text.TextIndexConfig in project jena by apache.

the class JenaTextExample1 method createCode.

public static Dataset createCode() {
    log.info("Construct an in-memory dataset with in-memory lucene index using code");
    // Build a text dataset by code.
    // Here , in-memory base data and in-memeory Lucene index
    // Base data
    Dataset ds1 = DatasetFactory.create();
    // Define the index mapping 
    EntityDefinition entDef = new EntityDefinition("uri", "text");
    entDef.setPrimaryPredicate(RDFS.label.asNode());
    // Lucene, in memory.
    Directory dir = new RAMDirectory();
    // Join together into a dataset
    Dataset ds = TextDatasetFactory.createLucene(ds1, dir, new TextIndexConfig(entDef));
    return ds;
}
Also used : EntityDefinition(org.apache.jena.query.text.EntityDefinition) TextIndexConfig(org.apache.jena.query.text.TextIndexConfig) RAMDirectory(org.apache.lucene.store.RAMDirectory) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory)

Example 2 with TextIndexConfig

use of org.apache.jena.query.text.TextIndexConfig in project jena by apache.

the class JenaTextExample1 method createCode.

public static Dataset createCode() {
    log.info("Construct an in-memory dataset with in-memory lucene index using code");
    // Build a text dataset by code.
    // Here , in-memory base data and in-memeory Lucene index
    // Base data
    Dataset ds1 = DatasetFactory.create();
    // Define the index mapping
    EntityDefinition entDef = new EntityDefinition("uri", "text");
    entDef.setPrimaryPredicate(RDFS.label.asNode());
    // Lucene, in memory.
    Directory dir = new ByteBuffersDirectory();
    // Join together into a dataset
    Dataset ds = TextDatasetFactory.createLucene(ds1, dir, new TextIndexConfig(entDef));
    return ds;
}
Also used : EntityDefinition(org.apache.jena.query.text.EntityDefinition) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) TextIndexConfig(org.apache.jena.query.text.TextIndexConfig) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) Directory(org.apache.lucene.store.Directory)

Example 3 with TextIndexConfig

use of org.apache.jena.query.text.TextIndexConfig in project jena by apache.

the class TextIndexESAssembler method open.

/*
    <#index> a :TextIndexES ;
        text:serverList "127.0.0.1:9300,127.0.0.2:9400,127.0.0.3:9500" ; #Comma separated list of hosts:ports
        text:clusterName "elasticsearch"
        text:shards "1"
        text:replicas "1"
        text:entityMap <#endMap> ;
        .
    */
@Override
public TextIndex open(Assembler a, Resource root, Mode mode) {
    try {
        String listOfHostsAndPorts = GraphUtils.getAsStringValue(root, pServerList);
        if (listOfHostsAndPorts == null || listOfHostsAndPorts.isEmpty()) {
            throw new TextIndexException("Mandatory property text:serverList (containing the comma-separated list of host:port) property is not specified. " + "An example value for the property: 127.0.0.1:9300");
        }
        String[] hosts = listOfHostsAndPorts.split(COMMA);
        Map<String, Integer> hostAndPortMapping = new HashMap<>();
        for (String host : hosts) {
            String[] hostAndPort = host.split(COLON);
            if (hostAndPort.length < 2) {
                LOGGER.error("Either the host or the port value is missing.Please specify the property in host:port format. " + "Both parts are mandatory. Ignoring this value. Moving to the next one.");
                continue;
            }
            hostAndPortMapping.put(hostAndPort[0], Integer.valueOf(hostAndPort[1]));
        }
        String clusterName = GraphUtils.getAsStringValue(root, pClusterName);
        if (clusterName == null || clusterName.isEmpty()) {
            LOGGER.warn("ClusterName property is not specified. Defaulting to 'elasticsearch'");
            clusterName = "elasticsearch";
        }
        String numberOfShards = GraphUtils.getAsStringValue(root, pShards);
        if (numberOfShards == null || numberOfShards.isEmpty()) {
            LOGGER.warn("shards property is not specified. Defaulting to '1'");
            numberOfShards = "1";
        }
        String replicationFactor = GraphUtils.getAsStringValue(root, pReplicas);
        if (replicationFactor == null || replicationFactor.isEmpty()) {
            LOGGER.warn("replicas property is not specified. Defaulting to '1'");
            replicationFactor = "1";
        }
        String indexName = GraphUtils.getAsStringValue(root, pIndexName);
        if (indexName == null || indexName.isEmpty()) {
            LOGGER.warn("index Name property is not specified. Defaulting to 'jena-text'");
            indexName = "jena-text";
        }
        Resource r = GraphUtils.getResourceValue(root, pEntityMap);
        EntityDefinition docDef = (EntityDefinition) a.open(r);
        TextIndexConfig config = new TextIndexConfig(docDef);
        //We have to create an ES specific settings class in order to pass the Index Initialization specific properties.
        ESSettings settings = new ESSettings().builder().clusterName(clusterName).hostAndPortMap(hostAndPortMapping).shards(Integer.valueOf(numberOfShards)).replicas(Integer.valueOf(replicationFactor)).indexName(indexName).build();
        return TextESDatasetFactory.createESIndex(config, settings);
    } catch (Exception e) {
        throw new TextIndexException("An exception occurred while trying to open/load the Assembler configuration. ", e);
    }
}
Also used : EntityDefinition(org.apache.jena.query.text.EntityDefinition) TextIndexException(org.apache.jena.query.text.TextIndexException) HashMap(java.util.HashMap) TextIndexConfig(org.apache.jena.query.text.TextIndexConfig) Resource(org.apache.jena.rdf.model.Resource) TextIndexException(org.apache.jena.query.text.TextIndexException)

Example 4 with TextIndexConfig

use of org.apache.jena.query.text.TextIndexConfig in project jena by apache.

the class BaseESTest method config.

/**
     * Simple Config for text index
     * @return
     */
private static TextIndexConfig config() {
    EntityDefinition ed = new EntityDefinition(DOC_TYPE, "label", RDFS.label);
    ed.set("comment", RDFS.comment.asNode());
    ed.setLangField("lang");
    TextIndexConfig config = new TextIndexConfig(ed);
    return config;
}
Also used : EntityDefinition(org.apache.jena.query.text.EntityDefinition) TextIndexConfig(org.apache.jena.query.text.TextIndexConfig)

Aggregations

EntityDefinition (org.apache.jena.query.text.EntityDefinition)4 TextIndexConfig (org.apache.jena.query.text.TextIndexConfig)4 Directory (org.apache.lucene.store.Directory)2 HashMap (java.util.HashMap)1 TextIndexException (org.apache.jena.query.text.TextIndexException)1 Resource (org.apache.jena.rdf.model.Resource)1 ByteBuffersDirectory (org.apache.lucene.store.ByteBuffersDirectory)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1