Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Solrnet在实现搜索时没有结果和类型转换问题_Asp.net_Solr_Solrnet - Fatal编程技术网

Asp.net Solrnet在实现搜索时没有结果和类型转换问题

Asp.net Solrnet在实现搜索时没有结果和类型转换问题,asp.net,solr,solrnet,Asp.net,Solr,Solrnet,我正在尝试从数据库中获取数据以显示在网页上,并通过页面上的文本框进行搜索,使用solrnet进行搜索和asp.net。我已经实现了类似于solrnet的wiki上的文档中设置的搜索。第一个问题是,大约有一半的代码在尝试设置查询时中断,奇怪的是,只有特定的输入字符串(我已经识别了“france”、“f”和“a”来中断内容)才会出现错误消息 "Object of type 'System.String' cannot be converted to type 'System.Nullable`1[S

我正在尝试从数据库中获取数据以显示在网页上,并通过页面上的文本框进行搜索,使用solrnet进行搜索和asp.net。我已经实现了类似于solrnet的wiki上的文档中设置的搜索。第一个问题是,大约有一半的代码在尝试设置查询时中断,奇怪的是,只有特定的输入字符串(我已经识别了“france”、“f”和“a”来中断内容)才会出现错误消息

"Object of type 'System.String' cannot be converted to type 'System.Nullable`1[System.Int32]'." 
我尝试过调试,但它深入到solrnet代码中,我甚至找不到它试图在哪里进行这种中断的转换。另一个问题是,即使它没有破裂,也不会有结果!我也不知道为什么会这样,尽管这可能与solr模式的“defaultfield”有关

无论如何,这里是代码的相关部分;如果您还需要什么,请告诉我,我可以发布:

    public string Search(string text)
    {
        // Solr init stuff
        var solr = SolrOpsCache<Product>.GetSolrOperations();

        // Code will often break pointing this block below
        var matchingProducts = solr.Query(new SolrQuery(text), new QueryOptions {
            Start = 1,
            Rows = 30,
        });

        // This is just formatting the results correctly for the
        // stored proc I have on the database
        List<string> matchingItemCodes = new List<string>();

        foreach (Product p in matchingProducts)
        {
            matchingItemCodes.Add(p.itemCode);
        }
        string itemCodesDelimited = ToDelimitedString(matchingItemCodes, ",");
        return itemCodesDelimited;
    }


    protected void SearchButton_Click(object sender, EventArgs e)
    {
        // Search based on what's in the box
        string codes = Search(SearchBox.Text);
        productList = pr.GetProductsByItemcode(codes);
    }
}
公共字符串搜索(字符串文本)
{
//Solr init东西
var solr=SolrOpsCache.getSolropertions();
//代码经常会在指向下面的块时中断
var matchingProducts=solr.Query(新的SolrQuery(文本),新的QueryOptions{
开始=1,
行=30,
});
//这只是将结果正确地格式化为
//我在数据库上的存储过程
List matchingItemCodes=新列表();
foreach(匹配产品中的产品p)
{
匹配项目代码。添加(p.itemCode);
}
字符串itemCodesDelimited=ToDelimitedString(匹配itemcodes,“,”);
返回项目代码有限公司;
}
受保护的无效搜索按钮\u单击(对象发送者,事件参数e)
{
//根据框中的内容进行搜索
字符串代码=搜索(SearchBox.Text);
productList=pr.GetProductsByItemcode(代码);
}
}
schema.xml:

<schema name="RML Schema" version="1.1">
  <types>
    <fieldtype name="string"  class="solr.StrField" sortMissingLast="true" omitNorms="true" />
    <fieldType name="cat_string" class="solr.TextField" sortMissingLast="true" omitNorms="true">      
      <analyzer>  
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>  
      </analyzer>  
    </fieldType>
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>

    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>
    <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="int" class="solr.IntField" />
  </types>

 <fields>   

    <field name="ItemCode" type="string" indexed="true" stored="true" required="true" />  
     <field name="ItemName" type="text_general" indexed="true" stored="true"/>  
     <field name="RML" type="cat_string" indexed="true" stored="true"/>  
     <field name="Buyer" type="cat_string" indexed="true" stored="true"/>  
     <field name="Vendor" type="cat_string" indexed="true" stored="true"/> 

     <field name="AvgCost" type="float" indexed="true" stored="true"/> 
     <field name="SalePrice" type="float" indexed="true" stored="true"/> 
     <field name="Profit_Ave" type="float" indexed="true" stored="true"/> 
     <field name="Profit_MSRP" type="float" indexed="true" stored="true"/> 
     <field name="OnHand" type="int" indexed="true" stored="true"/> 
     <field name="IsCommited" type="int" indexed="true" stored="true"/> 
     <field name="OnOrder" type="int" indexed="true" stored="true"/> 
     <field name="ATS" type="int" indexed="true" stored="true"/> 
     <field name="AOH" type="int" indexed="true" stored="true"/> 

     <field name="text" type="text_general" indexed="true" stored="true" multiValued="true"/>
     <field name="Vintage" type="cat_string" indexed="true" stored="true"/>
     <field name="Producer" type="cat_string" indexed="true" stored="true" />
     <field name="Country" type="cat_string" indexed="true" stored="true" />
     <field name="Region" type="cat_string" indexed="true" stored="true" />
     <field name="Appellation" type="cat_string" indexed="true" stored="true" />
     <field name="CRU" type="cat_string" indexed="true" stored="true" />
     <field name="Size" type="cat_string" indexed="true" stored="true" />
     <field name="RtrakDept" type="cat_string" indexed="true" stored="true" />

 </fields>

还有我的产品课

public class Product
    {
        [SolrUniqueKey("ItemCode")]
        public string itemCode { get; set; }

        [SolrField("ItemName")]
        public string itemName { get; set; }

        /* Commented out because it's not in the database yet
        [SolrField("RML")]
        public string rml { get; set; }        
        */

        [SolrField("Buyer")]
        public string buyer { get; set; }

        [SolrField("Vendor")]
        public string vendor { get; set; }

        [SolrField("AvgCost")]
        public Nullable<float> avgCost { get; set; }

        [SolrField("SalePrice")]
        public Nullable<float> salePrice { get; set; }

        [SolrField("Profit_Ave")]
        public Nullable<float> profitAve { get; set; }

        [SolrField("Profit_MSRP")]
        public Nullable<float> profitMSRP { get; set; }

        [SolrField("OnHand")]
        public Nullable<int> onHand { get; set; }

        [SolrField("IsCommited")]
        public Nullable<int> isCommited { get; set; }

        [SolrField("OnOrder")]
        public Nullable<int> onOrder { get; set; }        

        [SolrField("ATS")]
        public Nullable<int> ats { get; set; }

        [SolrField("AOH")]
        public Nullable<int> aoh { get; set; }

        [SolrField("Vintage")]
        public string vintage { get; set; }

        [SolrField("Producer")]
        public string producer { get; set; }

        [SolrField("Country")]
        public string country { get; set; }

        [SolrField("Region")]
        public string region { get; set; }

        [SolrField("Appellation")]
        public string appellation { get; set; }

        [SolrField("CRU")]
        public string cru { get; set; }

        [SolrField("Size")]
        public string size { get; set; }

        [SolrField("RtrakDept")]
        public string rtrakDept { get; set; }
}
公共类产品
{
[SolrUniqueKey(“项目代码”)]
公共字符串itemCode{get;set;}
[索尔菲尔德(“项目名称”)]
公共字符串itemName{get;set;}
/*注释掉了,因为它还不在数据库中
[索尔菲尔德(“RML”)]
公共字符串rml{get;set;}
*/
[索尔菲尔德(“买方”)]
公共字符串买方{get;set;}
[索尔菲尔德(“供应商”)]
公共字符串供应商{get;set;}
[索尔菲尔德(“AvgCost”)]
公共可为空的avgCost{get;set;}
[索尔菲尔德(“售价”)]
公共可为空的售价{get;set;}
[索尔菲尔德(“利润大道”)]
公共可为空的profitAve{get;set;}
[SolrField(“利润”)]
公共可空profitMSRP{get;set;}
[索尔菲尔德(“现场”)]
公共可空的现有{get;set;}
[索尔菲尔德(“被认可”)]
公共可为null的isCommited{get;set;}
[索尔菲尔德(“OnOrder”)]
公共可为空的onOrder{get;set;}
[索尔菲尔德(“ATS”)]
公共可为空的ats{get;set;}
[索尔菲尔德(“AOH”)]
公共可空aoh{get;set;}
[索尔菲尔德(“复古”)]
公共字符串{get;set;}
[索尔菲尔德(“制作人”)]
公共字符串生成器{get;set;}
[索尔菲尔德(“国家”)]
公共字符串国家{get;set;}
[索尔菲尔德(“地区”)]
公共字符串区域{get;set;}
[索尔菲尔德(“称谓”)]
公共字符串名称{get;set;}
[索尔菲尔德(“CRU”)]
公共字符串cru{get;set;}
[索尔菲尔德(“尺寸”)]
公共字符串大小{get;set;}
[索尔菲尔德(“RTRAKDEP”)]
公共字符串rtrakDept{get;set;}
}

谢谢大家!

您的
schema.xml
Product
类看起来像什么?我怀疑solr模式中定义了一个字符串字段,您正在将该字段映射到类的
int
属性。现在更新帖子,我似乎找不到未映射的字段。留意任何看起来可疑的东西,没有什么特别的。是否有可以共享的stacktrace?也许有更多的信息在例外?这是正在讨论的SolrNet论坛-我得到了整理(大部分)。原来这是一个奇怪的索引问题;我还没有完全解决它,但现在能够解决这个问题。如果任何人(谷歌人)想要更多关于这个bug的信息,请关注我在SolrNet论坛上发布的讨论。