2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 package com
.intellij
.find
.ngrams
;
22 import com
.intellij
.openapi
.util
.text
.TrigramBuilder
;
23 import com
.intellij
.openapi
.vfs
.VirtualFile
;
24 import com
.intellij
.util
.indexing
.*;
25 import com
.intellij
.util
.io
.EnumeratorIntegerDescriptor
;
26 import com
.intellij
.util
.io
.KeyDescriptor
;
27 import gnu
.trove
.THashMap
;
28 import gnu
.trove
.TIntHashSet
;
29 import gnu
.trove
.TIntProcedure
;
30 import org
.jetbrains
.annotations
.NotNull
;
34 public class TrigramIndex
extends ScalarIndexExtension
<Integer
> {
35 public static final boolean ENABLED
= "true".equals(System
.getProperty("idea.internal.trigramindex.enabled"));
37 public static final ID
<Integer
,Void
> INDEX_ID
= ID
.create("Trigram.Index");
39 private static final FileBasedIndex
.InputFilter INPUT_FILTER
= new FileBasedIndex
.InputFilter() {
40 public boolean acceptInput(VirtualFile file
) {
41 return !file
.getFileType().isBinary();
44 private static final FileBasedIndex
.InputFilter NO_FILES
= new FileBasedIndex
.InputFilter() {
45 public boolean acceptInput(VirtualFile file
) {
50 public ID
<Integer
, Void
> getName() {
54 public DataIndexer
<Integer
, Void
, FileContent
> getIndexer() {
55 return new DataIndexer
<Integer
, Void
, FileContent
>() {
57 public Map
<Integer
, Void
> map(FileContent inputData
) {
58 final Map
<Integer
, Void
> result
= new THashMap
<Integer
, Void
>();
59 TIntHashSet built
= TrigramBuilder
.buildTrigram(inputData
.getContentAsText());
60 built
.forEach(new TIntProcedure() {
61 public boolean execute(int value
) {
62 result
.put(value
, null);
71 public KeyDescriptor
<Integer
> getKeyDescriptor() {
72 return new EnumeratorIntegerDescriptor();
75 public FileBasedIndex
.InputFilter
getInputFilter() {
84 public boolean dependsOnFileContent() {
88 public int getVersion() {
89 return ENABLED ?
2 : 1;