Changeset 32912 for lang

Show
Ignore:
Timestamp:
04/28/09 21:20:47 (4 years ago)
Author:
hoge1e3
Message:

#150 複数語検索 と #144

Location:
lang/csharp/soyText/soyText
Files:
3 added
11 modified

Legend:

Unmodified
Added
Removed
  • lang/csharp/soyText/soyText/DocumentSercher.cs

    r32864 r32912  
    66namespace SoyText 
    77{ 
    8     class DocumentSercher 
     8    public class DocumentSercher 
    99    { 
    10         DocumentSet documentSet; 
    11         SearchCondition searchCondition; 
    12         FoundHandler foundHandler; 
     10        public DocumentSet documentSet; 
     11        public SearchCondition searchCondition; 
     12        public FoundHandler foundHandler; 
     13        bool terminated = false; 
     14        public void terminate() { terminated = true; } 
    1315        public SortedList<long, Document> search() 
    1416        { 
     
    2022            } 
    2123            var res = new SortedList<long, Document>(); 
    22             if (searchCondition == null || searchCondition.isAny) 
     24            if (searchCondition == null || searchCondition is AnyCondition) 
    2325            { 
    2426                foreach (var d in rec) 
     
    2729                    if (a == FoundHandlerAction.End) break; 
    2830                    if (a == FoundHandlerAction.Accept) res.Add(d.Key, d.Value); 
     31                    if (terminated) break; 
    2932                } 
    3033                return res; 
     
    4548                    } 
    4649                } 
     50                if (terminated) break; 
    4751            } 
    4852            Debug.print("完了: 文書を検索: " + searchCondition); 
  • lang/csharp/soyText/soyText/DocumentSet.cs

    r32760 r32912  
    9797            return maxHandle; 
    9898        } 
     99        public DocumentSercher createDocumentSearcher(String kw, FoundHandler f) 
     100        { 
     101            var s = new DocumentSercher(); 
     102            s.searchCondition = SearchCondition.fromExpression(kw); 
     103            s.foundHandler = f; 
     104            s.documentSet = this; 
     105            return s; 
     106        } 
    99107        public SortedList<long,Document> search(String kw, FoundHandler f) 
    100108        { 
    101             var rec0 = getRecents(); 
    102             var rec = new SortedList<long, Document>(); 
    103             lock (rec0) 
    104             { 
    105                 foreach (var d in rec0) rec.Add(d.Key, d.Value); 
    106             } 
    107             var res = new SortedList<long, Document>(); 
    108             if (kw == null || kw.Equals("")) 
    109             { 
    110                 foreach (var d in rec) 
    111                 {  
    112                     var a = f(d.Value); 
    113                     if (a == FoundHandlerAction.End) break; 
    114                     if (a == FoundHandlerAction.Accept) res.Add(d.Key,d.Value); 
    115                 } 
    116                 return res; 
    117             } 
    118             var t = workspace.indexer.createToken(kw); 
    119             /*Debug.print("文字検索: " + kw); 
    120             foreach (var st in t.existentSuperstrings) 
    121             { 
    122                 var ress = exactSearch(st); 
    123                 foreach (var d in ress) { 
    124                     if (!res.ContainsKey(d.Key)) 
    125                     { 
    126                         res.Add(d.Key, d.Value); 
    127                     } 
    128                 } 
    129             }*/ 
    130             var c=rec.Count; 
    131             var cnt = 0; 
    132             foreach (var d in rec) 
    133             { 
    134                 Debug.print("文書を検索: " + kw+"("+cnt+"/"+c+") - "+res.Count+"件見つかりました"); 
    135                 cnt++; 
    136                 if (d.Value.matches(kw)) 
    137                 { 
    138                     if (!res.ContainsKey(d.Key)) 
    139                     { 
    140                         var a=f(d.Value); 
    141                         if (a == FoundHandlerAction.End) break; 
    142                         if (a == FoundHandlerAction.Accept) res.Add(d.Key, d.Value); 
    143                     } 
    144                 } 
    145             } 
    146             Debug.print("完了: 文書を検索: " + kw); 
    147              
    148             //var resList = res.ToList(); 
    149             //Debug.print("検索結果の並べ替え: "+kw); 
    150             //resList.Sort(byRecency); 
    151             //Debug.print("End: 検索結果の並べ替え: " + kw); 
    152             return res; 
    153  
     109            var s = createDocumentSearcher(kw, f); 
     110            return s.search(); 
    154111        } 
     112         
    155113        private SortedList<long, Document> exactSearch(Token t) 
    156114        { 
  • lang/csharp/soyText/soyText/Form1.cs

    r32864 r32912  
    6767        } 
    6868        TerminableThread searchThread = new TerminableThread(); 
     69        DocumentSercher documentSearcher; 
    6970        public void refreshList(String kw) 
    7071        { 
    7172            if (kw == "" || kw==null) Text = "soyText"; 
    7273            else Text = kw + " - " + "soyText"; 
    73  
     74            if (documentSearcher != null) documentSearcher.terminate(); 
    7475            searchThread.exec(delegate(TerminableThread t) 
    7576            { 
     
    7980                    docListBox.Items.Clear(); 
    8081                }); 
    81                 SortedList<long, Document> res = documentSet.search(kw, delegate(Document d) 
     82                documentSearcher = documentSet.createDocumentSearcher(kw, 
     83                delegate(Document d) 
    8284                { 
    8385                    cnt++; 
    84                     if (cnt < 100 && !t.terminated) 
     86                    if (cnt < 100) 
    8587                    { 
    8688                        syncUI(delegate() { docListBox.Items.Add(d); }); 
     
    9395                    } 
    9496                }); 
     97                documentSearcher.search(); 
    9598                statusText = "完了"; 
    9699            }); 
  • lang/csharp/soyText/soyText/SearchCondition.cs

    r32864 r32912  
    66namespace SoyText 
    77{ 
    8     public class SearchCondition 
     8    public abstract class SearchCondition 
    99    { 
    10         String word; 
    11         public bool matches(Document d) 
    12         { 
    13             return d.content.IndexOf(word) >= 0; 
    14         } 
    15         public bool matches(DocumentLine line) 
    16         { 
    17             return line.content.IndexOf(word) >= 0; 
    18         } 
     10        public abstract bool matches(Document d); 
     11        public abstract bool matches(DocumentLine d); 
    1912        public static SearchCondition fromExpression(String expr) 
    2013        { 
    21             var r = new SearchCondition(); 
    22             r.word = expr; 
    23             return r; 
    24         } 
    25         public bool isAny { get { return word == ""; } } 
    26         public override string ToString() 
    27         { 
    28             return word; 
     14            if (expr == null || expr == "") return new AnyCondition(); 
     15            string[] s = expr.Split(' '); 
     16            if (s.Length == 1) 
     17            { 
     18                return new KeywordCondition(expr); 
     19            } 
     20            if (s.Length == 0) 
     21            { 
     22                return new AnyCondition(); 
     23            } 
     24            var res = new AndCondition(); 
     25            foreach (var e in s) 
     26            { 
     27                res.add(fromExpression(e)); 
     28            } 
     29            return res; 
    2930        } 
    3031    } 
  • lang/csharp/soyText/soyText/TerminableThread.cs

    r32864 r32912  
    2828                        { 
    2929                            r = nextRun; 
     30                            nextRun = null; 
    3031                            _running = true; 
    3132                            terminated = false; 
  • lang/csharp/soyText/soyText/bin/Debug/soyText.application

    r32864 r32912  
    1212        </dsig:Transforms> 
    1313        <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
    14         <dsig:DigestValue>j6hhuQVWYtfWkwy8j3nFgirX6hk=</dsig:DigestValue> 
     14        <dsig:DigestValue>b4VFJRybu2kjnO+ggm9SDfFqbuo=</dsig:DigestValue> 
    1515      </hash> 
    1616    </dependentAssembly> 
  • lang/csharp/soyText/soyText/bin/Debug/soyText.exe.manifest

    r32864 r32912  
    5353  </dependency> 
    5454  <dependency> 
    55     <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="soyText.exe" size="45568"> 
     55    <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="soyText.exe" size="46080"> 
    5656      <assemblyIdentity name="soyText" version="1.0.0.0" language="neutral" processorArchitecture="msil" /> 
    5757      <hash> 
     
    6060        </dsig:Transforms> 
    6161        <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
    62         <dsig:DigestValue>EHWhcOuAInIwLvFSenDNLPBrS1s=</dsig:DigestValue> 
     62        <dsig:DigestValue>yJYEl9jmz0Myd9vk+kUqmHKRDv4=</dsig:DigestValue> 
    6363      </hash> 
    6464    </dependentAssembly> 
  • lang/csharp/soyText/soyText/bin/Debug/soyText.vshost.application

    r32864 r32912  
    1212        </dsig:Transforms> 
    1313        <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
    14         <dsig:DigestValue>j6hhuQVWYtfWkwy8j3nFgirX6hk=</dsig:DigestValue> 
     14        <dsig:DigestValue>b4VFJRybu2kjnO+ggm9SDfFqbuo=</dsig:DigestValue> 
    1515      </hash> 
    1616    </dependentAssembly> 
  • lang/csharp/soyText/soyText/soyText.csproj

    r32864 r32912  
    7070  </ItemGroup> 
    7171  <ItemGroup> 
     72    <Compile Include="AndCondition.cs" /> 
    7273    <Compile Include="Debug.cs" /> 
    7374    <Compile Include="Document.cs" /> 
    7475    <Compile Include="DocumentImporter.cs" /> 
    7576    <Compile Include="DocumentLine.cs" /> 
     77    <Compile Include="AnyCondition.cs" /> 
    7678    <Compile Include="DocumentSercher.cs" /> 
    7779    <Compile Include="DocumentSet.cs" /> 
     
    125127    </Compile> 
    126128    <Compile Include="Inclusion.cs" /> 
     129    <Compile Include="KeywordCondition.cs" /> 
    127130    <Compile Include="SearchCondition.cs" /> 
    128131    <Compile Include="Str.cs" /> 
     
    171174    </BootstrapperPackage> 
    172175  </ItemGroup> 
     176  <ItemGroup> 
     177    <Folder Include="Search\" /> 
     178  </ItemGroup> 
    173179  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 
    174180  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.