39. Document
field value
ID 2
name “Mike Hugo”
company “Entagen”
“lorem ipsum
bio
dolor sum etc...”
40. Index
field
field value
value
field
field value
value
field
field value
name
name field “mike value
value
hugo”
“mike hugo”
name
name “mike hugo”
“mike hugo”
name
nameid “mike hugo”
“mike 2hugo”
company
company “Entagen”
“Entagen”
company
company
name “Entagen”
“Entagen”
“Mike Hugo”
company
company “Entagen”
“Entagen”
“Entagen” Indexed
company “lorem ipsum
“lorem ipsum
bio
bio “lorem ipsum
“lorem etc...”
bio
bio “loremipsum
dolorsum ipsum
dolor“loremetc...” not
bio
bio sum ipsum
dolorsum etc...””
dolor sum etc... ”
bio dolor sum ipsum”
“lorem etc...
dolor sum etc... Stored
dolor sum etc...”
51. arqlQueryService.executeForEach(reposito
String uri = it.uri.stringValue()
String label = it.label.stringValue()
Document doc = new Document()
doc.add(new Field(SUBJECT_URI_FIELD,
uri, Instantiate a
new Lucene
Field.Store.YES,
Document
Field.Index.ANALYZED))
doc.add(new Field(LABEL_FIELD,
label,
Field.Store.NO,
Field.Index.ANALYZED))
writer.addDocument(doc)
52. key
Document doc = new Document()
doc.add(new Field(SUBJECT_URI_FIELD,
value uri,
Field.Store.YES,
Field.Index.ANALYZED))
doc.add(new Field(LABEL_FIELD,
label, Add the Subject
Field.Store.NO, URI to the
Document
Field.Index.ANALYZED))
writer.addDocument(doc)
lly {
53. Field.Store.YES,
Field.Index.ANALYZED))
doc.add(new Field(LABEL_FIELD, key
value label,
Field.Store.NO,
Field.Index.ANALYZED))
Add the Label field
writer.addDocument(doc) document
to the
(but don’t store it)
lly {
iter.close() // Close index
54. doc.add(new Field(LABEL_FIELD, labe
Field.Store.NO,
Field.Index.ANALYZED))
writer.addDocument(doc)
}
inally {
writer.close() // Closethe document
Add index
to the Index
56. f query = {
Query query = new QueryParser(
Version.LUCENE_CURRENT,
LABEL_FIELD, query this field
new StandardAnalyzer())
.parse(params.query);
for this value
def s Create a Lucene
= new Date().time
Query from user
List results = executeQuery(query)
input
def e = new Date().time
render(view: 'index', model: [results:
57. IndexSearcher searcher = luceneSearche
ScoreDoc[] scoreDocs =
searcher.search(query, 10).scoreDo
List results = [] Search the index
(limit 10) for
def connection = repository.connection
scoreDocs.each { matching
documents
Document doc = searcher.doc(it.doc
String uri = doc[SUBJECT_URI_FIELD
Map labelAndType = sparqlQueryServ
results << [uri: uri, type: labelA
}
connection.close()
return results
58. List results = []
def connection = repository.connection
scoreDocs.each {
Document doc = searcher.doc(it.doc)
String uri = doc[SUBJECT_URI_FIELD]
Map labelAndType =
For each matching
sparqlQueryService.
document, get the
getLabelAndType(uri, connection)
doc and extract the
results.add([
Subject URI
uri: uri,
type: labelAndType.type,
label: labelAndType.label])
}
connection.close()
return results
59. List results = []
def connection = repository.connection
scoreDocs.each {
Document doc = searcher.doc(it.doc)
String uri = doc[SUBJECT_URI_FIELD]
Map labelAndType =
sparqlQueryService.
getLabelAndType(uri, connection)
results.add([
uri: uri, Using the Subject
URI, load properties
type: labelAndType.type,
from the triplestore
label: labelAndType.label])
}
connection.close()
return results
68. Connection connection = repository.conn
y {
String subjectUris = """
SELECT distinct ?uri
WHERE {
?uri ?p ?o .
}
"""
sparqlQueryService.executeForEach(rep
def doc = new Select all Subject
Document()
URIs from the
triplestore
String subjectUri = it.uri.string
doc.add(new Field(SUBJECT_URI_FIE
subjectUri,
69. """
sparqlQueryService.executeForEach(
repository, subjectUris) {
def doc = new Document()
String subjectUri = it.uri.stringV
doc.add(new Field(SUBJECT_URI_FIEL
subjectUri,
Field.Store.YES,
Execute the Sparql Query
Field.Index.ANALYZED))
For each URI, create a
new Document
StringWriter triplesStringWriter =
NTriplesWriter nTriplesWriter =
new NTriplesWriter(triplesStri
70. epository, subjectUris) {
def doc = new Document()
String subjectUri = it.uri.stringValue
doc.add(new Field(SUBJECT_URI_FIELD,
subjectUri,
Field.Store.YES,
Field.Index.ANALYZED))
StringWriter triplesStringWriter = new
NTriplesWriter nTriplesWriter =URI
Add the Subject
to the Document
new NTriplesWriter(triplesStringWr
connection.exportStatements(
new URIImpl(subjectUri),
null, null, false,
71. Field.Index.ANALYZED))
StringWriter triplesStringWriter = new
NTriplesWriter nTriplesWriter =
new NTriplesWriter(triplesStringWr
connection.exportStatements(
new URIImpl(subjectUri),
null, null, false,
nTriplesWriter)
Get an NTriples
doc.add(new Field(TRIPLES_FIELD,
string from the
triplesStringWriter.toString()
Field.Store.NO, triplestore
Field.Index.ANALYZED))
72. new URIImpl(subjectUri),
null, null, false,
nTriplesWriter)
doc.add(new Field(TRIPLES_FIELD,
triplesStringWriter.toString()
Field.Store.NO,
Field.Index.ANALYZED))
Add the NTriples
writer.addDocument(doc)
string to the
document
73. doc.add(new Field(TRIPLES_FIELD,
triplesStringWriter.toString()
Field.Store.NO,
Field.Index.ANALYZED))
writer.addDocument(doc)
Add the document
to the index
75. SirenCellQuery predicate =
new SirenCellQuery(
new SirenTermQuery(
new Term(TRIPLES_FIELD,
RDFS.LABEL.stringValue())));
predicate.constraint = PREDICATE_CELL
SirenCellQuery object =
query the Triples
new SirenCellQuery(
new SirenTermQuery( field
new Term(TRIPLES_FIELD,
params.query.toLowerCase()))
object.constraint = OBJECT_CELL
76. SirenCellQuery predicate =
new SirenCellQuery(
new SirenTermQuery(
new Term(TRIPLES_FIELD,
RDFS.LABEL.stringValue())));
predicate.constraint = PREDICATE_CELL
SirenCellQuery object =
new SirenCellQuery( a predicate
for
new SirenTermQuery(
new Term(TRIPLES_FIELD,
params.query.toLowerCase()))
object.constraint = OBJECT_CELL
77. SirenCellQuery predicate =
new SirenCellQuery(
new SirenTermQuery(
new Term(TRIPLES_FIELD,
RDFS.LABEL.stringValue())));
predicate.constraint = PREDICATE_CELL
of rdfs:label *
SirenCellQuery object =
new SirenCellQuery(
new SirenTermQuery(
new Term(TRIPLES_FIELD,
params.query.toLowerCase()))
* note: could be any predicate!
object.constraint = OBJECT_CELL
78. SirenCellQuery object =
new SirenCellQuery(
new SirenTermQuery(
new Term(TRIPLES_FIELD,
params.query.toLowerCase())
object.constraint = OBJECT_CELL
Query query = new SirenTupleQuery()
query the Triples
query.add(predicate,
field
SirenTupleClause.Occur.MUST)
query.add(object,
SirenTupleClause.Occur.MUST)
79. SirenCellQuery object =
new SirenCellQuery(
new SirenTermQuery(
new Term(TRIPLES_FIELD,
params.query.toLowerCase())
object.constraint = OBJECT_CELL
Query query = new SirenTupleQuery()
query.add(predicate,
for an object
SirenTupleClause.Occur.MUST)
query.add(object,
SirenTupleClause.Occur.MUST)
80. SirenCellQuery object =
new SirenCellQuery(
new SirenTermQuery(
new Term(TRIPLES_FIELD,
params.query.toLowerCase())
object.constraint = OBJECT_CELL
Query query = new SirenTupleQuery()
query.add(predicate, matching the
user input
SirenTupleClause.Occur.MUST)
query.add(object,
SirenTupleClause.Occur.MUST)