private static void Init() { _indexDir = new RAMDirectory(); _schema = new DefaultIndexSchema(); _analyzer = new StandardAnalyzer(LuceneVersion); _init = true; }
internal static IFullTextSearchResult ToResult(this Document doc, double score, IFullTextIndexSchema schema) { //First get the node type Field nodeTypeField = doc.GetField(schema.NodeTypeField); if (nodeTypeField == null) throw new RdfQueryException("Node Type field " + schema.NodeTypeField + " not present on a retrieved document. Please check you have configured the Index Schema correctly"); NodeType nodeType; try { nodeType = (NodeType)Enum.Parse(typeof(NodeType), nodeTypeField.StringValue()); } catch { throw new RdfQueryException("Node Type field " + schema.NodeTypeField + " contained an invalid value '" + nodeTypeField.StringValue() + "'. Please check you have configured the Index Schema correctly"); } //Then get the node value Field nodeValueField = doc.GetField(schema.NodeValueField); if (nodeValueField == null) throw new RdfQueryException("Node Value field " + schema.NodeValueField + " not present on a retrieved document. Please check you have configured the Index Schema correctly"); String nodeValue = nodeValueField.StringValue(); //Then depending on the Node Type determine whether we need to obtain the Meta Field as well switch (nodeType) { case NodeType.Blank: //Can just create a Blank Node return new FullTextSearchResult(_factory.CreateBlankNode(nodeValue), score); case NodeType.Literal: //Need to get Meta field to determine whether we have a language or datatype present Field nodeMetaField = doc.GetField(schema.NodeMetaField); if (nodeMetaField == null) { //Assume a Plain Literal return new FullTextSearchResult(_factory.CreateLiteralNode(nodeValue), score); } else { String nodeMeta = nodeMetaField.StringValue(); if (nodeMeta.StartsWith("@")) { //Language Specified literal return new FullTextSearchResult(_factory.CreateLiteralNode(nodeValue, nodeMeta), score); } else { //Assume a Datatyped literal return new FullTextSearchResult(_factory.CreateLiteralNode(nodeValue, new Uri(nodeMeta)), score); } } case NodeType.Uri: //Can just create a URI Node return new FullTextSearchResult(_factory.CreateUriNode(new Uri(nodeValue)), score); default: throw new RdfQueryException("Only Blank, Literal and URI Nodes may be retrieved from a Lucene Document"); } }
/// <summary> /// Creates a new Simple Lucene Indexer /// </summary> /// <param name="indexDir">Directory</param> /// <param name="analyzer">Analyzer</param> /// <param name="schema">Index Schema</param> /// <param name="mode">Indexing Mode</param> public BaseSimpleLuceneIndexer(Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema, IndexingMode mode) { if (this._mode == IndexingMode.Custom) throw new ArgumentException("Cannot use IndexingMode.Custom with the BaseSimpleLuceneIndexer"); this._mode = mode; this._indexDir = indexDir; this._analyzer = analyzer; this._schema = schema; this._writer = new IndexWriter(indexDir, analyzer); this._searcher = new LucSearch.IndexSearcher(this._indexDir, true); }
/// <summary> /// Creates a new Base Lucene Search Provider /// </summary> /// <param name="ver">Lucene Version</param> /// <param name="indexDir">Directory</param> /// <param name="analyzer">Analyzer</param> /// <param name="schema">Index Schema</param> public BaseLuceneSearchProvider(LucUtil.Version ver, Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema) { this._version = ver; this._indexDir = indexDir; this._analyzer = analyzer; this._schema = schema; //Create necessary objects this._searcher = new LucSearch.IndexSearcher(this._indexDir, true); this._parser = new QueryParser(this._version, this._schema.IndexField, this._analyzer); }
/// <summary> /// Creates a new Base Lucene Search Provider /// </summary> /// <param name="ver">Lucene Version</param> /// <param name="indexDir">Directory</param> /// <param name="analyzer">Analyzer</param> /// <param name="schema">Index Schema</param> public BaseLuceneSearchProvider(LucUtil.Version ver, Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema) { this._version = ver; this._indexDir = indexDir; this._analyzer = analyzer; this._schema = schema; //Create necessary objects this._searcher = new LucSearch.IndexSearcher(this._indexDir, true); this._parser = new QueryParser(this._version, this._schema.IndexField, this._analyzer); }
/// <summary> /// Creates a new Simple Lucene Indexer. /// </summary> /// <param name="indexDir">Directory.</param> /// <param name="analyzer">Analyzer.</param> /// <param name="schema">Index Schema.</param> /// <param name="mode">Indexing Mode.</param> public BaseSimpleLuceneIndexer(Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema, IndexingMode mode) { if (this._mode == IndexingMode.Custom) { throw new ArgumentException("Cannot use IndexingMode.Custom with the BaseSimpleLuceneIndexer"); } this._mode = mode; this._indexDir = indexDir; this._analyzer = analyzer; this._schema = schema; this._writer = new IndexWriter(indexDir, analyzer, IndexWriter.MaxFieldLength.UNLIMITED); }
/// <summary> /// Creates a new Lucene Search Provider /// </summary> /// <param name="ver">Version</param> /// <param name="indexDir">Directory</param> /// <param name="analyzer">Analyzer</param> /// <param name="schema">Index Schema</param> public LuceneSearchProvider(LucUtil.Version ver, Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema) : base(ver, indexDir, analyzer, schema) { }
/// <summary> /// Creates a Lucene Subjects Indexer /// </summary> /// <param name="indexDir">Directory</param> /// <param name="analyzer">Analyzer</param> /// <param name="schema">Index Schema</param> public LuceneSubjectsIndexer(Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema) : base(indexDir, analyzer, schema, IndexingMode.Subjects) { }
/// <summary> /// Creates a Lucene Predicates Indexer /// </summary> /// <param name="indexDir">Directory</param> /// <param name="analyzer">Analyzer</param> /// <param name="schema">Index Schema</param> public LucenePredicatesIndexer(Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema) : base(indexDir, analyzer, schema, IndexingMode.Predicates) { }
internal static IFullTextSearchResult ToResult(this Document doc, double score, IFullTextIndexSchema schema) { //First get the node type Field nodeTypeField = doc.GetField(schema.NodeTypeField); if (nodeTypeField == null) { throw new RdfQueryException("Node Type field " + schema.NodeTypeField + " not present on a retrieved document. Please check you have configured the Index Schema correctly"); } NodeType nodeType; try { nodeType = (NodeType)Enum.Parse(typeof(NodeType), nodeTypeField.StringValue); } catch { throw new RdfQueryException("Node Type field " + schema.NodeTypeField + " contained an invalid value '" + nodeTypeField.StringValue + "'. Please check you have configured the Index Schema correctly"); } //Get the Graph Uri graphUri; Field graphField = doc.GetField(schema.GraphField); graphUri = (graphField == null ? null : UriFactory.Create(graphField.StringValue)); //Then get the node value Field nodeValueField = doc.GetField(schema.NodeValueField); if (nodeValueField == null) { throw new RdfQueryException("Node Value field " + schema.NodeValueField + " not present on a retrieved document. Please check you have configured the Index Schema correctly"); } String nodeValue = nodeValueField.StringValue; //Then depending on the Node Type determine whether we need to obtain the Meta Field as well switch (nodeType) { case NodeType.Blank: //Can just create a Blank Node return(new FullTextSearchResult(graphUri, _factory.CreateBlankNode(nodeValue), score)); case NodeType.Literal: //Need to get Meta field to determine whether we have a language or datatype present Field nodeMetaField = doc.GetField(schema.NodeMetaField); if (nodeMetaField == null) { //Assume a Plain Literal return(new FullTextSearchResult(graphUri, _factory.CreateLiteralNode(nodeValue), score)); } else { String nodeMeta = nodeMetaField.StringValue; if (nodeMeta.StartsWith("@")) { //Language Specified literal return(new FullTextSearchResult(graphUri, _factory.CreateLiteralNode(nodeValue, nodeMeta.Substring(1)), score)); } else { //Assume a Datatyped literal return(new FullTextSearchResult(graphUri, _factory.CreateLiteralNode(nodeValue, UriFactory.Create(nodeMeta)), score)); } } case NodeType.Uri: //Can just create a URI Node return(new FullTextSearchResult(graphUri, _factory.CreateUriNode(UriFactory.Create(nodeValue)), score)); default: throw new RdfQueryException("Only Blank, Literal and URI Nodes may be retrieved from a Lucene Document"); } }
/// <summary> /// Creates a new Lucene Search Provider. /// </summary> /// <param name="ver">Version.</param> /// <param name="indexDir">Directory.</param> /// <param name="analyzer">Analyzer.</param> /// <param name="schema">Index Schema.</param> /// <param name="autoSync">Whether to keep the search provider in sync with the index.</param> public LuceneSearchProvider(LucUtil.Version ver, Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema, bool autoSync) : base(ver, indexDir, analyzer, schema, autoSync) { }
/// <summary> /// Creates a new Lucene Search Provider. /// </summary> /// <param name="ver">Version.</param> /// <param name="indexDir">Directory.</param> /// <param name="analyzer">Analyzer.</param> /// <param name="schema">Index Schema.</param> public LuceneSearchProvider(LucUtil.Version ver, Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema) : this(ver, indexDir, analyzer, schema, true) { }
/// <summary> /// Creates a new Lucene Search Provider. /// </summary> /// <param name="ver">Version.</param> /// <param name="indexDir">Directory.</param> /// <param name="schema">Index Schema.</param> /// <param name="autoSync">Whether to keep the search provider in sync with the index.</param> /// <remarks> /// Uses the <see cref="StandardAnalyzer">StandardAnalyzer</see> as the analyzer. /// </remarks> public LuceneSearchProvider(LucUtil.Version ver, Directory indexDir, IFullTextIndexSchema schema, bool autoSync) : this(ver, indexDir, new StandardAnalyzer(ver), schema, autoSync) { }
/// <summary> /// Creates a new Lucene Search Provider /// </summary> /// <param name="ver">Version</param> /// <param name="indexDir">Directory</param> /// <param name="schema">Index Schema</param> /// <remarks> /// Uses the <see cref="StandardAnalyzer">StandardAnalyzer</see> as the analyzer /// </remarks> public LuceneSearchProvider(LucUtil.Version ver, Directory indexDir, IFullTextIndexSchema schema) : this(ver, indexDir, new StandardAnalyzer(ver), schema) { }
/// <summary> /// Creates a Lucene Subjects Indexer /// </summary> /// <param name="indexDir">Directory</param> /// <param name="analyzer">Analyzer</param> /// <param name="schema">Index Schema</param> public LuceneSubjectsIndexer(Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema) : base(indexDir, analyzer, schema, IndexingMode.Subjects) { }
/// <summary> /// Creates a Lucene Predicates Indexer /// </summary> /// <param name="indexDir">Directory</param> /// <param name="analyzer">Analyzer</param> /// <param name="schema">Index Schema</param> public LucenePredicatesIndexer(Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema) : base(indexDir, analyzer, schema, IndexingMode.Predicates) { }
/// <summary> /// Creates a new Base Lucene Search Provider. /// </summary> /// <param name="ver">Lucene Version.</param> /// <param name="indexDir">Directory.</param> /// <param name="analyzer">Analyzer.</param> /// <param name="schema">Index Schema.</param> public BaseLuceneSearchProvider(LucUtil.Version ver, Directory indexDir, Analyzer analyzer, IFullTextIndexSchema schema) : this(ver, indexDir, analyzer, schema, true) { _uriComparer = new UriComparer(); }