org.elasticsearch.search.lookup.SourceLookup Java Examples
The following examples show how to use
org.elasticsearch.search.lookup.SourceLookup.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SourceSimpleFragmentsBuilder.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected Field[] getFields(IndexReader reader, int docId, String fieldName) throws IOException { // we know its low level reader, and matching docId, since that's how we call the highlighter with SourceLookup sourceLookup = searchContext.lookup().source(); sourceLookup.setSegmentAndDocument((LeafReaderContext) reader.getContext(), docId); List<Object> values = sourceLookup.extractRawValues(hitContext.getSourcePath(mapper.fieldType().names().fullName())); if (values.isEmpty()) { return EMPTY_FIELDS; } Field[] fields = new Field[values.size()]; for (int i = 0; i < values.size(); i++) { fields[i] = new Field(mapper.fieldType().names().indexName(), values.get(i).toString(), TextField.TYPE_NOT_STORED); } return fields; }
Example #2
Source File: SearchResultComponentGeneratorSupport.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
protected String getPrivilegedRepositoryName(Map<String,Object> source) { String repositoryName = (String) source.get(REPOSITORY_NAME); String repositoryFormat = (String) source.get(FORMAT); List<Map<String, Object>> assets = (List<Map<String, Object>>) source.getOrDefault("assets", Collections.emptyList()); SourceLookup lookup = new SourceLookup(); lookup.setSource(source); if (assets != null && !assets.isEmpty()) { VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(repositoryFormat); VariableSource variableSource = variableResolverAdapter.fromSourceLookup(lookup, assets.get(0)); List<String> repositoryNames = repositoryManager.findContainingGroups(repositoryName); repositoryNames.add(0, repositoryName); for (String name : repositoryNames) { if (contentPermissionChecker.isPermitted(name, repositoryFormat, BreadActions.BROWSE, variableSource)) { return name; } } } return null; }
Example #3
Source File: InternalSearchHit.java From Elasticsearch with Apache License 2.0 | 5 votes |
@SuppressWarnings({"unchecked"}) @Override public Map<String, Object> sourceAsMap() throws ElasticsearchParseException { if (source == null) { return null; } if (sourceAsMap != null) { return sourceAsMap; } sourceAsMap = SourceLookup.sourceAsMap(source); return sourceAsMap; }
Example #4
Source File: SourceScoreOrderFragmentsBuilder.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected Field[] getFields(IndexReader reader, int docId, String fieldName) throws IOException { // we know its low level reader, and matching docId, since that's how we call the highlighter with SourceLookup sourceLookup = searchContext.lookup().source(); sourceLookup.setSegmentAndDocument((LeafReaderContext) reader.getContext(), docId); List<Object> values = sourceLookup.extractRawValues(hitContext.getSourcePath(mapper.fieldType().names().fullName())); Field[] fields = new Field[values.size()]; for (int i = 0; i < values.size(); i++) { fields[i] = new Field(mapper.fieldType().names().indexName(), values.get(i).toString(), TextField.TYPE_NOT_STORED); } return fields; }
Example #5
Source File: GetResult.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * The source of the document (As a map). */ @SuppressWarnings({"unchecked"}) public Map<String, Object> sourceAsMap() throws ElasticsearchParseException { if (source == null) { return null; } if (sourceAsMap != null) { return sourceAsMap; } sourceAsMap = SourceLookup.sourceAsMap(source); return sourceAsMap; }
Example #6
Source File: OrientMavenVariableResolverAdapter.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected void addFromSourceLookup(final VariableSourceBuilder builder, final SourceLookup sourceLookup, final Map<String, Object> asset) { addMavenCoordinates(builder, (String) asset.get(MetadataNodeEntityAdapter.P_NAME)); }
Example #7
Source File: MavenVariableResolverAdapter.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected void addFromSourceLookup( final VariableSourceBuilder builder, final SourceLookup sourceLookup, final Map<String, Object> asset) { addMavenCoordinates(builder, (String) asset.get(NAME)); }
Example #8
Source File: SimpleVariableResolverAdapter.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected void addFromSourceLookup(final VariableSourceBuilder builder, final SourceLookup sourceLookup, final Map<String, Object> asset) { //no-op the simple impl just allows for the path/format variable resolvers in the support class }
Example #9
Source File: SimpleVariableResolverAdapter.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected void addFromSourceLookup(final VariableSourceBuilder builder, final SourceLookup sourceLookup, final Map<String, Object> asset) { // no-op the simple impl just allows for the path/format variable resolvers in the support class }
Example #10
Source File: VariableResolverAdapterSupport.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public VariableSource fromSourceLookup(final SourceLookup sourceLookup, final Map<String, Object> asset) { VariableSourceBuilder builder = new VariableSourceBuilder(); builder.addResolver( new ConstantVariableResolver(checkNotNull((String) asset.get(NAME)), PATH)); builder.addResolver( new ConstantVariableResolver(checkNotNull(sourceLookup.get(FORMAT)), FORMAT)); addFromSourceLookup(builder, sourceLookup, asset); return builder.build(); }
Example #11
Source File: ContentAuthPluginScript.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public Object run() { ThreadState threadState = new SubjectThreadState(subject); threadState.bind(); try { SourceLookup sourceLookup = getSourceLookup(); String format = (String) checkNotNull(sourceLookup.get(FORMAT)); String repositoryName = (String) checkNotNull(sourceLookup.get(REPOSITORY_NAME)); VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(format); @SuppressWarnings("unchecked") List<Map<String, Object>> assets = (List<Map<String, Object>>) sourceLookup.getOrDefault("assets", Collections.emptyList()); if (assets != null && !assets.isEmpty()) { Map<String, Object> asset = assets.get(0); VariableSource variableSource = variableResolverAdapter.fromSourceLookup(sourceLookup, asset); Set<String> repoNames = new HashSet<>(); repoNames.add(repositoryName); repoNames.addAll(repositoryManager.findContainingGroups(repositoryName)); return contentPermissionChecker.isPermitted(repoNames, format, BROWSE, variableSource); } return false; } finally { threadState.clear(); if (contentAuthSleep) { try { TimeUnit.MILLISECONDS.sleep(1); } catch (InterruptedException e) { // NOSONAR: pooled ES thread log.error("Thread.sleep interruped", e); } } } }
Example #12
Source File: ContentAuthPluginScriptTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Before public void setup() { sourceLookup = new SourceLookup(); when(variableResolverAdapterManager.get(FORMAT)).thenReturn(variableResolverAdapter); when(variableResolverAdapter.fromSourceLookup(eq(sourceLookup), anyMap())).thenReturn(variableSource); when(repositoryManager.findContainingGroups(any())).thenReturn(Collections.emptyList()); underTest = new ContentAuthPluginScript(subject, contentPermissionChecker, variableResolverAdapterManager, repositoryManager, true) { @Override protected SourceLookup getSourceLookup() { return sourceLookup; } }; }
Example #13
Source File: VariableResolverAdapterSupport.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
protected abstract void addFromSourceLookup(VariableSourceBuilder builder, SourceLookup sourceLookup, Map<String, Object> asset);
Example #14
Source File: ContentAuthPluginScript.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
/** * Delegates to {@link #source()}, only here to aid in unit testing. */ @VisibleForTesting protected SourceLookup getSourceLookup() { return source(); }
Example #15
Source File: VariableResolverAdapter.java From nexus-public with Eclipse Public License 1.0 | 2 votes |
/** * Creates a {@link VariableSource} from an ES-indexed asset. */ VariableSource fromSourceLookup(SourceLookup sourceLookup, Map<String, Object> asset);