コード例 #1
0
        private static string GetSubQueryString(string sen, float boost)
        {
            string queryString = sen;

            BooleanQuery query  = new BooleanQuery();
            QueryParser  parser = new QueryParser(MyLucene.GetLuceneVersion(), "name", AnalyzerFactory.GetAnalyzer());
            Query        q      = parser.Parse(queryString);

            q.SetBoost(boost * 9);
            query.Add(q, BooleanClause.Occur.SHOULD);

            parser = new QueryParser(MyLucene.GetLuceneVersion(), "oldName", AnalyzerFactory.GetAnalyzer());
            q      = parser.Parse(queryString);
            q.SetBoost(boost * 7);
            query.Add(q, BooleanClause.Occur.SHOULD);

            parser = new QueryParser(MyLucene.GetLuceneVersion(), "shortName", AnalyzerFactory.GetAnalyzer());
            q.SetBoost(boost * 10);
            q = parser.Parse(queryString);
            query.Add(q, BooleanClause.Occur.SHOULD);

            parser = new QueryParser(MyLucene.GetLuceneVersion(), "japName", AnalyzerFactory.GetAnalyzer());
            q.SetBoost(boost * 8);
            q = parser.Parse(queryString);
            query.Add(q, BooleanClause.Occur.SHOULD);

            parser = new QueryParser(MyLucene.GetLuceneVersion(), "enName", AnalyzerFactory.GetAnalyzer());
            q.SetBoost(boost * 7);
            q = parser.Parse(queryString);
            query.Add(q, BooleanClause.Occur.SHOULD);

            return(query.ToString());
        }
コード例 #2
0
        public async Task <IHttpActionResult> Get(long id1, long id2)
        {
            var sw       = Stopwatch.StartNew();
            var analyzer = AnalyzerFactory.GetAnalyzer();

            try
            {
                var paths = await analyzer.FindPathsAsync(id1, id2);

                // 返回只要 Id 就可以了。
                // 由于结构比较简单,所以可以强行 json 。
                var resultBuilder = new StringBuilder("[");
                var isFirst       = true;
                foreach (var path in paths)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        resultBuilder.Append(",\n");
                    }
                    resultBuilder.Append("[");
                    for (int j = 0; j < path.Length; j++)
                    {
                        if (j > 0)
                        {
                            resultBuilder.Append(",");
                        }
                        resultBuilder.Append(path[j].Id);
                    }
                    resultBuilder.Append("]");
                }
                resultBuilder.Append("]");
                var resp = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(resultBuilder.ToString(), null, Utility.JsonMediaType)
                };
                AnalyzerFactory.PutAnalyzer(analyzer);
                return(new ResponseMessageResult(resp));
            }
            finally
            {
                analyzer.LogStatistics();
                analyzer.SearchClient.LogStatistics();
                TimerLogger.TraceTimer("MagikController", sw);
            }
        }
コード例 #3
0
        public CardDescription[] Search2(string queryString, SortField[] sortFields)
        {
            try
            {
                if (queryString != null)
                {
                    queryString = queryString.Trim();
                }


                Query query = null;
                if (queryString == null || queryString == "")
                {
                    query = new MatchAllDocsQuery();
                }
                else
                {
                    BooleanQuery bquery = new BooleanQuery();
                    QueryParser  parser = new QueryParser("name", AnalyzerFactory.GetAnalyzer());
                    Query        q      = parser.Parse(queryString);
                    bquery.Add(q, BooleanClause.Occur.SHOULD);

                    parser = new QueryParser("oldName", AnalyzerFactory.GetAnalyzer());
                    q      = parser.Parse(queryString);
                    bquery.Add(q, BooleanClause.Occur.SHOULD);

                    parser = new QueryParser("shortName", AnalyzerFactory.GetAnalyzer());
                    q      = parser.Parse(queryString);
                    bquery.Add(q, BooleanClause.Occur.SHOULD);

                    parser = new QueryParser("japName", AnalyzerFactory.GetAnalyzer());
                    q      = parser.Parse(queryString);
                    bquery.Add(q, BooleanClause.Occur.SHOULD);

                    parser = new QueryParser("enName", AnalyzerFactory.GetAnalyzer());
                    q      = parser.Parse(queryString);
                    bquery.Add(q, BooleanClause.Occur.SHOULD);

                    query = bquery;
                }

                Searcher searcher = null;
                if (KeepInMemory)
                {
                    if (allowDIY && ramdiydir != null)
                    {
                        IndexSearcher[] indexsearchers = new IndexSearcher[2];
                        indexsearchers[0] = new IndexSearcher(ramdir);
                        indexsearchers[1] = new IndexSearcher(ramdiydir);
                        searcher          = new MultiSearcher(indexsearchers);
                    }
                    else
                    {
                        searcher = new IndexSearcher(ramdir);
                    }
                }
                else
                {
                    if (allowDIY && Directory.Exists(Path + "DIYCardIndex"))
                    {
                        IndexSearcher[] indexsearchers = new IndexSearcher[2];
                        indexsearchers[0] = new IndexSearcher(Path + "CardIndex");
                        indexsearchers[1] = new IndexSearcher(Path + "DIYCardIndex");
                        searcher          = new MultiSearcher(indexsearchers);
                    }
                    else
                    {
                        searcher = new IndexSearcher(Path + "CardIndex");
                    }
                }

                Hits hits = null;

                if (sortFields == null)
                {
                    hits = searcher.Search(query);
                }
                else
                {
                    hits = searcher.Search(query, new Sort(sortFields));
                }

                int length = hits.Length();
                CardDescription[] cards = new CardDescription[length];
                for (int i = 0; i < length; i++)
                {
                    Document doc = hits.Doc(i);
                    cards[i] = GetCardByID(int.Parse(doc.GetField("ID").StringValue()));
                }

                return(cards);
            }
            catch
            {
                return(new CardDescription[0]);
            }
        }
コード例 #4
0
        public CardDescription[] Search(string queryString, SortField[] sortFields)
        {
            try
            {
                if (queryString != null)
                {
                    queryString = queryString.Trim();
                }


                Query query = null;
                if (queryString == null || queryString == "")
                {
                    query = new MatchAllDocsQuery();
                }
                else
                {
                    QueryParser parser = new MultiFieldQueryParser(MyLucene.GetLuceneVersion(), new string[] { "name", "oldName", "shortName", "japName", "enName", "effect", "effectType", "cardType", "tribe", "element", "level", "atk", "def", "aliasList", "package", "infrequence" }, AnalyzerFactory.GetAnalyzer());
                    query = parser.Parse(queryString);
                }

                TopDocs docs = null;

                if (sortFields == null)
                {
                    docs = searcher.Search(query, null, searcher.MaxDoc());
                }
                else
                {
                    docs = searcher.Search(query, null, searcher.MaxDoc(), new Sort(sortFields));
                }

                ScoreDoc[] sdocs  = docs.scoreDocs;
                int        length = sdocs.Length;

                CardDescription[] cards = new CardDescription[length];
                for (int i = 0; i < length; i++)
                {
                    cards[i] = GetCardByIndex(sdocs[i].doc);
                }

                return(cards);
            }
            catch
            {
                return(new CardDescription[0]);
            }
        }