HitImpl.java
3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Item
* javax.jcr.Node
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Value
* javax.jcr.query.Row
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
*/
package com.day.cq.search.impl.result;
import com.day.cq.search.impl.builder.QueryImpl;
import com.day.cq.search.impl.misc.Excerpt;
import com.day.cq.search.impl.misc.ExcerptsMap;
import com.day.cq.search.result.Hit;
import java.util.Map;
import java.util.Set;
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.query.Row;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
public class HitImpl
implements Hit {
public static final String JCR_TITLE = "jcr:title";
private final QueryImpl query;
private final Row row;
private final long index;
private Map<String, String> excerpts;
public HitImpl(QueryImpl query, Row row, long index) {
this.query = query;
this.row = row;
this.index = index;
}
@Override
public long getIndex() {
return this.index;
}
@Override
public Map<String, String> getExcerpts() throws RepositoryException {
if (this.excerpts == null) {
this.excerpts = new ExcerptsMap(this.row, this.query.getSession());
}
return this.excerpts;
}
@Override
public String getExcerpt() throws RepositoryException {
return Excerpt.create(this, this.query.getExcerptPropertyNames(), 150).getText();
}
@Override
public Resource getResource() throws RepositoryException {
ResourceResolver resolver = this.query.getResourceResolver();
return resolver.getResource(this.getPath());
}
@Override
public Node getNode() throws RepositoryException {
return (Node)this.query.getSession().getItem(this.getPath());
}
@Override
public String getPath() throws RepositoryException {
return this.row.getValue("jcr:path").getString();
}
@Override
public ValueMap getProperties() throws RepositoryException {
Resource resource = this.getResource();
if (resource != null) {
Resource contentResource = resource.getResourceResolver().getResource(resource, "jcr:content");
if (contentResource == null) {
contentResource = resource;
}
return (ValueMap)contentResource.adaptTo(ValueMap.class);
}
return ValueMap.EMPTY;
}
@Override
public String getTitle() throws RepositoryException {
String excerpt = this.getExcerpts().get("jcr:title");
if (excerpt != null) {
return excerpt;
}
return ((Node)this.getResource().adaptTo(Node.class)).getName();
}
public Row getRow() {
return this.row;
}
@Override
public double getScore() throws RepositoryException {
return this.row.getScore();
}
}